# Path: yubioath/gui/ccid.py
# class CardStatus:
#     NoCard, InUse, Present = range(3)
# 
# Path: yubioath/yubicommon/compat.py
# def byte2int(i):
#     if _PY2:
#         return ord(i)
#     return i
# 
# def int2byte(i):
#     if _PY2:
#         return chr(i)
#     return bytes((i,))


from .ccid import CardStatus
from yubioath.yubicommon.compat import byte2int, int2byte
from smartcard.scard import (
    SCardTransmit, SCardGetErrorMessage, SCardConnect, SCardDisconnect,
    SCardEstablishContext, SCardReleaseContext, SCardListReaders,
    SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, SCARD_SCOPE_USER, SCARD_SHARE_SHARED,
    SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1
)
from PySide import QtCore
import threading
import time
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, We grant you additional
# permission to convey the resulting work. Corresponding Source for a
# non-source form of such a combination shall include the source code
# for the parts of OpenSSL used as well as that of the covered work.



class LLScardDevice(object):

    """
    Low level pyscard based backend (Windows chokes on the high level one
    whenever you remove the key and re-insert it).
    """

    def __init__(self, context, card, protocol):
        self._context = context
        self._card = card
        self._protocol = protocol

    def send_apdu(self, cl, ins, p1, p2, data):

# Path: yubioath/gui/ccid.py
# class CardStatus:
#     NoCard, InUse, Present = range(3)
# 
# Path: yubioath/yubicommon/compat.py
# def byte2int(i):
#     if _PY2:
#         return ord(i)
#     return i
# 
# def int2byte(i):
#     if _PY2:
#         return chr(i)
#     return bytes((i,))


# Path: yubioath/gui/ccid_poll.py
from .ccid import CardStatus
from yubioath.yubicommon.compat import byte2int, int2byte
from smartcard.scard import (
    SCardTransmit, SCardGetErrorMessage, SCardConnect, SCardDisconnect,
    SCardEstablishContext, SCardReleaseContext, SCardListReaders,
    SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, SCARD_SCOPE_USER, SCARD_SHARE_SHARED,
    SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1
)
from PySide import QtCore
import threading
import time

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Additional permission under GNU GPL version 3 section 7
#
# If you modify this program, or any covered work, by linking or
# combining it with the OpenSSL project's OpenSSL library (or a
# modified version of that library), containing parts covered by the
# terms of the OpenSSL or SSLeay licenses, We grant you additional
# permission to convey the resulting work. Corresponding Source for a
# non-source form of such a combination shall include the source code
# for the parts of OpenSSL used as well as that of the covered work.



class LLScardDevice(object):

    """
    Low level pyscard based backend (Windows chokes on the high level one
    whenever you remove the key and re-insert it).
    """

    def __init__(self, context, card, protocol):
        self._context = context
        self._card = card
        self._protocol = protocol

    def send_apdu(self, cl, ins, p1, p2, data):

        apdu = [cl, ins, p1, p2, len(data)] + [byte2int(b) for b in data]