3 lá˜_ ã@s$ddlmZmZmZddlZddlZddlmZddlm Z ej ej ƒGdd„de ƒƒZ ej ej ƒGdd„de ƒƒZej ej ƒGd d „d e ƒƒZej ej ƒGd d „d eƒƒZej ej ƒGd d„de ƒƒZeZddd„Zddd„Zdd„Zdd„ZGdd„de ƒZGdd„de ƒZGdd„de ƒZdS)é)Úabsolute_importÚdivisionÚprint_functionN)Úutils)Ú _get_backendc@seZdZejdd„ƒZdS)Ú DSAParameterscCsdS)z8 Generates and returns a DSAPrivateKey. N©)Úselfrrú/usr/lib64/python3.6/dsa.pyÚgenerate_private_keysz"DSAParameters.generate_private_keyN)Ú__name__Ú __module__Ú __qualname__ÚabcÚabstractmethodr rrrr rsrc@seZdZejdd„ƒZdS)ÚDSAParametersWithNumberscCsdS)z0 Returns a DSAParameterNumbers. Nr)r rrr Úparameter_numberssz*DSAParametersWithNumbers.parameter_numbersN)r r rrrrrrrr rsrc@sReZdZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ ejd d „ƒZ d S) Ú DSAPrivateKeycCsdS)z6 The bit length of the prime modulus. Nr)r rrr Úkey_size#szDSAPrivateKey.key_sizecCsdS)zD The DSAPublicKey associated with this private key. Nr)r rrr Ú public_key)szDSAPrivateKey.public_keycCsdS)zL The DSAParameters object associated with this private key. Nr)r rrr Ú parameters/szDSAPrivateKey.parameterscCsdS)zN Returns an AsymmetricSignatureContext used for signing data. Nr)r Úsignature_algorithmrrr Úsigner5szDSAPrivateKey.signercCsdS)z Signs the data Nr)r ÚdataÚ algorithmrrr Úsign;szDSAPrivateKey.signN) r r rrÚabstractpropertyrrrrrrrrrr r!s rc@s(eZdZejdd„ƒZejdd„ƒZdS)ÚDSAPrivateKeyWithSerializationcCsdS)z. Returns a DSAPrivateNumbers. Nr)r rrr Úprivate_numbersDsz.DSAPrivateKeyWithSerialization.private_numberscCsdS)z6 Returns the key serialized as bytes. Nr)r ÚencodingÚformatZencryption_algorithmrrr Ú private_bytesJsz,DSAPrivateKeyWithSerialization.private_bytesN)r r rrrrr!rrrr rBsrc@s`eZdZejdd„ƒZejdd„ƒZejdd„ƒZejdd„ƒZ ejd d „ƒZ ejd d „ƒZ d S)Ú DSAPublicKeycCsdS)z6 The bit length of the prime modulus. Nr)r rrr rSszDSAPublicKey.key_sizecCsdS)zK The DSAParameters object associated with this public key. Nr)r rrr rYszDSAPublicKey.parameterscCsdS)zQ Returns an AsymmetricVerificationContext used for signing data. Nr)r Ú signaturerrrr Úverifier_szDSAPublicKey.verifiercCsdS)z- Returns a DSAPublicNumbers. Nr)r rrr Úpublic_numberseszDSAPublicKey.public_numberscCsdS)z6 Returns the key serialized as bytes. Nr)r rr rrr Ú public_byteskszDSAPublicKey.public_bytescCsdS)z5 Verifies the signature of the data. Nr)r r#rrrrr ÚverifyqszDSAPublicKey.verifyN) r r rrrrrrr$r%r&r'rrrr r"Qs r"cCst|ƒ}|j|ƒS)N)rZgenerate_dsa_parameters)rÚbackendrrr Úgenerate_parameters{sr)cCst|ƒ}|j|ƒS)N)rZ'generate_dsa_private_key_and_parameters)rr(rrr r €sr cCsT|jjƒd krtdƒ‚|jjƒd kr,td ƒ‚d |jkoB|jknsPtd ƒ‚dS)Nééé éz5p must be exactly 1024, 2048, 3072, or 4096 bits longé éàéz,q must be exactly 160, 224, or 256 bits longézg, p don't satisfy 1 < g < p.)r*r+r,r-)r.r/r0)ÚpÚ bit_lengthÚ ValueErrorÚqÚg)rrrr Ú_check_dsa_parameters…sr7cCsT|jj}t|ƒ|jdks&|j|jkr.tdƒ‚|jjt|j|j|j ƒkrPtdƒ‚dS)Nrzx must be > 0 and < q.z y must be equal to (g ** x % p).) r%rr7Úxr5r4ÚyÚpowr6r2)Znumbersrrrr Ú_check_dsa_private_numbers‘s r;c@sTeZdZdd„ZejdƒZejdƒZejdƒZddd„Z d d „Z d d „Z d d„Z dS)ÚDSAParameterNumberscCsHt|tjƒ s*t|tjƒ s*t|tjƒ r2tdƒ‚||_||_||_dS)Nz;DSAParameterNumbers p, q, and g arguments must be integers.)Ú isinstanceÚsixÚ integer_typesÚ TypeErrorÚ_pÚ_qÚ_g)r r2r5r6rrr Ú__init__œszDSAParameterNumbers.__init__rArBrCNcCst|ƒ}|j|ƒS)N)rZload_dsa_parameter_numbers)r r(rrr r®szDSAParameterNumbers.parameterscCs2t|tƒstS|j|jko0|j|jko0|j|jkS)N)r=r<ÚNotImplementedr2r5r6)r Úotherrrr Ú__eq__²s zDSAParameterNumbers.__eq__cCs ||k S)Nr)r rFrrr Ú__ne__¸szDSAParameterNumbers.__ne__cCs dj|dS)Nz9)r )r )r rrr Ú__repr__»szDSAParameterNumbers.__repr__)N) r r rrDrÚread_only_propertyr2r5r6rrGrHrIrrrr r<›s    r<c@sJeZdZdd„ZejdƒZejdƒZddd„Zdd „Z d d „Z d d „Z dS)ÚDSAPublicNumberscCs6t|tjƒstdƒ‚t|tƒs&tdƒ‚||_||_dS)Nz/DSAPublicNumbers y argument must be an integer.z9parameter_numbers must be a DSAParameterNumbers instance.)r=r>r?r@r<Ú_yÚ_parameter_numbers)r r9rrrr rDÃs  zDSAPublicNumbers.__init__rLrMNcCst|ƒ}|j|ƒS)N)rZload_dsa_public_numbers)r r(rrr rÒszDSAPublicNumbers.public_keycCs&t|tƒstS|j|jko$|j|jkS)N)r=rKrEr9r)r rFrrr rGÖs  zDSAPublicNumbers.__eq__cCs ||k S)Nr)r rFrrr rHßszDSAPublicNumbers.__ne__cCs dj|dS)NzJ)r )r )r rrr rIâszDSAPublicNumbers.__repr__)N) r r rrDrrJr9rrrGrHrIrrrr rKÂs    rKc@sBeZdZdd„ZejdƒZejdƒZd dd„Zdd „Z d d „Z dS) ÚDSAPrivateNumberscCs6t|tjƒstdƒ‚t|tƒs&tdƒ‚||_||_dS)Nz0DSAPrivateNumbers x argument must be an integer.z3public_numbers must be a DSAPublicNumbers instance.)r=r>r?r@rKÚ_public_numbersÚ_x)r r8r%rrr rDês  zDSAPrivateNumbers.__init__rPrONcCst|ƒ}|j|ƒS)N)rZload_dsa_private_numbers)r r(rrr Ú private_keyøszDSAPrivateNumbers.private_keycCs&t|tƒstS|j|jko$|j|jkS)N)r=rNrEr8r%)r rFrrr rGüs zDSAPrivateNumbers.__eq__cCs ||k S)Nr)r rFrrr rHszDSAPrivateNumbers.__ne__)N) r r rrDrrJr8r%rQrGrHrrrr rNés    rN)N)N)Z __future__rrrrr>Z cryptographyrZcryptography.hazmat.backendsrZ add_metaclassÚABCMetaÚobjectrrrrr"ZDSAPublicKeyWithSerializationr)r r7r;r<rKrNrrrr Ús,   &    ''