# 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 yubioath.yubicommon.compat import int2byte, byte2int
from Crypto.Hash import HMAC, SHA
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Random import get_random_bytes
    from urlparse import urlparse, parse_qs
    from urllib import unquote
    from urllib.parse import unquote, urlparse, parse_qs
        from win32com.client import GetObject
        from win32api import OpenProcess, CloseHandle, TerminateProcess
import subprocess
import struct
import time
import sys
import re


def format_code(code, digits=6):
    return ('%%0%dd' % digits) % (code % 10 ** digits)


def parse_uri(uri):
    uri = uri.strip()  # Remove surrounding whitespace
    parsed = urlparse(uri)
    if parsed.scheme != 'otpauth':  # Not a uri, assume secret.
        return {'secret': uri}
    params = dict((k, v[0]) for k, v in parse_qs(parsed.query).items())
    params['name'] = unquote(parsed.path)[1:]  # Unquote and strip leading /
    params['type'] = parsed.hostname
    if 'issuer' in params and not params['name'].startswith(params['issuer']):
        params['name'] = params['issuer'] + ':' + params['name']
    return params


#
# General utils
#

def derive_key(salt, passphrase):
    if not passphrase:
        return None
    return PBKDF2(passphrase, salt, 16, 1000)


def der_pack(*values):

# 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/utils.py
from yubioath.yubicommon.compat import int2byte, byte2int
from Crypto.Hash import HMAC, SHA
from Crypto.Protocol.KDF import PBKDF2
from Crypto.Random import get_random_bytes
    from urlparse import urlparse, parse_qs
    from urllib import unquote
    from urllib.parse import unquote, urlparse, parse_qs
        from win32com.client import GetObject
        from win32api import OpenProcess, CloseHandle, TerminateProcess
import subprocess
import struct
import time
import sys
import re



def format_code(code, digits=6):
    return ('%%0%dd' % digits) % (code % 10 ** digits)


def parse_uri(uri):
    uri = uri.strip()  # Remove surrounding whitespace
    parsed = urlparse(uri)
    if parsed.scheme != 'otpauth':  # Not a uri, assume secret.
        return {'secret': uri}
    params = dict((k, v[0]) for k, v in parse_qs(parsed.query).items())
    params['name'] = unquote(parsed.path)[1:]  # Unquote and strip leading /
    params['type'] = parsed.hostname
    if 'issuer' in params and not params['name'].startswith(params['issuer']):
        params['name'] = params['issuer'] + ':' + params['name']
    return params


#
# General utils
#

def derive_key(salt, passphrase):
    if not passphrase:
        return None
    return PBKDF2(passphrase, salt, 16, 1000)


def der_pack(*values):

    return b''.join([int2byte(t) + int2byte(len(v)) + v for t, v in zip(