# 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
TAG_ALGO = 0x7b
TAG_TOUCH_RESPONSE = 0x7c

TYPE_MASK = 0xf0
TYPE_HOTP = 0x10
TYPE_TOTP = 0x20

ALG_MASK = 0x0f
ALG_SHA1 = 0x01
ALG_SHA256 = 0x02

PROP_ALWAYS_INC = 0x01
PROP_REQUIRE_TOUCH = 0x02

SCHEME_STANDARD = 0x00
SCHEME_STEAM = 0x01

STEAM_CHAR_TABLE = "23456789BCDFGHJKMNPQRTVWXY"


def format_code_steam(int_data, digits):
    chars = []
    for i in range(5):
        chars.append(STEAM_CHAR_TABLE[int_data % len(STEAM_CHAR_TABLE)])
        int_data //= len(STEAM_CHAR_TABLE)
    return ''.join(chars)


def ensure_unlocked(ykoath):
    if ykoath.locked:

# 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

TAG_ALGO = 0x7b
TAG_TOUCH_RESPONSE = 0x7c

TYPE_MASK = 0xf0
TYPE_HOTP = 0x10
TYPE_TOTP = 0x20

ALG_MASK = 0x0f
ALG_SHA1 = 0x01
ALG_SHA256 = 0x02

PROP_ALWAYS_INC = 0x01
PROP_REQUIRE_TOUCH = 0x02

SCHEME_STANDARD = 0x00
SCHEME_STEAM = 0x01

STEAM_CHAR_TABLE = "23456789BCDFGHJKMNPQRTVWXY"


def format_code_steam(int_data, digits):
    chars = []
    for i in range(5):
        chars.append(STEAM_CHAR_TABLE[int_data % len(STEAM_CHAR_TABLE)])
        int_data //= len(STEAM_CHAR_TABLE)
    return ''.join(chars)


def ensure_unlocked(ykoath):
    if ykoath.locked:

        raise DeviceLockedError()