
    Bwg                         d dl mZmZmZmZ d dlZd dlZd dlZddlm	Z	m
Z
 ddlmZ ddlmZmZmZ ej"                  dk  reZnd Zd	gZd
 Zy)    )unicode_literalsdivisionabsolute_importprint_functionN   )int_from_bytesint_to_bytes)pretty_message)	type_namebyte_cls	int_types)   c                     t        | g      S )N)bytes)nums    G/var/www/horilla/myenv/lib/python3.12/site-packages/oscrypto/_pkcs12.pychr_clsr      s    cU|    
pkcs12_kdfc           
         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        t        dt        |                  t        |t
              st        t        dt	        |                  |dk  rt        t        dt        |                  | t        g d      vrt        t        d	t        |                   |t        g d
      vrt        t        dt        |                  |j                  d      j                  d      dz   }t        t        |       }ddddddd|    }| dv rd}	nd}	t        |      |	z  }
d}|dk7  r]|	t        t        j                   t#        t%        |            |	z              z  }t%        |      |k  r||z  }t%        |      |k  r|d| }d}|dk7  r]|	t        t        j                   t#        t%        |            |	z              z  }t%        |      |k  r||z  }t%        |      |k  r|d| }||z   }t        t        j                   t#        |      |z              }d||z  z  }t'        d|dz         D ]  } ||
|z         j)                         }t'        d|dz         D ]  } ||      j)                         } ||k  rd}t%        |      |	k  r||z  }t%        |      |	k  rt+        |d|	       dz   }t'        dt%        |      |	z        D ]Q  }||	z  }|dz   |	z  }||| }t-        t+        |      |z         }t%        |      }||	kD  r|||	z
  d }|d| |z   ||d z   }S |dz
  |z  }t/        ||      }|d| |d| z   |||z   d z   } |d| S )a  
    KDF from RFC7292 appendix b.2 - https://tools.ietf.org/html/rfc7292#page-19

    :param hash_algorithm:
        The string name of the hash algorithm to use: "md5", "sha1", "sha224",
        "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

    :param id_:
        The ID of the usage - 1 for key, 2 for iv, 3 for mac

    :return:
        The derived key as a byte string
    z@
            password must be a byte string, not %s
            z<
            salt must be a byte string, not %s
            z?
            iterations must be an integer, not %s
            r   zC
            iterations must be greater than 0 - is %s
            z?
            key_length must be an integer, not %s
            zC
            key_length must be greater than 0 - is %s
            )md5sha1sha224sha256sha384sha512z
            hash_algorithm must be one of "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", not %s
            )r      r   z<
            id_ must be one of 1, 2, 3, not %s
            zutf-8zutf-16bes                  0   @   )r   r      r   r       r   N)
isinstancer   	TypeErrorr
   r   r   
ValueErrorreprsetdecodeencodegetattrhashlibr   intmathceilfloatlenrangedigestr   r	   min)hash_algorithmpasswordsalt
iterations
key_lengthid_utf16_passwordalgouvdss_lenpp_lenicar   a2_bnum2startendi_num2i_num2_lbeginto_copys                                r   r   r      sl   6 h) h	
  	 dH% dO	
  	 j), j!	
  	 A~ 	
  	 j), j!	
  	 A~ 	
  	 S!XYY  
  	 #i.  I	
  	 __W-44Z@;NN7N+D 	 	A -- 	qA 	As{C		%D	"2Q"6788!funIA !funaJ 	AC		%N(;"<q"@ABB!funA !funaJ 	
AA 	DIIeJ'!+,-A1q5AQA  =!a%[!q*q.) 	#Ab"B	# 7Aa&1*R a&1* q1v&*A aQ1- 2qax1n5%nV&<q&@A v;a<#HqLM2FaJ'!CD'12 qAj!$aJAg&57?+;)<<A =D Qz?r   )
__future__r   r   r   r   sysr.   r0   _asn1r   r	   _errorsr
   _typesr   r   r   version_infochrr   __all__r    r   r   <module>r\      sL    R R 
   / # 2 2 dG
 
lr   