B
    M]                 @   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   /lib/python3.7/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.
    z1.2.840.113549.1.1.1z1.2.840.113549.1.1.11z1.2.840.113549.1.1.12z1.2.840.113549.1.1.13z1.2.840.113549.1.1.14z1.3.14.3.2.26z2.16.840.1.101.3.4.2.4z2.16.840.1.101.3.4.2.1z2.16.840.1.101.3.4.2.2z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   )selfZ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valueZres)r'   r   r   r&   _   s    
z _ForceNullParameters.__setitem__)
r   r   r   __doc__setr"   r$   Z_spec_callbacksr&   __classcell__r   r   )r'   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   r:   |   s   r:   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/   r0   r1   r2   r3   r4   r5   r6   r7   r8   Zshake128Zshake256Zshake128_lenZshake256_len)z1.2.840.113549.2.2z1.2.840.113549.2.5z1.3.14.3.2.26z2.16.840.1.101.3.4.2.4z2.16.840.1.101.3.4.2.1z2.16.840.1.101.3.4.2.2z2.16.840.1.101.3.4.2.3z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.18N)r   r   r   r9   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S )DigestAlgorithmr   r   r   TN)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 )
DigestInfoZdigest_algorithmZdigestN)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 )MaskGenAlgorithmIdz1.2.840.113549.1.1.8mgf1N)r   r   r   r9   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 )MaskGenAlgorithmr   r   r   T)r   r   rA   N)	r   r   r   r@   r   r   r   r>   r    r   r   r   r   rB      s   rB   c               @   s   e Zd ZddiZdS )TrailerFieldr   trailer_field_bcN)r   r   r   r9   r   r   r   r   rC      s   rC   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   rA   )r   r   Zsalt_length      Ztrailer_field   rD   N)r   r   r   r>   rB   r   rC   r   r   r   r   r   rE      s"   rE   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Zdddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0Zd1S )2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)z1.3.14.3.2.3z1.3.14.3.2.29z1.3.14.7.2.3.1z1.2.840.113549.1.1.2z1.2.840.113549.1.1.4z1.2.840.113549.1.1.5z1.2.840.113549.1.1.14z1.2.840.113549.1.1.11z1.2.840.113549.1.1.12z1.2.840.113549.1.1.13z1.2.840.113549.1.1.10z1.2.840.10040.4.3z1.3.14.3.2.13z1.3.14.3.2.27z2.16.840.1.101.3.4.3.1z2.16.840.1.101.3.4.3.2z1.2.840.10045.4.1z1.2.840.10045.4.3.1z1.2.840.10045.4.3.2z1.2.840.10045.4.3.3z1.2.840.10045.4.3.4z2.16.840.1.101.3.4.3.9z2.16.840.1.101.3.4.3.10z2.16.840.1.101.3.4.3.11z2.16.840.1.101.3.4.3.12z1.2.840.113549.1.1.1z1.2.840.10040.4.1z1.2.840.10045.4z1.2.840.10040.4.1z1.2.840.10045.4z1.2.840.113549.1.1.2z1.2.840.113549.1.1.4z1.2.840.113549.1.1.1z1.2.840.113549.1.1.10z1.2.840.10040.4.3z1.2.840.10045.4.1z1.2.840.113549.1.1.5z2.16.840.1.101.3.4.3.1z1.2.840.10045.4.3.1z1.2.840.113549.1.1.14z2.16.840.1.101.3.4.3.2z1.2.840.10045.4.3.2z1.2.840.113549.1.1.11z1.2.840.10045.4.3.3z1.2.840.113549.1.1.12z1.2.840.10045.4.3.4z1.2.840.113549.1.1.13z2.16.840.1.101.3.4.3.9z2.16.840.1.101.3.4.3.10z2.16.840.1.101.3.4.3.11z2.16.840.1.101.3.4.3.12)rc   rd   rP   rN   rb   rU   rV   rY   rO   rW   rZ   rQ   rX   r[   rR   r\   rS   r]   rT   r^   r_   r`   ra   N)r   r   r   r9   Z_reverse_mapr   r   r   r   rM      sf   rM   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   T)r   r   rU   c             C   s`   | 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}||krN|| S ttd|dS )	zx
        :return:
            A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa" or
            "ecdsa"
        r   rb   rU   rc   rd   )rP   rN   rO   rQ   rR   rS   rT   rb   rU   rV   rW   rX   rc   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rd   z>
            Signature algorithm not known for %s
            N)r   
ValueErrorr   )r#   r   algo_mapr   r   r   signature_algo/  s:    
z$SignedDigestAlgorithm.signature_algoc             C   sj   | d j }dddddddddddddddd	}||kr>|| S |d
krX| 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"
        r   r<   r=   r.   r/   r0   r1   r2   )rP   rN   rO   rQ   rR   rS   rT   rV   rW   rX   rY   rZ   r[   r\   r]   rU   r   rF   z9
            Hash algorithm not known for %s
            N)r   rf   r   )r#   r   rg   r   r   r   	hash_algo\  s.    
zSignedDigestAlgorithm.hash_algoN)r   r   r   rM   r   r   r   rE   r    propertyrh   ri   r   r   r   r   re   $  s   -re   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   rk     s   rk   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   rk   r   r:   r   r   r   r   r   rm     s   rm   c               @   s   e Zd ZddiZdS )KdfAlgorithmIdz1.2.840.113549.1.5.12pbkdf2N)r   r   r   r9   r   r   r   r   rr     s   rr   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   T)r   r   rs   N)	r   r   r   rr   r   r   r   rm   r    r   r   r   r   rt     s   rt   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   r*   r   r   r   r   r   r   ru     s   ru   c               @   s   e Zd ZddiZdS )KeyExchangeAlgorithmIdz1.2.840.113549.1.3.1dhN)r   r   r   r9   r   r   r   r   rx     s   rx   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   T)r   r   ry   N)	r   r   r   rx   r   r   r   ru   r    r   r   r   r   rz     s   rz   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-0N)r   r   r   r9   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 )Pbes1Paramsrn   
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_icvlenN)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 )PSourceAlgorithmIdz1.2.840.113549.1.1.9p_specifiedN)r   r   r   r9   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   T)r   r   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 )RSAESOAEPParamsrF   r   r   r.   )rG   rH   rI   r   rA   )r   r   Zp_source_algorithmrJ   r       N)r   r   r   r>   rB   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   rJ   N)r   r   )r	   len)clsdatar   r   r   r   r   
from_p1363.  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_p1363?  s    	

zDSASignature.to_p1363N)	r   r   r   r*   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.6z1.2.840.113549.1.1.1z1.2.840.113549.1.1.7N)r   r   r   r9   r   r   r   r   r   R  sX   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   T)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   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_kdfz~
                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splitrf   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   rq   r   r   r   rJ   z~
                Encryption algorithm "%s" does not have a registered key
                derivation function
                z}
            Unrecognized encryption algorithm "%s", can not determine key
            derivation hmac algorithm
            N)r   r   r   rf   r   )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   rn   rl   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   z~
                Encryption algorithm "%s" does not have a registered key
                derivation function
                zs
            Unrecognized encryption algorithm "%s", can not determine key
            derivation salt
            N)r   namerf   r   r   )r#   r   rn   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   ro   r   r   r   r   z~
                Encryption algorithm "%s" does not have a registered key
                derivation function
                zy
            Unrecognized encryption algorithm "%s", can not determine key
            derivation iterations
            N)r   r   rf   r   )r#   r   r   r   r   kdf_iterations)  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 jd d j}|d j }dd
dd}||kr|| S |dkr|S |dkrd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   rL   aesr          )aes128_aes192_aes256_      )r   r   r   r   encryption_schemer|      )   x   :      N   zw
                Invalid RC2 parameter version found in EncryptionAlgorithm
                parameters
                r   r   rp   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   z@
            Unrecognized encryption algorithm "%s"
            )r   parsedrf   r   rp   r   )r#   r   Zcipher_lengthsZ
rc2_paramsr|   Zencoded_key_bits_maprp   r   r   r   rp   K  s\    

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   z@
            Unrecognized encryption algorithm "%s"
            )r   r+   encryption_moderf   r   )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rd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   r   r   r   r   r   r   r   r   r   r   z@
            Unrecognized encryption algorithm "%s"
            N)r   r+   encryption_cipherr   rf   r   )r#   r   r   r   r   r     s4    
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 jd j d S |dkrv| d d jS |ddkrd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   r   r   r   r   r   r   r   r   r   r   z@
            Unrecognized encryption algorithm "%s"
            N)r   r+   r   encryption_block_sizer   rf   r   )r#   r   Z
cipher_mapr   r   r   r     s:    	
z)EncryptionAlgorithm.encryption_block_sizec          	   C   s   | d j }|tddgkr*| d jd j S tdddd	d
dddg}||krT| d j S |dkrj| d d jS |ddkr|d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   Nz@
            Unrecognized encryption algorithm "%s"
            )r   r+   r   encryption_ivr   rf   r   )r#   r   Zoctet_string_iv_oidsr   r   r   r   1  s*    

z!EncryptionAlgorithm.encryption_ivN)r   r   r   r   r   r   r   r   r{   r   r   r   r   r    rj   r   r   r   r   rp   r   r   r   r   r   r   r   r   r     sL   )$-"`"13r   c               @   s   e Zd ZdefdefgZdS )Pbes2Paramsr   r   N)r   r   r   rt   r   r   r   r   r   r   r   b  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   rt   r:   r   r   r   r   r   r   i  s   r   c               @   s   e Zd ZddiZdS )
Pkcs5MacIdz1.2.840.113549.1.5.14pbmac1N)r   r   r   r9   r   r   r   r   r   p  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   r   N)	r   r   r   r   r   r   r   r   r    r   r   r   r   r   v  s   
r   r   c               @   s   e Zd Zi Zdd ZdS )AnyAlgorithmIdc             C   s@   | j j}x2tttfD ]$}x|j D ]\}}|||< q$W qW d S )N)r'   r9   r   rM   r;   items)r#   r9   	other_clsoidr   r   r   r   _setup  s    zAnyAlgorithmId._setupN)r   r   r   r9   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   T)r   r   c             C   sH   t |  | jj}x0ttfD ]$}x|j D ]\}}|||< q,W qW d S )N)r   r   r'   r    r   re   r   )r#   Z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)=r*   Z
__future__r   r   r   r   Z_errorsr   _intr   utilr	   r
   Zcorer   r   r   r   r   r   r   r   r   objectr   r-   r:   r;   r>   r?   r@   rB   rC   rE   rM   re   rk   rm   rr   rt   ru   rx   rz   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			#35   ^

