U afr@sddlmZmZmZmZddlmZddlmZddl m Z m Z ddl m Z ddlmZmZmZdd d gZeZed krd d lmZmZmZmZmZddZde_dd ZnddlmZddlmZdS))unicode_literalsdivisionabsolute_importprint_function)backend)pretty_message)buffer_from_bytesbytes_from_buffer) pkcs12_kdf) type_namebyte_cls int_typespbkdf2r rand_byteswin)bcrypt BcryptConst handle_erroropen_alg_handleclose_alg_handlec Cs4t|tsttdt|t|ts8ttdt|t|tsTttdt||dkrdtdt|tsttdt||dkrtd|tdd d d gkrttd t|t j t j t j t j d |}d}zJt|t j}t|}t||t||t||||d }t|t|WS|r.t|XdS)a% PBKDF2 from PKCS#5 :param hash_algorithm: The string name of the hash algorithm to use: "sha1", "sha256", "sha384", "sha512" :param password: A byte string of the password to use an input to the KDF :param salt: A cryptographic random byte string :param iterations: The numbers of iterations to use when deriving the key :param key_length: The length of the desired key in bytes :raises: ValueError - when any of the parameters contain an invalid value TypeError - when any of the parameters are of the wrong type OSError - when an error is returned by the OS crypto library :return: The derived key as a byte string zH password must be a byte string, not %s zD salt must be a byte string, not %s zG iterations must be an integer, not %s rz!iterations must be greater than 0zG key_length must be an integer, not %s z!key_length must be greater than 0sha1sha256sha384sha512z| hash_algorithm must be one of "sha1", "sha256", "sha384", "sha512", not %s )rrrrNr) isinstancer TypeErrorrr r ValueErrorsetreprrZBCRYPT_SHA1_ALGORITHMZBCRYPT_SHA256_ALGORITHMZBCRYPT_SHA384_ALGORITHMZBCRYPT_SHA512_ALGORITHMrrZBCRYPT_ALG_HANDLE_HMAC_FLAGr rZBCryptDeriveKeyPBKDF2lenrr ) Zhash_algorithmpasswordZsaltZ iterationsZ key_lengthZ alg_constant alg_handleZ output_bufferresr%C/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/oscrypto/_win/util.pyrsn        FcCst|tsttdt||dkr,td|dkrs"   j /