
    Bwgr                         d dl mZmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZmZ g dZ e       Zed	k(  rd
dlmZmZmZmZmZ d Zde_        d ZyddlmZ ddlmZ y)    )unicode_literalsdivisionabsolute_importprint_function   )backend)pretty_message)buffer_from_bytesbytes_from_buffer)
pkcs12_kdf)	type_namebyte_cls	int_types)pbkdf2r   
rand_byteswin   )bcryptBcryptConsthandle_erroropen_alg_handleclose_alg_handlec                    t        |t              st        t        dt	        |                  t        |t              st        t        dt	        |                  t        |t
              st        t        dt	        |                  |dk  rt        d      t        |t
              st        t        dt	        |                  |dk  rt        d      | t        g d      vrt        t        d	t        |                   t        j                  t        j                  t        j                  t        j                  d|    }d
}	 t        |t        j                        }t!        |      }t#        j$                  ||t'        |      |t'        |      |||d	      }t)        |       t+        |      |rt-        |       S S # |rt-        |       w w xY w)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
                r   z!iterations must be greater than 0zG
                key_length must be an integer, not %s
                z!key_length must be greater than 0)sha1sha256sha384sha512z|
                hash_algorithm must be one of "sha1", "sha256", "sha384", "sha512",
                not %s
                Nr   )
isinstancer   	TypeErrorr	   r   r   
ValueErrorsetreprr   BCRYPT_SHA1_ALGORITHMBCRYPT_SHA256_ALGORITHMBCRYPT_SHA384_ALGORITHMBCRYPT_SHA512_ALGORITHMr   BCRYPT_ALG_HANDLE_HMAC_FLAGr
   r   BCryptDeriveKeyPBKDF2lenr   r   r   )	hash_algorithmpasswordsalt
iterations
key_lengthalg_constant
alg_handleoutput_bufferress	            I/var/www/horilla/myenv/lib/python3.12/site-packages/oscrypto/_win/util.pyr   r      s   8 (H-N (#	   $)N $	   *i0N *%	   >@AA*i0N *%	   >@AA%K!LL^ ^$    55!99!99!99	

  
	-({7^7^_J-j9M..HD	
C $]3 , z , s   A)G GFc                    t        | t              st        t        dt	        |                   | dk  rt        d      | dkD  rt        d      d}	 t        t        j                        }t        |       }t        j                  ||| d      }t        |       t        |      |rt        |       S S # |rt        |       w w xY w)a  
        Returns a number of random bytes suitable for cryptographic purposes

        :param length:
            The desired number of 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:
            A byte string
        zC
                length must be an integer, not %s
                r   zlength must be greater than 0i   z$length must not be greater than 1024Nr   )r   r   r   r	   r   r    r   r   BCRYPT_RNG_ALGORITHMr
   r   BCryptGenRandomr   r   r   )lengthr0   bufferr2   s       r3   r   r      s      &),N &!	   A:<==D=CDD
	-()I)IJJ&v.F((VVQGC$V,  , z , s   AB2 2C)r   )r   N)
__future__r   r   r   r    r   _errorsr	   _ffir
   r   _pkcs12r   _typesr   r   r   __all___backend_cngr   r   r   r   r   r   pure_pythonr   _pkcs5_rand     r3   <module>rG      s\    R R  $ 7   3 3 9 uZZh-T F+-^  "rF   