• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / pyscard / 14386189929

10 Apr 2025 03:40PM UTC coverage: 66.028% (-0.06%) from 66.092%
14386189929

push

github

LudovicRousseau
PCSCCardRequest: correctly initialize waitforcardevent()

The method returned immediatly because there was no previous state and
readerstates[] was not initialized.

104 of 483 branches covered (21.53%)

0 of 2 new or added lines in 1 file covered. (0.0%)

35 existing lines in 22 files now uncovered.

4445 of 6732 relevant lines covered (66.03%)

4.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/smartcard/ExclusiveTransmitCardConnection.py
1
"""Sample CardConnectionDecorator that provides exclusive transmit()
2

3
__author__ = "https://www.gemalto.com/"
4

5
Copyright 2001-2012 gemalto
6
Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
7

8
This file is part of pyscard.
9

10
pyscard is free software; you can redistribute it and/or modify
11
it under the terms of the GNU Lesser General Public License as published by
12
the Free Software Foundation; either version 2.1 of the License, or
13
(at your option) any later version.
14

15
pyscard is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
GNU Lesser General Public License for more details.
19

20
You should have received a copy of the GNU Lesser General Public License
21
along with pyscard; if not, write to the Free Software
22
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
"""
24

25
import smartcard.pcsc
×
26
from smartcard.CardConnectionDecorator import CardConnectionDecorator
×
27
from smartcard.Exceptions import CardConnectionException
×
28
from smartcard.scard import (
×
29
    SCARD_LEAVE_CARD,
30
    SCARD_S_SUCCESS,
31
    SCardBeginTransaction,
32
    SCardEndTransaction,
33
    SCardGetErrorMessage,
34
)
35

36

37
class ExclusiveTransmitCardConnection(CardConnectionDecorator):
×
38
    """This decorator uses
39
    L{SCardBeginTransaction}/L{SCardEndTransaction} to preserve other
40
    processes of threads to access the card during transmit()."""
41

42
    def __init__(self, cardconnection):
×
43
        CardConnectionDecorator.__init__(self, cardconnection)
×
44

45
    def lock(self):
×
46
        """Lock card with L{SCardBeginTransaction}."""
47

48
        component = self.component
×
UNCOV
49
        while True:
50
            if isinstance(
×
51
                component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection
52
            ):
53
                hresult = SCardBeginTransaction(component.hcard)
×
54
                if SCARD_S_SUCCESS != hresult:
×
55
                    raise CardConnectionException(
×
56
                        "Failed to lock with SCardBeginTransaction: "
57
                        + SCardGetErrorMessage(hresult)
58
                    )
59
                else:
60
                    # print('locked')
UNCOV
61
                    pass
62
                break
×
63
            if hasattr(component, "component"):
×
64
                component = component.component
×
65
            else:
66
                break
×
67

68
    def unlock(self):
×
69
        """Unlock card with L{SCardEndTransaction}."""
70
        component = self.component
×
UNCOV
71
        while True:
72
            if isinstance(
×
73
                component, smartcard.pcsc.PCSCCardConnection.PCSCCardConnection
74
            ):
75
                hresult = SCardEndTransaction(component.hcard, SCARD_LEAVE_CARD)
×
76
                if SCARD_S_SUCCESS != hresult:
×
77
                    raise CardConnectionException(
×
78
                        "Failed to unlock with SCardEndTransaction: "
79
                        + SCardGetErrorMessage(hresult)
80
                    )
81
                else:
82
                    # print('unlocked')
UNCOV
83
                    pass
84
                break
×
85
            if hasattr(component, "component"):
×
86
                component = component.component
×
87
            else:
88
                break
×
89

90
    def transmit(self, command, protocol=None):
×
91
        """Gain exclusive access to card during APDU transmission for if this
92
        decorator decorates a PCSCCardConnection."""
93
        data, sw1, sw2 = CardConnectionDecorator.transmit(self, command, protocol)
×
94
        return data, sw1, sw2
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc