3 L]/@sdZddlmZmZmZmZddlmZddlm Z ddl m Z m Z ddl mZmZmZmZmZmZmZmZGdd d eZGd d d eZGd d d eZGdddeZGdddeZGdddeeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gd d!d!eeZ#Gd"d#d#eZ$Gd$d%d%eZ%Gd&d'd'eZ&Gd(d)d)eZ'Gd*d+d+eZ(Gd,d-d-eZ)Gd.d/d/eZ*Gd0d1d1eZ+Gd2d3d3eZ,Gd4d5d5eZ-Gd6d7d7eZ.Gd8d9d9eZ/Gd:d;d;eZ0Gdd?d?eZ2Gd@dAdAeZ3GdBdCdCeeZ4GdDdEdEeZ5GdFdGdGeZ6GdHdIdIeZ7GdJdKdKeZ8e5e4j9dL<GdMdNdNeZ:GdOdPdPeeZ;dQS)Ra 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_literalsdivisionabsolute_importprint_function)unwrap) fill_width)int_from_bytes int_to_bytes)AnyChoiceIntegerNullObjectIdentifier OctetStringSequenceVoidc@s"eZdZdefdeddifgZdS)AlgorithmIdentifier algorithm parametersoptionalTN)__name__ __module__ __qualname__rr _fieldsrr8/tmp/pip-install-wfra5znf/asn1crypto/asn1crypto/algos.pyr+src sLeZdZdZedddddddd d d g Zd d ZdeiZfddZZ S)_ForceNullParametersz Various structures based on AlgorithmIdentifier require that the parameters field be core.Null() for certain OIDs. This mixin ensures that happens. z1.2.840.113549.1.1.1z1.2.840.113549.1.1.11z1.2.840.113549.1.1.12z1.2.840.113549.1.1.13z1.2.840.113549.1.1.14z 1.3.14.3.2.26z2.16.840.1.101.3.4.2.4z2.16.840.1.101.3.4.2.1z2.16.840.1.101.3.4.2.2z2.16.840.1.101.3.4.2.3cCs@|jdkr(|dj}||jkr(|j|S|dj|jkr Signature algorithm not known for %s N)r ValueErrorr)r#ralgo_maprrrsignature_algos2 z$SignedDigestAlgorithm.signature_algocCsj|dj}dddddddddddddddd }||kr>||S|d krX|d d djSttd |dS)z :return: A unicode string of "md2", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", "sha512_224", "sha512_256" rr:r;r0r1r2r3r4)rOrMrNrPrQrRrSrUrVrWrXrYrZr[r\rTrrEz9 Hash algorithm not known for %s N)rrar)r#rrbrrr hash_algoDs. zSignedDigestAlgorithm.hash_algoN)rr) rrrrLr rrrDr propertyrcrdrrrrr`s  )r`c@seZdZdefdefgZdS) Pbkdf2SaltZ specified other_sourceN)rrrrrZ _alternativesrrrrrfmsrfc@s8eZdZdefdefdeddifdeddd iifgZd S) Pbkdf2Paramssaltiteration_count key_lengthrTprfrGrr0N)rrrrfr r8rrrrrrhts rhc@seZdZddiZdS)KdfAlgorithmIdz1.2.840.113549.1.5.12pbkdf2N)rrrr7rrrrrm}srmc@s.eZdZdefdeddifgZdZdeiZdS) KdfAlgorithmrrrTrnN)rr) rrrrmr rrrhr rrrrrosroc@s,eZdZdZdefdefdeddifgZdS) DHParameterszn Original Name: DHParameter Source: ftp://ftp.rsasecurity.com/pub/pkcs/ascii/pkcs-3.asc section 9 pgZprivate_value_lengthrTN)rrrr,r rrrrrrpsrpc@seZdZddiZdS)KeyExchangeAlgorithmIdz1.2.840.113549.1.3.1dhN)rrrr7rrrrrssrsc@s.eZdZdefdeddifgZdZdeiZdS)KeyExchangeAlgorithmrrrTrtN)rr) rrrrsr rrrpr rrrrrusruc@s"eZdZdeddifdefgZdS) Rc2Paramsrc2_parameter_versionrTivN)rrrr rrrrrrrvs rvc@seZdZddiZdS)Rc5ParamVersionzv1-0N)rrrr7rrrrrysryc@s.eZdZdefdefdefdeddifgZdS) Rc5Paramsversionroundsblock_size_in_bitsrxrTN)rrrryr rrrrrrr{sr{c@seZdZdefdefgZdS) Pbes1Paramsri iterationsN)rrrrr rrrrrrsrc@seZdZddiZdS)PSourceAlgorithmIdz1.2.840.113549.1.1.9 p_specifiedN)rrrr7rrrrrsrc@s.eZdZdefdeddifgZdZdeiZdS)PSourceAlgorithmrrrTrN)rr) rrrrr rrrr rrrrrsrc@sNeZdZdedddidfdeddddid dfd ed d d d dfgZdS)RSAESOAEPParamsrErrr0)rFrGrHrr@)rrZp_source_algorithmrIrN)rrrr<rArrrrrrrs rc@s4eZdZdZdefdefgZeddZddZdS) 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 rscCs>t|dt|d}t|t|dd}|||dS)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 rrIN)rr)r len)clsdatarrrrr from_p1363 s zDSASignature.from_p1363cCsJt|dj}t|dj}tt|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() rr)r rmaxrr)r#Zr_bytesZs_bytesZint_byte_lengthrrrto_p1363s   zDSASignature.to_p1363N) rrrr,r r classmethodrrrrrrrs   rc,@sheZdZddddddddd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,+Zd-S).EncryptionAlgorithmIddestripledes_3keyrc2rc5Z aes128_ecb aes128_cbc aes128_ofbZ aes128_cfbZ aes128_wrapZ aes128_gcmZ aes128_ccmZaes128_wrap_padZ aes192_ecb aes192_cbc aes192_ofbZ aes192_cfbZ aes192_wrapZ aes192_gcmZ aes192_ccmZaes192_wrap_padZ aes256_ecb aes256_cbc aes256_ofbZ aes256_cfbZ aes256_wrapZ aes256_gcmZ aes256_ccmZaes256_wrap_padpbes2 pbes1_md2_des pbes1_md5_des pbes1_md2_rc2 pbes1_md5_rc2pbes1_sha1_despbes1_sha1_rc2pkcs12_sha1_rc4_128pkcs12_sha1_rc4_40pkcs12_sha1_tripledes_3keypkcs12_sha1_tripledes_2keypkcs12_sha1_rc2_128pkcs12_sha1_rc2_40Zrsaes_pkcs1v15 rsaes_oaep)+z 1.3.14.3.2.7z1.2.840.113549.3.7z1.2.840.113549.3.2z1.2.840.113549.3.9z2.16.840.1.101.3.4.1.1z2.16.840.1.101.3.4.1.2z2.16.840.1.101.3.4.1.3z2.16.840.1.101.3.4.1.4z2.16.840.1.101.3.4.1.5z2.16.840.1.101.3.4.1.6z2.16.840.1.101.3.4.1.7z2.16.840.1.101.3.4.1.8z2.16.840.1.101.3.4.1.21z2.16.840.1.101.3.4.1.22z2.16.840.1.101.3.4.1.23z2.16.840.1.101.3.4.1.24z2.16.840.1.101.3.4.1.25z2.16.840.1.101.3.4.1.26z2.16.840.1.101.3.4.1.27z2.16.840.1.101.3.4.1.28z2.16.840.1.101.3.4.1.41z2.16.840.1.101.3.4.1.42z2.16.840.1.101.3.4.1.43z2.16.840.1.101.3.4.1.44z2.16.840.1.101.3.4.1.45z2.16.840.1.101.3.4.1.46z2.16.840.1.101.3.4.1.47z2.16.840.1.101.3.4.1.48z1.2.840.113549.1.5.13z1.2.840.113549.1.5.1z1.2.840.113549.1.5.3z1.2.840.113549.1.5.4z1.2.840.113549.1.5.6z1.2.840.113549.1.5.10z1.2.840.113549.1.5.11z1.2.840.113549.1.12.1.1z1.2.840.113549.1.12.1.2z1.2.840.113549.1.12.1.3z1.2.840.113549.1.12.1.4z1.2.840.113549.1.12.1.5z1.2.840.113549.1.12.1.6z1.2.840.113549.1.1.1z1.2.840.113549.1.1.7N)rrrr7rrrrr1sVrc@seZdZdefdeddifgZdZeeee eeeeeee e e e e e e e e e e e e dZ e ddZe dd Ze d d Ze d d Ze ddZe ddZe ddZe ddZe ddZdS)EncryptionAlgorithmrrrT)rrrrrrrrrrrrrrrrrrrrrrrcCs|dj}|dkr$|dddjS|jddkrv|jddkrh|jdd\}}|dkr\d S|d krhd Sttd |ttd |dS)z Returns the name of the key derivation function to use. :return: A unicode from of one of the following: "pbkdf1", "pbkdf2", "pkcs12_kdf" rrrkey_derivation_func.r_Zpbes1Zpbkdf1Zpkcs12Z pkcs12_kdfz~ Encryption algorithm "%s" does not have a registered key derivation function zw Unrecognized encryption algorithm "%s", can not determine key derivation function Nr)rfindsplitrar)r#encryption_algorrrrkdfs zEncryptionAlgorithm.kdfcCs~|dj}|dkr,|dddddjS|jdd krl|jddkr^|jdd \}}}|Sttd |ttd |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" rrrrrlrrrrIz~ Encryption algorithm "%s" does not have a registered key derivation function z} Unrecognized encryption algorithm "%s", can not determine key derivation hmac algorithm Nrr)rrrrar)r#rrZ hmac_algorrrkdf_hmacs zEncryptionAlgorithm.kdf_hmaccCs|dj}|dkrB|dddd}|jdkr|S|d krJd S|d kr`|ddjS|jddkrddd d dd ddd d d d d |Sttd|dS)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" rrrrrrrrrrrZ tripledesrrrrrZrc4) rrrrrrrrrrrrz@ Unrecognized encryption algorithm "%s" Nr)rr-encryption_cipherrrar)r#rrrrrs4 z%EncryptionAlgorithm.encryption_cipherc Cs|dj}|ddtdddgkr(dSdddd }||krD||S|d kr`|d jd jdS|d krv|d djS|jddkrddddddddddddd |Sttd|dS)z Returns the block size of the encryption cipher, in bytes. :return: An integer that is the block size in bytes rrrrrrrzr)rrrrrr~rrrr) rrrrrrrrrrrrz@ Unrecognized encryption algorithm "%s" Nr)rr-rencryption_block_sizerrar)r#rZ cipher_maprrrrs: z)EncryptionAlgorithm.encryption_block_sizec Cs|dj}|tddgkr*|djdjStdddd d d d d g}||krT|djS|dkrj|ddjS|jddkr|dSttd|dS)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 rrrrrxrrrrrrrrrrrrNz@ Unrecognized encryption algorithm "%s" r)rr-r encryption_ivrrar)r#rZoctet_string_iv_oidsrrrr s*  z!EncryptionAlgorithm.encryption_ivN)rr)rrrrr rrrrvr{rrr rerrrrrkrrrrrrrrresF ) $ - " ` " 1 3rc@seZdZdefdefgZdS) Pbes2ParamsrrN)rrrrorrrrrrr<src@seZdZdefdefgZdS) Pbmac1ParamsrZmessage_auth_schemeN)rrrror8rrrrrrCsrc@seZdZddiZdS) Pkcs5MacIdz1.2.840.113549.1.5.14pbmac1N)rrrr7rrrrrJsrc@s(eZdZdefdefgZdZdeiZdS)Pkcs5MacAlgorithmrrrN)rr) rrrrr rrrr rrrrrPs rrc@seZdZiZddZdS)AnyAlgorithmIdcCs@|jj}x2tttfD]$}x|jjD]\}}|||<q$WqWdS)N)r(r7rrLr9items)r#r7 other_clsoidrrrr_setupbszAnyAlgorithmId._setupN)rrrr7rrrrrr_src@s2eZdZdefdeddifgZdZiZddZdS) AnyAlgorithmIdentifierrrrTcCsHtj||jj}x0ttfD]$}x|jjD]\}}|||<q,WqWdS)N)rrr(r rr`r)r#specsrrspecrrrrrs  zAnyAlgorithmIdentifier._setupN)rr) rrrrr rrr rrrrrris rN)sZ  (9  (4]      #34Z