# Path: webtools/utils/encoding.py
# def smart_bytes(value, encoding='utf-8', errors='strict'):
#     if isinstance(value, bytes):
#         if encoding == 'utf-8':
#             return value
# 
#         return value.decode('utf-8', errors).encode(encoding, errors)
# 
#     if not isinstance(value, str):
#         value = str(value)
# 
#     return value.encode(encoding, errors)


import hmac
import struct
import hashlib
import binascii
import operator
import time
import random
    import warnings
from functools import reduce
from webtools.utils.encoding import smart_bytes

    This function operates on bytes.
    """
    dig1, dig2 = digest(), digest()
    if len(key) > dig1.block_size:
        key = digest(key).digest()
    key += b'\x00' * (dig1.block_size - len(key))
    dig1.update(key.translate(_trans_36))
    dig1.update(msg)
    dig2.update(key.translate(_trans_5c))
    dig2.update(dig1.digest())
    return dig2


def pbkdf2(password, salt, iterations, dklen=0, digest=None):
    """
    Implements PBKDF2 as defined in RFC 2898, section 5.2

    HMAC+SHA256 is used as the default pseudo random function.

    Right now 10,000 iterations is the recommended default which takes
    100ms on a 2.2Ghz Core 2 Duo.  This is probably the bare minimum
    for security given 1000 iterations was recommended in 2001. This
    code is very well optimized for CPython and is only four times
    slower than openssl's implementation.
    """
    assert iterations > 0
    if not digest:
        digest = hashlib.sha256
    password = smart_bytes(password)

# Path: webtools/utils/encoding.py
# def smart_bytes(value, encoding='utf-8', errors='strict'):
#     if isinstance(value, bytes):
#         if encoding == 'utf-8':
#             return value
# 
#         return value.decode('utf-8', errors).encode(encoding, errors)
# 
#     if not isinstance(value, str):
#         value = str(value)
# 
#     return value.encode(encoding, errors)


# Path: webtools/utils/crypto.py
import hmac
import struct
import hashlib
import binascii
import operator
import time
import random
    import warnings
from functools import reduce
from webtools.utils.encoding import smart_bytes


    This function operates on bytes.
    """
    dig1, dig2 = digest(), digest()
    if len(key) > dig1.block_size:
        key = digest(key).digest()
    key += b'\x00' * (dig1.block_size - len(key))
    dig1.update(key.translate(_trans_36))
    dig1.update(msg)
    dig2.update(key.translate(_trans_5c))
    dig2.update(dig1.digest())
    return dig2


def pbkdf2(password, salt, iterations, dklen=0, digest=None):
    """
    Implements PBKDF2 as defined in RFC 2898, section 5.2

    HMAC+SHA256 is used as the default pseudo random function.

    Right now 10,000 iterations is the recommended default which takes
    100ms on a 2.2Ghz Core 2 Duo.  This is probably the bare minimum
    for security given 1000 iterations was recommended in 2001. This
    code is very well optimized for CPython and is only four times
    slower than openssl's implementation.
    """
    assert iterations > 0
    if not digest:
        digest = hashlib.sha256
    password = smart_bytes(password)

    salt = smart_bytes(salt)