U
    ÈZjŒ  ã                   @   sÒ  d Z 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mZmZmZmZmZmZmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deeƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ deƒZ"G d d!„ d!eeƒZ#G d"d#„ d#eƒZ$G d$d%„ d%eƒZ%G d&d'„ d'eƒZ&G d(d)„ d)eƒZ'G d*d+„ d+eƒZ(G d,d-„ d-eƒZ)G d.d/„ d/eƒZ*G d0d1„ d1eƒZ+G d2d3„ d3eƒZ,G d4d5„ d5eƒZ-G d6d7„ d7eƒZ.G d8d9„ d9eƒZ/G d:d;„ d;eƒZ0G d<d=„ d=eƒZ1G d>d?„ d?eƒZ2G d@dA„ dAeƒZ3G dBdC„ dCeƒZ4G dDdE„ dEeeƒZ5G dFdG„ dGeƒZ6G dHdI„ dIeƒZ7G dJdK„ dKeƒZ8G dLdM„ dMeƒZ9e6e5j:dN< G dOdP„ dPeƒZ;G dQdR„ dReeƒZ<dSS )Ta¤  
ASN.1 type classes for various algorithms using in various aspects of public
key cryptography. Exports the following items:

 - AlgorithmIdentifier()
 - AnyAlgorithmIdentifier()
 - DigestAlgorithm()
 - DigestInfo()
 - DSASignature()
 - EncryptionAlgorithm()
 - HmacAlgorithm()
 - KdfAlgorithm()
 - Pkcs5MacAlgorithm()
 - SignedDigestAlgorithm()

Other type classes are defined that help compose the types listed above.
é    )Úunicode_literalsÚdivisionÚabsolute_importÚprint_functioné   )Úunwrap)Ú
fill_width)Úint_from_bytesÚint_to_bytes)ÚAnyÚChoiceÚIntegerÚNullÚObjectIdentifierÚOctetStringÚSequenceÚVoidc                   @   s"   e Zd ZdefdeddifgZdS )ÚAlgorithmIdentifierÚ	algorithmÚ
parametersÚoptionalTN)Ú__name__Ú
__module__Ú__qualname__r   r   Ú_fields© r   r   úS/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/asn1crypto/algos.pyr   +   s   þr   c                       sL   e Zd ZdZedddddddd	d
dg
ƒZdd„ ZdeiZ‡ fdd„Z‡  Z	S )Ú_ForceNullParametersz¡
    Various structures based on AlgorithmIdentifier require that the parameters
    field be core.Null() for certain OIDs. This mixin ensures that happens.
    ú1.2.840.113549.1.1.1ú1.2.840.113549.1.1.11ú1.2.840.113549.1.1.12ú1.2.840.113549.1.1.13ú1.2.840.113549.1.1.14ú1.3.14.3.2.26ú2.16.840.1.101.3.4.2.4ú2.16.840.1.101.3.4.2.1ú2.16.840.1.101.3.4.2.2ú2.16.840.1.101.3.4.2.3c                 C   s@   | j dkr(| d j}|| jkr(| j| S | d j| jkr<tS d S )N©r   r   r   )Ú	_oid_pairÚnativeÚ
_oid_specsÚdottedÚ_null_algosr   )ÚselfÚalgor   r   r   Ú_parameters_specJ   s    



z%_ForceNullParameters._parameters_specr   c                    sR   t t| ƒ ||¡}|dkr|S | d j| jkr2|S | d jtkrD|S tƒ | d< |S )Nr   r   )Úsuperr   Ú__setitem__r,   r-   Ú	__class__r   r   )r.   ÚkeyÚvalueÚres©r3   r   r   r2   _   s    
z _ForceNullParameters.__setitem__)
r   r   r   Ú__doc__Úsetr-   r0   Z_spec_callbacksr2   Ú__classcell__r   r   r7   r   r   2   s$   
ö ÿ
r   c                   @   s*   e Zd Zddddddddd	d
dddœZdS )ÚHmacAlgorithmIdZdes_macÚsha1Úsha224Úsha256Úsha384Úsha512Ú
sha512_224Ú
sha512_256Úsha3_224Úsha3_256Úsha3_384Úsha3_512)z1.3.14.3.2.10z1.2.840.113549.2.7z1.2.840.113549.2.8z1.2.840.113549.2.9z1.2.840.113549.2.10z1.2.840.113549.2.11z1.2.840.113549.2.12z1.2.840.113549.2.13z2.16.840.1.101.3.4.2.13z2.16.840.1.101.3.4.2.14z2.16.840.1.101.3.4.2.15z2.16.840.1.101.3.4.2.16N©r   r   r   Ú_mapr   r   r   r   r;   k   s   ôr;   c                   @   s"   e Zd ZdefdeddifgZdS )ÚHmacAlgorithmr   r   r   TN)r   r   r   r;   r   r   r   r   r   r   rI   |   s   þrI   c                   @   s4   e Zd Zddddddddd	d
ddddddddœZdS )ÚDigestAlgorithmIdÚmd2Úmd5r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   Zshake128Úshake256Zshake128_lenZshake256_len)z1.2.840.113549.2.2z1.2.840.113549.2.5r#   r$   r%   r&   r'   z2.16.840.1.101.3.4.2.5z2.16.840.1.101.3.4.2.6z2.16.840.1.101.3.4.2.7z2.16.840.1.101.3.4.2.8z2.16.840.1.101.3.4.2.9z2.16.840.1.101.3.4.2.10z2.16.840.1.101.3.4.2.11z2.16.840.1.101.3.4.2.12z2.16.840.1.101.3.4.2.17z2.16.840.1.101.3.4.2.18NrG   r   r   r   r   rJ   ƒ   s$   ïrJ   c                   @   s"   e Zd ZdefdeddifgZdS )ÚDigestAlgorithmr   r   r   TN)r   r   r   rJ   r   r   r   r   r   r   rN   ™   s   þrN   c                   @   s   e Zd ZdefdefgZdS )Ú
DigestInfoZdigest_algorithmÚdigestN)r   r   r   rN   r   r   r   r   r   r   rO   ¡   s   þrO   c                   @   s   e Zd ZddiZdS )ÚMaskGenAlgorithmIdz1.2.840.113549.1.1.8Úmgf1NrG   r   r   r   r   rQ   ¨   s    ÿrQ   c                   @   s.   e Zd ZdefdeddifgZdZdeiZdS )ÚMaskGenAlgorithmr   r   r   Tr(   rR   N)	r   r   r   rQ   r   r   r)   rN   r+   r   r   r   r   rS   ®   s   þ ÿrS   c                   @   s   e Zd ZddiZdS )ÚTrailerFieldr   Útrailer_field_bcNrG   r   r   r   r   rT   º   s    ÿrT   c                   @   sV   e Zd Zdedddidœfdeddddid	œdœfd
edddœfdedddœfgZdS )ÚRSASSAPSSParamsÚhash_algorithmr   r   r<   ©ÚexplicitÚdefaultÚmask_gen_algorithmr   rR   r(   Zsalt_lengthé   é   Ztrailer_fieldé   rU   N)r   r   r   rN   rS   r   rT   r   r   r   r   r   rV   À   s6   þý	þþýþý	þýärV   c                   @   s†   e Zd Zdddddddddddd	d	d	d
ddddddddddddddddœZdddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4œZd5S )6ÚSignedDigestAlgorithmIdÚmd5_rsaÚsha1_rsaÚmd2_rsaÚ
sha224_rsaÚ
sha256_rsaÚ
sha384_rsaÚ
sha512_rsaÚ
rsassa_pssÚsha1_dsaÚ
sha224_dsaÚ
sha256_dsaÚ
sha1_ecdsaÚsha224_ecdsaÚsha256_ecdsaÚsha384_ecdsaÚsha512_ecdsaÚsha3_224_ecdsaÚsha3_256_ecdsaÚsha3_384_ecdsaÚsha3_512_ecdsaÚrsassa_pkcs1v15ÚdsaÚecdsaÚed25519Úed448)z1.3.14.3.2.3z1.3.14.3.2.29z1.3.14.7.2.3.1ú1.2.840.113549.1.1.2ú1.2.840.113549.1.1.4ú1.2.840.113549.1.1.5r"   r   r    r!   ú1.2.840.113549.1.1.10ú1.2.840.10040.4.3z1.3.14.3.2.13z1.3.14.3.2.27ú2.16.840.1.101.3.4.3.1ú2.16.840.1.101.3.4.3.2ú1.2.840.10045.4.1ú1.2.840.10045.4.3.1ú1.2.840.10045.4.3.2ú1.2.840.10045.4.3.3ú1.2.840.10045.4.3.4ú2.16.840.1.101.3.4.3.9ú2.16.840.1.101.3.4.3.10ú2.16.840.1.101.3.4.3.11ú2.16.840.1.101.3.4.3.12r   ú1.2.840.10040.4.1ú1.2.840.10045.4ú1.3.101.112ú1.3.101.113r‰   rŠ   ry   rz   r   r|   r}   r€   r{   r~   r�   r"   r   r‚   r   rƒ   r    r„   r!   r…   r†   r‡   rˆ   r‹   rŒ   )ru   rv   rb   r`   rt   rg   rh   rk   ra   ri   rl   rc   rj   rm   rd   rn   re   ro   rf   rp   rq   rr   rs   rw   rx   N)r   r   r   rH   Z_reverse_mapr   r   r   r   r_   è   sr   à$çr_   c                   @   sF   e Zd ZdefdeddifgZdZdeiZe	dd„ ƒZ
e	d	d
„ ƒZdS )ÚSignedDigestAlgorithmr   r   r   Tr(   rg   c                 C   sd   | d j }ddddddddddddddddddddddddddœ}||krR|| S ttd	|ƒƒ‚d
S )zŒ
        :return:
            A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa",
            "ecdsa", "ed25519" or "ed448"
        r   rt   rg   ru   rv   rw   rx   )rb   r`   ra   rc   rd   re   rf   rt   rg   rh   ri   rj   ru   rk   rl   rm   rn   ro   rp   rq   rr   rs   rv   rw   rx   z>
            Signature algorithm not known for %s
            N©r*   Ú
ValueErrorr   ©r.   r   Zalgo_mapr   r   r   Úsignature_algo4  sB    
çüz$SignedDigestAlgorithm.signature_algoc                 C   sn   | d j }ddddddddddddddddd	d
œ}||krB|| S |dkr\| d d d j S ttd|ƒƒ‚dS )z­
        :return:
            A unicode string of "md2", "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", "sha512_224", "sha512_256" or "shake256"
        r   rK   rL   r<   r=   r>   r?   r@   rM   )rb   r`   ra   rc   rd   re   rf   rh   ri   rj   rk   rl   rm   rn   ro   rw   rx   rg   r   rW   z9
            Hash algorithm not known for %s
            NrŽ   r�   r   r   r   Ú	hash_algoc  s6    
ïüzSignedDigestAlgorithm.hash_algoN)r   r   r   r_   r   r   r)   rV   r+   Úpropertyr‘   r’   r   r   r   r   r�   )  s   þ ÿ
.r�   c                   @   s   e Zd ZdefdefgZdS )Ú
Pbkdf2SaltZ	specifiedÚother_sourceN)r   r   r   r   r   Z_alternativesr   r   r   r   r”   Ž  s   þr”   c                   @   s8   e Zd Zdefdefdeddifdeddd	iifgZd
S )ÚPbkdf2ParamsÚsaltÚiteration_countÚ
key_lengthr   TÚprfrZ   r   r<   N)r   r   r   r”   r   rI   r   r   r   r   r   r–   •  s
   ür–   c                   @   s   e Zd ZddiZdS )ÚKdfAlgorithmIdz1.2.840.113549.1.5.12Úpbkdf2NrG   r   r   r   r   r›   ž  s    ÿr›   c                   @   s.   e Zd ZdefdeddifgZdZdeiZdS )ÚKdfAlgorithmr   r   r   Tr(   rœ   N)	r   r   r   r›   r   r   r)   r–   r+   r   r   r   r   r�   ¤  s   þ ÿr�   c                   @   s,   e Zd ZdZdefdefdeddifgZdS )ÚDHParameterszn
    Original Name: DHParameter
    Source: ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-3.asc section 9
    ÚpÚgZprivate_value_lengthr   TN)r   r   r   r8   r   r   r   r   r   r   rž   ¯  s
   ýrž   c                   @   s   e Zd ZddiZdS )ÚKeyExchangeAlgorithmIdz1.2.840.113549.1.3.1ÚdhNrG   r   r   r   r   r¡   ¼  s    ÿr¡   c                   @   s.   e Zd ZdefdeddifgZdZdeiZdS )ÚKeyExchangeAlgorithmr   r   r   Tr(   r¢   N)	r   r   r   r¡   r   r   r)   rž   r+   r   r   r   r   r£   Â  s   þ ÿr£   c                   @   s"   e Zd ZdeddifdefgZdS )Ú	Rc2ParamsÚrc2_parameter_versionr   TÚivN)r   r   r   r   r   r   r   r   r   r   r¤   Í  s   þr¤   c                   @   s   e Zd ZddiZdS )ÚRc5ParamVersioné   zv1-0NrG   r   r   r   r   r§   Ô  s    ÿr§   c                   @   s.   e Zd ZdefdefdefdeddifgZdS )Ú	Rc5ParamsÚversionÚroundsÚblock_size_in_bitsr¦   r   TN)r   r   r   r§   r   r   r   r   r   r   r   r©   Ú  s
   ür©   c                   @   s   e Zd ZdefdefgZdS )ÚPbes1Paramsr—   Ú
iterationsN©r   r   r   r   r   r   r   r   r   r   r­   ã  s   þr­   c                   @   s   e Zd ZdefdefgZdS )Ú	CcmParamsZ	aes_nonceZ
aes_icvlenNr¯   r   r   r   r   r°   ê  s   þr°   c                   @   s   e Zd ZddiZdS )ÚPSourceAlgorithmIdz1.2.840.113549.1.1.9Úp_specifiedNrG   r   r   r   r   r±   ó  s    ÿr±   c                   @   s.   e Zd ZdefdeddifgZdZdeiZdS )ÚPSourceAlgorithmr   r   r   Tr(   r²   N)	r   r   r   r±   r   r   r)   r   r+   r   r   r   r   r³   ù  s   þ ÿr³   c                   @   sN   e Zd Zdedddidœfdeddddid	œdœfd
edddd	œdœfgZdS )ÚRSAESOAEPParamsrW   r   r   r<   rX   r[   r   rR   r(   Zp_source_algorithmr\   r²   ó    N)r   r   r   rN   rS   r³   r   r   r   r   r   r´     s.   þý	þþýþþýìr´   c                   @   s4   e Zd ZdZdefdefgZedd„ ƒZdd„ ZdS )	ÚDSASignaturea  
    An ASN.1 class for translating between the OS crypto library's
    representation of an (EC)DSA signature and the ASN.1 structure that is part
    of various RFCs.

    Original Name: DSS-Sig-Value
    Source: https://tools.ietf.org/html/rfc3279#section-2.2.2
    ÚrÚsc                 C   s>   t |dt|ƒd … ƒ}t |t|ƒd d… ƒ}| ||dœƒS )a  
        Reads a signature from a byte string encoding accordint to IEEE P1363,
        which is used by Microsoft's BCryptSignHash() function.

        :param data:
            A byte string from BCryptSignHash()

        :return:
            A DSASignature object
        r   r\   N)r·   r¸   )r	   Úlen)ÚclsÚdatar·   r¸   r   r   r   Ú
from_p13637  s    zDSASignature.from_p1363c                 C   sJ   t | d jƒ}t | d jƒ}tt|ƒt|ƒƒ}t||ƒ}t||ƒ}|| S )zÎ
        Dumps a signature to a byte string compatible with Microsoft's
        BCryptVerifySignature() function.

        :return:
            A byte string compatible with BCryptVerifySignature()
        r·   r¸   )r
   r*   Úmaxr¹   r   )r.   Zr_bytesZs_bytesZint_byte_lengthr   r   r   Úto_p1363H  s    	

zDSASignature.to_p1363N)	r   r   r   r8   r   r   Úclassmethodr¼   r¾   r   r   r   r   r¶   (  s   
þ
r¶   c                -   @   sj   e Zd Zddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-œ,Zd.S )/ÚEncryptionAlgorithmIdÚdesÚtripledes_3keyÚrc2Úrc4Úrc5Z
aes128_ecbÚ
aes128_cbcÚ
aes128_ofbZ
aes128_cfbZaes128_wrapZ
aes128_gcmÚ
aes128_ccmZaes128_wrap_padZ
aes192_ecbÚ
aes192_cbcÚ
aes192_ofbZ
aes192_cfbZaes192_wrapZ
aes192_gcmÚ
aes192_ccmZaes192_wrap_padZ
aes256_ecbÚ
aes256_cbcÚ
aes256_ofbZ
aes256_cfbZaes256_wrapZ
aes256_gcmÚ
aes256_ccmZaes256_wrap_padÚpbes2Úpbes1_md2_desÚpbes1_md5_desÚpbes1_md2_rc2Úpbes1_md5_rc2Úpbes1_sha1_desÚpbes1_sha1_rc2Úpkcs12_sha1_rc4_128Úpkcs12_sha1_rc4_40Úpkcs12_sha1_tripledes_3keyÚpkcs12_sha1_tripledes_2keyÚpkcs12_sha1_rc2_128Úpkcs12_sha1_rc2_40Zrsaes_pkcs1v15Ú
rsaes_oaep),z1.3.14.3.2.7z1.2.840.113549.3.7z1.2.840.113549.3.2z1.2.840.113549.3.4z1.2.840.113549.3.9z2.16.840.1.101.3.4.1.1z2.16.840.1.101.3.4.1.2z2.16.840.1.101.3.4.1.3z2.16.840.1.101.3.4.1.4z2.16.840.1.101.3.4.1.5z2.16.840.1.101.3.4.1.6z2.16.840.1.101.3.4.1.7z2.16.840.1.101.3.4.1.8z2.16.840.1.101.3.4.1.21z2.16.840.1.101.3.4.1.22z2.16.840.1.101.3.4.1.23z2.16.840.1.101.3.4.1.24z2.16.840.1.101.3.4.1.25z2.16.840.1.101.3.4.1.26z2.16.840.1.101.3.4.1.27z2.16.840.1.101.3.4.1.28z2.16.840.1.101.3.4.1.41z2.16.840.1.101.3.4.1.42z2.16.840.1.101.3.4.1.43z2.16.840.1.101.3.4.1.44z2.16.840.1.101.3.4.1.45z2.16.840.1.101.3.4.1.46z2.16.840.1.101.3.4.1.47z2.16.840.1.101.3.4.1.48z1.2.840.113549.1.5.13z1.2.840.113549.1.5.1z1.2.840.113549.1.5.3z1.2.840.113549.1.5.4z1.2.840.113549.1.5.6z1.2.840.113549.1.5.10z1.2.840.113549.1.5.11z1.2.840.113549.1.12.1.1z1.2.840.113549.1.12.1.2z1.2.840.113549.1.12.1.3z1.2.840.113549.1.12.1.4z1.2.840.113549.1.12.1.5z1.2.840.113549.1.12.1.6r   z1.2.840.113549.1.1.7NrG   r   r   r   r   rÀ   [  sZ   ÐrÀ   c                   @   sÌ   e Zd ZdefdeddifgZdZeeee	eeeeeee
e
e
eeeeeeeeeeeeedœZedd„ ƒZed	d
„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )ÚEncryptionAlgorithmr   r   r   Tr(   )rÁ   rÂ   rÃ   rÅ   rÆ   rÉ   rÌ   rÇ   rÊ   rÍ   rÈ   rË   rÎ   rÐ   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   rÛ   rÜ   c                 C   sˆ   | d j }|dkr$| d d d j S | d¡dkrv| d¡dkrh| dd¡\}}|d	kr\d
S |dkrhdS ttd|ƒƒ‚ttd|ƒƒ‚dS )z¼
        Returns the name of the key derivation function to use.

        :return:
            A unicode from of one of the following: "pbkdf1", "pbkdf2",
            "pkcs12_kdf"
        r   rÏ   r   Úkey_derivation_funcÚ.éÿÿÿÿÚ_r   Zpbes1Zpbkdf1Zpkcs12Z
pkcs12_kdfú~
                Encryption algorithm "%s" does not have a registered key
                derivation function
                zw
            Unrecognized encryption algorithm "%s", can not determine key
            derivation function
            N©r*   ÚfindÚsplitr�   r   )r.   Úencryption_algorá   r   r   r   Úkdf¸  s$    

ûûzEncryptionAlgorithm.kdfc                 C   s~   | d j }|dkr,| d d d d d j S | d¡dkrl| d¡dkr^| dd	¡\}}}|S ttd
|ƒƒ‚ttd|ƒƒ‚dS )zÒ
        Returns the HMAC algorithm to use with the KDF.

        :return:
            A unicode string of one of the following: "md2", "md5", "sha1",
            "sha224", "sha256", "sha384", "sha512"
        r   rÏ   r   rÞ   rš   rß   rà   rá   r\   râ   z}
            Unrecognized encryption algorithm "%s", can not determine key
            derivation hmac algorithm
            Nrã   )r.   ræ   rá   Z	hmac_algor   r   r   Úkdf_hmacá  s    

ûûzEncryptionAlgorithm.kdf_hmacc                 C   sŒ   | d j }|dkrB| d d d d }|jdkr<ttdƒƒ‚|j S | d¡d	krz| d
¡d	krl| d d j S ttd|ƒƒ‚ttd|ƒƒ‚dS )zu
        Returns the byte string to use as the salt for the KDF.

        :return:
            A byte string
        r   rÏ   r   rÞ   r—   r•   zÛ
                    Can not determine key derivation salt - the
                    reserved-for-future-use other source salt choice was
                    specified in the PBKDF2 params structure
                    rß   rà   rá   râ   zs
            Unrecognized encryption algorithm "%s", can not determine key
            derivation salt
            N)r*   Únamer�   r   rä   )r.   ræ   r—   r   r   r   Úkdf_salt  s&    	

ÿûûzEncryptionAlgorithm.kdf_saltc                 C   sr   | d j }|dkr(| d d d d j S | d¡dkr`| d¡dkrR| d d	 j S ttd
|ƒƒ‚ttd|ƒƒ‚dS )z{
        Returns the number of iterations that should be run via the KDF.

        :return:
            An integer
        r   rÏ   r   rÞ   r˜   rß   rà   rá   r®   râ   zy
            Unrecognized encryption algorithm "%s", can not determine key
            derivation iterations
            N)r*   rä   r�   r   ©r.   ræ   r   r   r   Úkdf_iterations2  s    	
ûûz"EncryptionAlgorithm.kdf_iterationsc                 C   s  | d j }|dd… dkr2ddddœ|dd	…  S d
ddœ}||krL|| S |dkr¢| d d j }dd
ddœ}||kr~|| S |dkrŠ|S |dkr–dS ttdƒƒ‚|dkrÚ| d d d d j }|dk	rÌ|S | d d jS | d¡dk�rd
d
d
d
d
d
dddddddœ| S ttd|ƒƒ‚dS )aî  
        Returns the key length to pass to the cipher/kdf. The PKCS#5 spec does
        not specify a way to store the RC5 key length, however this tends not
        to be a problem since OpenSSL does not support RC5 in PKCS#8 and OS X
        does not provide an RC5 cipher for use in the Security Transforms
        library.

        :raises:
            ValueError - when the key length can not be determined

        :return:
            An integer representing the length in bytes
        r   r   r^   Úaesr¨   é   é    )Úaes128_Úaes192_Úaes256_é   é   )rÁ   rÂ   rÃ   r   r¥   é   )é    éx   é:   é   Né   zw
                Invalid RC2 parameter version found in EncryptionAlgorithm
                parameters
                rÏ   rÞ   r™   Úencryption_schemerß   rà   ©rÐ   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   rÛ   ú@
            Unrecognized encryption algorithm "%s"
            )r*   r�   r   r™   rä   )r.   ræ   Zcipher_lengthsr¥   Zencoded_key_bits_mapr™   r   r   r   r™   T  sj    
ý
üþýÿôóüzEncryptionAlgorithm.key_lengthc                 C   s˜   | d j }|dd… tdddgƒkr0|dd… S |dd… d	krDd
S |dd… dkrXd
S |tddddgƒkrpd
S |dkr†| d d jS ttd|ƒƒ‚dS )zÔ
        Returns the name of the encryption mode to use.

        :return:
            A unicode string from one of the following: "cbc", "ecb", "ofb",
            "cfb", "wrap", "gcm", "ccm", "wrap_pad"
        r   r   ró   rð   rñ   rò   Né   Zpbes1_ZcbcZpkcs12_rÁ   rÂ   rÃ   rÅ   rÏ   r   rû   rý   )r*   r9   Úencryption_moder�   r   rë   r   r   r   rÿ   ³  s    

üz#EncryptionAlgorithm.encryption_modec                 C   s¢   | d j }|dd… tdddgƒkr(dS |tdd	d
gƒkr>|S |dkrJdS |dkr`| d d jS | d¡dkr�ddd	d	dd	ddddd	d	dœ| S ttd|ƒƒ‚dS )al  
        Returns the name of the symmetric encryption cipher to use. The key
        length can be retrieved via the .key_length property to disabiguate
        between different variations of TripleDES, AES, and the RC* ciphers.

        :return:
            A unicode string from one of the following: "rc2", "rc5", "des",
            "tripledes", "aes"
        r   r   ró   rð   rñ   rò   rí   rÁ   rÃ   rÅ   rÂ   Z	tripledesrÏ   r   rû   rß   rà   rÄ   rü   rý   N)r*   r9   Úencryption_cipherrä   r�   r   rë   r   r   r   r   Õ  s:    
ôóüz%EncryptionAlgorithm.encryption_cipherc                 C   s¶   | d j }|dd… tdddgƒkr(dS dddd	œ}||krD|| S |d
kr^| d d j d S |dkrt| d d jS | d¡dkr¤dddddddddddddœ| S ttd|ƒƒ‚dS )z•
        Returns the block size of the encryption cipher, in bytes.

        :return:
            An integer that is the block size in bytes
        r   r   ró   rð   rñ   rò   r¨   rô   )rÁ   rÂ   rÃ   rÅ   r   r¬   rÏ   rû   rß   rà   rü   rý   N)r*   r9   Úencryption_block_sizerä   r�   r   )r.   ræ   Z
cipher_mapr   r   r   r    sB    	
ýôóüz)EncryptionAlgorithm.encryption_block_sizec              	   C   sŒ   | d j }|tddgƒkr(| d d j S tdddd	d
dddgƒ}||krR| d j S |dkrh| d d jS | d¡dkrzdS ttd|ƒƒ‚dS )a  
        Returns the byte string of the initialization vector for the encryption
        scheme. Only the PBES2 stores the IV in the params. For PBES1, the IV
        is derived from the KDF and this property will return None.

        :return:
            A byte string or None
        r   rÃ   rÅ   r   r¦   rÁ   rÂ   rÆ   rÉ   rÌ   rÇ   rÊ   rÍ   rÏ   rû   rß   rà   Nrý   )r*   r9   Úencryption_ivrä   r�   r   )r.   ræ   Zoctet_string_iv_oidsr   r   r   r  9  s.    
ø

üz!EncryptionAlgorithm.encryption_ivN)r   r   r   rÀ   r   r   r)   r   r¤   r©   r°   r­   r´   r+   r“   rç   rè   rê   rì   r™   rÿ   r   r  r  r   r   r   r   rÝ   �  sb   þâ!
(
#
,
!
^
!
0
2rÝ   c                   @   s   e Zd ZdefdefgZdS )ÚPbes2ParamsrÞ   rû   N)r   r   r   r�   rÝ   r   r   r   r   r   r  j  s   þr  c                   @   s   e Zd ZdefdefgZdS )ÚPbmac1ParamsrÞ   Zmessage_auth_schemeN)r   r   r   r�   rI   r   r   r   r   r   r  q  s   þr  c                   @   s   e Zd ZddiZdS )Ú
Pkcs5MacIdz1.2.840.113549.1.5.14Úpbmac1NrG   r   r   r   r   r  x  s    ÿr  c                   @   s(   e Zd ZdefdefgZdZdeiZdS )ÚPkcs5MacAlgorithmr   r   r(   r  N)	r   r   r   r  r   r   r)   r  r+   r   r   r   r   r  ~  s   þ ÿr  rÏ   c                   @   s   e Zd Zi Zdd„ ZdS )ÚAnyAlgorithmIdc                 C   s8   | j j}tttfD ] }|j ¡ D ]\}}|||< q qd S ©N)r3   rH   rÀ   r_   rJ   Úitems)r.   rH   Ú	other_clsÚoidré   r   r   r   Ú_setup�  s    zAnyAlgorithmId._setupN)r   r   r   rH   r  r   r   r   r   r  �  s   r  c                   @   s2   e Zd ZdefdeddifgZdZi Zdd„ ZdS )	ÚAnyAlgorithmIdentifierr   r   r   Tr(   c                 C   s@   t  | ¡ | jj}ttfD ] }|j ¡ D ]\}}|||< q(qd S r	  )r   r  r3   r+   rÝ   r�   r
  )r.   Úspecsr  r  Úspecr   r   r   r     s
    
zAnyAlgorithmIdentifier._setupN)	r   r   r   r  r   r   r)   r+   r  r   r   r   r   r  —  s   þr  N)=r8   Ú
__future__r   r   r   r   Ú_errorsr   Ú_intr   Úutilr	   r
   Úcorer   r   r   r   r   r   r   r   r   Úobjectr   r;   rI   rJ   rN   rO   rQ   rS   rT   rV   r_   r�   r”   r–   r›   r�   rž   r¡   r£   r¤   r§   r©   r­   r°   r±   r³   r´   r¶   rÀ   rÝ   r  r  r  r  r+   r  r  r   r   r   r   Ú<module>   s\   (9(Ae			#35   ]

