o
    Œõ±jŒ  ã                   @   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                   @   ó"   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   úƒ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asn1crypto/algos.pyr   +   ó    þr   c                       s<   e Zd ZdZeg d¢ƒ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v r| j| S | d j| jv 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vr|S | d jtkr"|S tƒ | d< |S )Nr   r   )Úsuperr   Ú__setitem__r.   r/   Ú	__class__r   r   )r0   ÚkeyÚvalueÚres©r5   r   r   r4   _   s   
z _ForceNullParameters.__setitem__)
r   r   r   Ú__doc__Úsetr/   r2   Ú_spec_callbacksr4   Ú__classcell__r   r   r9   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 )ÚHmacAlgorithmIdÚ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                   @   r   )ÚHmacAlgorithmr   r   r   TN)r   r   r   r>   r   r   r   r   r   r   rM   |   r   rM   c                   @   sv   e Zd Zi 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 )$ÚDigestAlgorithmIdz1.2.840.113549.2.2Úmd2z1.2.840.113549.2.5Úmd5r%   r@   r&   rA   r'   rB   r(   rC   r)   rD   z2.16.840.1.101.3.4.2.5rE   z2.16.840.1.101.3.4.2.6rF   z2.16.840.1.101.3.4.2.7rG   z2.16.840.1.101.3.4.2.8rH   z2.16.840.1.101.3.4.2.9rI   z2.16.840.1.101.3.4.2.10rJ   z2.16.840.1.101.3.4.2.11Úshake128z2.16.840.1.101.3.4.2.12Úshake256z2.16.840.1.101.3.4.2.17Úshake128_lenz2.16.840.1.101.3.4.2.18Úshake256_lenNrK   r   r   r   r   rN   ƒ   sH    ÿþýüûúùø	÷
öõôóòñðïrN   c                   @   r   )ÚDigestAlgorithmr   r   r   TN)r   r   r   rN   r   r   r   r   r   r   rU   ™   r   rU   c                   @   ó   e Zd ZdefdefgZdS )Ú
DigestInfoÚdigest_algorithmÚdigestN)r   r   r   rU   r   r   r   r   r   r   rW   ¡   ó    þrW   c                   @   ó   e Zd ZddiZdS )ÚMaskGenAlgorithmIdz1.2.840.113549.1.1.8Úmgf1NrK   r   r   r   r   r\   ¨   ó    ÿr\   c                   @   ó.   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*   r]   N)	r   r   r   r\   r   r   r+   rU   r-   r   r   r   r   r`   ®   ó    þÿr`   c                   @   r[   )ÚTrailerFieldr   Útrailer_field_bcNrK   r   r   r   r   rb   º   r^   rb   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   r]   r*   Úsalt_lengthé   é   Útrailer_fieldé   rc   N)r   r   r   rU   r`   r   rb   r   r   r   r   r   rd   À   s8    þý	þþýþý	þýärd   c                   @   s  e Zd Zi 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(d)d*d+œ¥Zi 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d0“dd“d d1“dd“d2dd3d4d5d6d7d8d9œ¥Zd:S );ÚSignedDigestAlgorithmIdz1.3.14.3.2.3Úmd5_rsaz1.3.14.3.2.29Úsha1_rsaz1.3.14.7.2.3.1Úmd2_rsaz1.2.840.113549.1.1.2z1.2.840.113549.1.1.4z1.2.840.113549.1.1.5r$   Ú
sha224_rsar!   Ú
sha256_rsar"   Ú
sha384_rsar#   Ú
sha512_rsaz1.2.840.113549.1.1.10Ú
rsassa_pssz1.2.840.10040.4.3Úsha1_dsaz1.3.14.3.2.13z1.3.14.3.2.27z2.16.840.1.101.3.4.3.1Ú
sha224_dsaz2.16.840.1.101.3.4.3.2Ú
sha256_dsaz1.2.840.10045.4.1Ú
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)ú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’   r    r‰   rŠ   r‹   rŒ   r�   rŽ   r�   r�   r“   r”   )r   rv   r€   r�   r‚   rƒ   r‡   rˆ   N)r   r   r   rL   Ú_reverse_mapr   r   r   r   ro   è   s¼    ÿþýüûúùø	÷
öõôóòñðïà#ÿþýüûúùø	÷
öõôóòñðïçro   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*   rw   c              
   C   s¨   | d j }i 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œ¥}||v rM|| S ttd|ƒƒ‚)zŒ
        :return:
            A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa",
            "ecdsa", "ed25519" or "ed448"
        r   rr   r„   rp   rq   rs   rt   ru   rv   rw   rx   r…   ry   rz   r{   r†   r|   r}   r~   r‡   rˆ   )r   r€   r�   r‚   rƒ   r†   r‡   rˆ   z>
            Signature algorithm not known for %s
            ©r,   Ú
ValueErrorr   ©r0   r   Úalgo_mapr   r   r   Úsignature_algo4  sf   
ÿþýüûúùø	÷
öõôóòñðïçüz$SignedDigestAlgorithm.signature_algoc                 C   s¬   | d j }i 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“}||v rB|| S |dkrO| d d d j S ttd|ƒƒ‚)z­
        :return:
            A unicode string of "md2", "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", "sha512_224", "sha512_256" or "shake256"
        r   rr   rO   rp   rP   rq   r@   rs   rA   rt   rB   ru   rC   rv   rD   rx   ry   rz   r{   r|   r}   r~   r   r‡   rˆ   rR   rw   r   re   z9
            Hash algorithm not known for %s
            r—   r™   r   r   r   Ú	hash_algoc  sX   
ÿþýüûúùø	÷
öõôóòñðïüzSignedDigestAlgorithm.hash_algoN)r   r   r   ro   r   r   r+   rd   r-   Úpropertyr›   rœ   r   r   r   r   r–   )  s    þÿ
.r–   c                   @   rV   )Ú
Pbkdf2SaltÚ	specifiedÚother_sourceN)r   r   r   r   r   Ú_alternativesr   r   r   r   rž   Ž  rZ   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Úprfrh   r   r@   N)r   r   r   rž   r   rM   r   r   r   r   r   r¢   •  s    ür¢   c                   @   r[   )ÚKdfAlgorithmIdz1.2.840.113549.1.5.12Úpbkdf2NrK   r   r   r   r   r§   ž  r^   r§   c                   @   r_   )ÚKdfAlgorithmr   r   r   Tr*   r¨   N)	r   r   r   r§   r   r   r+   r¢   r-   r   r   r   r   r©   ¤  ó    þÿ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ÚgÚprivate_value_lengthr   TN)r   r   r   r:   r   r   r   r   r   r   r«   ¯  s    ýr«   c                   @   r[   )ÚKeyExchangeAlgorithmIdz1.2.840.113549.1.3.1ÚdhNrK   r   r   r   r   r¯   ¼  r^   r¯   c                   @   r_   )ÚKeyExchangeAlgorithmr   r   r   Tr*   r°   N)	r   r   r   r¯   r   r   r+   r«   r-   r   r   r   r   r±   Â  rª   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                   @   r[   )ÚRc5ParamVersioné   zv1-0NrK   r   r   r   r   rµ   Ô  r^   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                   @   rV   )ÚPbes1Paramsr£   Ú
iterationsN©r   r   r   r   r   r   r   r   r   r   r»   ã  rZ   r»   c                   @   rV   )Ú	CcmParamsÚ	aes_nonceÚ
aes_icvlenNr½   r   r   r   r   r¾   ê  s    þr¾   c                   @   r[   )ÚPSourceAlgorithmIdz1.2.840.113549.1.1.9Úp_specifiedNrK   r   r   r   r   rÁ   ó  r^   rÁ   c                   @   r_   )ÚPSourceAlgorithmr   r   r   Tr*   rÂ   N)	r   r   r   rÁ   r   r   r+   r   r-   r   r   r   r   rÃ   ù  ra   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 )ÚRSAESOAEPParamsre   r   r   r@   rf   ri   r   r]   r*   Úp_source_algorithmrk   rÂ   ó    N)r   r   r   rU   r`   rÃ   r   r   r   r   r   rÄ     s0    þý	þþýþþýì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   rk   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   )r0   Úr_bytesÚs_bytesÚint_byte_lengthr   r   r   Úto_p1363H  s   	

zDSASignature.to_p1363N)	r   r   r   r:   r   r   ÚclassmethodrÍ   rÒ   r   r   r   r   rÇ   (  s    
þ
rÇ   c                   @   sú   e Zd Zi 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"“i d#d$“d%d&“d'd(“d)d*“d+d,“d-d.“d/d0“d1d2“d3d4“d5d6“d7d8“d9d:“d;d<“d=d>“d?d@“dAdB“dCdD“¥dEdFdGdHdIdJdKdLdMdNdOœ
¥ZdPS )QÚEncryptionAlgorithmIdz1.3.14.3.2.7Údesz1.2.840.113549.3.7Útripledes_3keyz1.2.840.113549.3.2Úrc2z1.2.840.113549.3.4Úrc4z1.2.840.113549.3.9Úrc5z2.16.840.1.101.3.4.1.1Ú
aes128_ecbz2.16.840.1.101.3.4.1.2Ú
aes128_cbcz2.16.840.1.101.3.4.1.3Ú
aes128_ofbz2.16.840.1.101.3.4.1.4Ú
aes128_cfbz2.16.840.1.101.3.4.1.5Úaes128_wrapz2.16.840.1.101.3.4.1.6Ú
aes128_gcmz2.16.840.1.101.3.4.1.7Ú
aes128_ccmz2.16.840.1.101.3.4.1.8Úaes128_wrap_padz2.16.840.1.101.3.4.1.21Ú
aes192_ecbz2.16.840.1.101.3.4.1.22Ú
aes192_cbcz2.16.840.1.101.3.4.1.23Ú
aes192_ofbz2.16.840.1.101.3.4.1.24Ú
aes192_cfbz2.16.840.1.101.3.4.1.25Úaes192_wrapz2.16.840.1.101.3.4.1.26Ú
aes192_gcmz2.16.840.1.101.3.4.1.27Ú
aes192_ccmz2.16.840.1.101.3.4.1.28Úaes192_wrap_padz2.16.840.1.101.3.4.1.41Ú
aes256_ecbz2.16.840.1.101.3.4.1.42Ú
aes256_cbcz2.16.840.1.101.3.4.1.43Ú
aes256_ofbz2.16.840.1.101.3.4.1.44Ú
aes256_cfbz2.16.840.1.101.3.4.1.45Úaes256_wrapz2.16.840.1.101.3.4.1.46Ú
aes256_gcmz2.16.840.1.101.3.4.1.47Ú
aes256_ccmz2.16.840.1.101.3.4.1.48Úaes256_wrap_padz1.2.840.113549.1.5.13Úpbes2z1.2.840.113549.1.5.1Úpbes1_md2_desz1.2.840.113549.1.5.3Úpbes1_md5_desz1.2.840.113549.1.5.4Úpbes1_md2_rc2z1.2.840.113549.1.5.6Ú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_40Úrsaes_pkcs1v15Ú
rsaes_oaep)
z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.7NrK   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i de“de“de“d	e	“d
e“de“de“de“de“de“de
“de
“de
“de“de“de“d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r;| d¡dkr4| dd¡\}}|d	kr.d
S |dkr4dS ttd|ƒƒ‚ttd|ƒƒ‚)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   Úpbes1Úpbkdf1Úpkcs12Ú
pkcs12_kdfú~
                Encryption algorithm "%s" does not have a registered key
                derivation function
                zw
            Unrecognized encryption algorithm "%s", can not determine key
            derivation function
            ©r,   ÚfindÚsplitr˜   r   )r0   Úencryption_algor  r   r   r   Úkdf¸  s$   

ûûzEncryptionAlgorithm.kdfc                 C   sz   | d j }|dkr| d d d d d j S | d¡dkr6| d¡dkr/| dd	¡\}}}|S ttd
|ƒƒ‚ttd|ƒƒ‚)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  rk   r
  z}
            Unrecognized encryption algorithm "%s", can not determine key
            derivation hmac algorithm
            r  )r0   r  r  Ú	hmac_algor   r   r   Úkdf_hmacá  s   

ûûzEncryptionAlgorithm.kdf_hmacc                 C   sˆ   | d j }|dkr!| d d d d }|jdkrttdƒƒ‚|j S | d¡d	kr=| d
¡d	kr6| d d j S ttd|ƒƒ‚ttd|ƒƒ‚)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
            )r,   Únamer˜   r   r  )r0   r  r£   r   r   r   Úkdf_salt  s&   
	
ÿûûzEncryptionAlgorithm.kdf_saltc                 C   sn   | d j }|dkr| d d d d j S | d¡dkr0| d¡dkr)| d d	 j S ttd
|ƒƒ‚ttd|ƒƒ‚)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
            )r,   r  r˜   r   ©r0   r  r   r   r   Úkdf_iterations2  s   
	ûûz"EncryptionAlgorithm.kdf_iterationsc                 C   s  | d j }|dd… dkrddddœ|dd	…  S d
ddœ}||v r&|| S |dkrQ| d d j }dd
ddœ}||v r?|| S |dkrE|S |du rKdS ttdƒƒ‚|dkrm| d d d d j }|durf|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|ƒƒ‚)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   rn   Ú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  )r0   r  Úcipher_lengthsr³   Úencoded_key_bits_mapr¥   r   r   r   r¥   T  sj   
ý
üþýÿôóüzEncryptionAlgorithm.key_lengthc                 C   sŽ   | d j }|dd… tg d¢ƒv r|dd… S |dd… dkr!dS |dd… d	kr+dS |tg d
¢ƒv r5dS |dkr@| d d jS ttd|ƒƒ‚)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  Né   Úpbes1_ÚcbcÚpkcs12_)rÕ   rÖ   r×   rÙ   rò   r   r%  r'  )r,   r;   Úencryption_moder˜   r   r  r   r   r   r.  ³  s   

üz#EncryptionAlgorithm.encryption_modec                 C   sš   | d j }|dd… tg d¢ƒv rdS |tg d¢ƒv r|S |dkr#dS |d	kr.| d
 d jS | d¡dkrFdddddddddddddœ| S ttd|ƒƒ‚)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Ö   Ú	tripledesrò   r   r%  r  r  rÕ   r×   rØ   r&  r'  )r,   r;   Úencryption_cipherr  r˜   r   r  r   r   r   r0  Õ  s:   
ôóüz%EncryptionAlgorithm.encryption_cipherc                 C   s°   | d j }|dd… tg d¢ƒv rdS ddddœ}||v r!|| S |dkr.| d	 d
 j d S |dkr9| d	 d jS | d¡dkrQdddddddddddddœ| S ttd|ƒƒ‚)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;   Úencryption_block_sizer  r˜   r   )r0   r  Ú
cipher_mapr   r   r   r1    sB   
	ýôóüz)EncryptionAlgorithm.encryption_block_sizec                 C   s|   | d j }|tddgƒv r| d d j S tg d¢ƒ}||v r#| d j S |dkr.| d d jS | d	¡d
kr7dS ttd|ƒƒ‚)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,   r;   Úencryption_ivr  r˜   r   )r0   r  Úoctet_string_iv_oidsr   r   r   r3  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.  r0  r1  r3  r   r   r   r   r  �  sˆ    þÿþýüûúùø	÷
öôóòðïîíâ!
(
#
,
!
^
!
0
2r  c                   @   rV   )ÚPbes2Paramsr  r%  N)r   r   r   r©   r  r   r   r   r   r   r5  j  rZ   r5  c                   @   rV   )ÚPbmac1Paramsr  Úmessage_auth_schemeN)r   r   r   r©   rM   r   r   r   r   r   r6  q  rZ   r6  c                   @   r[   )Ú
Pkcs5MacIdz1.2.840.113549.1.5.14Úpbmac1NrK   r   r   r   r   r8  x  r^   r8  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*   r9  N)	r   r   r   r8  r   r   r+   r6  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)r5   rL   rÔ   ro   rN   Úitems)r0   rL   Ú	other_clsÚoidr  r   r   r   Ú_setup�  s   
ÿÿzAnyAlgorithmId._setupN)r   r   r   rL   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@  r5   r-   r  r–   r=  )r0   Úspecsr>  r?  Úspecr   r   r   r@     s   

ÿÿzAnyAlgorithmIdentifier._setupN)	r   r   r   r;  r   r   r+   r-   r@  r   r   r   r   rA  —  s    þrA  N)=r:   Ú
__future__r   r   r   r   Ú_errorsr   Ú_intr   Úutilr	   r
   Úcorer   r   r   r   r   r   r   r   r   Úobjectr   r>   rM   rN   rU   rW   r\   r`   rb   rd   ro   r–   rž   r¢   r§   r©   r«   r¯   r±   r²   rµ   r·   r»   r¾   rÁ   rÃ   rÄ   rÇ   rÔ   r  r5  r6  r8  r:  r-   r;  rA  r   r   r   r   Ú<module>   s^   (9(Ae			#35   ]

