# Path: yubioath/core/exc.py
# class CardError(Exception):
# 
#     def __init__(self, status, message=''):
#         super(CardError, self).__init__('Card Error (%04x): %s' %
#                                         (status, message))
#         self.status = status
# 
# class DeviceLockedError(Exception):
# 
#     def __init__(self):
#         super(DeviceLockedError, self).__init__('Device is locked!')
# 
# class NoSpaceError(Exception):
# 
#     def __init__(self):
#         super(NoSpaceError, self).__init__('No space available on device.')
# 
# Path: yubioath/core/utils.py
# def hmac_sha1(secret, message):
# def time_challenge(t=None):
# def parse_full(resp):
# def parse_truncated(resp):
# def format_code(code, digits=6):
# def parse_uri(uri):
# def derive_key(salt, passphrase):
# def der_pack(*values):
# def der_read(der_data, expected_t=None):
# def b2len(bs):
# def kill_scdaemon():
# def ccid_supported_but_disabled():
# def _get_pids_linux():
# def _get_pids_osx():
# def _get_pids_win():
#         WMI = GetObject('winmgmts:')
# NON_CCID_YK_PIDS = set([0x0110, 0x0113, 0x0114, 0x0401, 0x0402, 0x0403])
# 
# Path: yubioath/yubicommon/compat.py
# def int2byte(i):
#     if _PY2:
#         return chr(i)
#     return bytes((i,))
# 
# def byte2int(i):
#     if _PY2:
#         return ord(i)
#     return i


from .exc import CardError, DeviceLockedError, NoSpaceError
from .utils import (
    der_read, der_pack, hmac_sha1, derive_key, get_random_bytes,
    time_challenge, parse_truncated, format_code)
from yubioath.yubicommon.compat import int2byte, byte2int
import hashlib
import struct
import os
        resp, status = self._delegate.send_apdu(cl, ins, p1, p2, data)
        self._long_resp = len(resp) > 52  # 52 bytes resp, 2 bytes status...
        return resp, status


class YubiOathCcid(object):

    """
    Device interface to a OATH-enabled YubiKey.
    """

    def __init__(self, device):
        self._device = device

        self._select()

        if (4, 2, 0) <= self.version <= (4, 2, 6):
            self._device = _426Device(device)

    def _send(self, ins, data='', p1=0, p2=0, expected=0x9000):
        resp, status = self._device.send_apdu(0, ins, p1, p2, data)
        while (status >> 8) == RESP_MORE_DATA:
            more, status = self._device.send_apdu(
                0, INS_SEND_REMAINING, 0, 0, '')
            resp += more

        if status == YKOATH_NO_SPACE:
            raise NoSpaceError()

        if expected != status:

# Path: yubioath/core/exc.py
# class CardError(Exception):
# 
#     def __init__(self, status, message=''):
#         super(CardError, self).__init__('Card Error (%04x): %s' %
#                                         (status, message))
#         self.status = status
# 
# class DeviceLockedError(Exception):
# 
#     def __init__(self):
#         super(DeviceLockedError, self).__init__('Device is locked!')
# 
# class NoSpaceError(Exception):
# 
#     def __init__(self):
#         super(NoSpaceError, self).__init__('No space available on device.')
# 
# Path: yubioath/core/utils.py
# def hmac_sha1(secret, message):
# def time_challenge(t=None):
# def parse_full(resp):
# def parse_truncated(resp):
# def format_code(code, digits=6):
# def parse_uri(uri):
# def derive_key(salt, passphrase):
# def der_pack(*values):
# def der_read(der_data, expected_t=None):
# def b2len(bs):
# def kill_scdaemon():
# def ccid_supported_but_disabled():
# def _get_pids_linux():
# def _get_pids_osx():
# def _get_pids_win():
#         WMI = GetObject('winmgmts:')
# NON_CCID_YK_PIDS = set([0x0110, 0x0113, 0x0114, 0x0401, 0x0402, 0x0403])
# 
# Path: yubioath/yubicommon/compat.py
# def int2byte(i):
#     if _PY2:
#         return chr(i)
#     return bytes((i,))
# 
# def byte2int(i):
#     if _PY2:
#         return ord(i)
#     return i


# Path: yubioath/core/standard.py
from .exc import CardError, DeviceLockedError, NoSpaceError
from .utils import (
    der_read, der_pack, hmac_sha1, derive_key, get_random_bytes,
    time_challenge, parse_truncated, format_code)
from yubioath.yubicommon.compat import int2byte, byte2int
import hashlib
import struct
import os

        resp, status = self._delegate.send_apdu(cl, ins, p1, p2, data)
        self._long_resp = len(resp) > 52  # 52 bytes resp, 2 bytes status...
        return resp, status


class YubiOathCcid(object):

    """
    Device interface to a OATH-enabled YubiKey.
    """

    def __init__(self, device):
        self._device = device

        self._select()

        if (4, 2, 0) <= self.version <= (4, 2, 6):
            self._device = _426Device(device)

    def _send(self, ins, data='', p1=0, p2=0, expected=0x9000):
        resp, status = self._device.send_apdu(0, ins, p1, p2, data)
        while (status >> 8) == RESP_MORE_DATA:
            more, status = self._device.send_apdu(
                0, INS_SEND_REMAINING, 0, 0, '')
            resp += more

        if status == YKOATH_NO_SPACE:
            raise NoSpaceError()

        if expected != status:

            raise CardError(status)