3 œäL]Êã@sŒddlmZmZmZddlZddlmZddlmZddl m Z ddl m Z m Z dZeje ƒGdd „d eƒƒZeje ƒGd d „d eƒƒZdS) é)Úabsolute_importÚdivisionÚprint_functionN)Úutils)Ú_evp_pkey_derive)Ú serialization)ÚX25519PrivateKeyÚX25519PublicKeyé c@s&eZdZdd„Zddd„Zdd„ZdS) Ú_X25519PublicKeycCs||_||_dS)N)Ú_backendÚ _evp_pkey)ÚselfÚbackendÚevp_pkey©rúU/tmp/pip-install-wfra5znf/cryptography/cryptography/hazmat/backends/openssl/x25519.pyÚ__init__sz_X25519PublicKey.__init__NcCs¼|dks|dkrH|dk s |dk r*tdƒ‚ntjdtjƒtjj}tjj}|tjjks`|tjjkrˆ|tjjk sx|tjjk r€tdƒ‚|j ƒS|tj kr¦|tjj k r¦tdƒ‚|j j ||||jdƒS)Nz%Both encoding and format are requiredz‚public_bytes now requires encoding and format arguments. Support for calling without arguments will be removed in cryptography 2.7z3When using Raw both encoding and format must be Rawz?format must be SubjectPublicKeyInfo when encoding is PEM or DER)Ú ValueErrorÚwarningsÚwarnrZDeprecatedIn25rÚEncodingÚRawÚ PublicFormatÚ_raw_public_bytesÚ_PEM_DERZSubjectPublicKeyInfor Z_public_key_bytesr )rÚencodingÚformatrrrÚ public_bytess*       z_X25519PublicKey.public_bytescCs||jjjdƒ}|jjj|j|ƒ}|jj|dkƒ|jj|d|jjjkƒ|jjj|d|jjj ƒ}|jjj ||ƒdd…S)Nzunsigned char **r r) r Ú_ffiÚnewÚ_libZEVP_PKEY_get1_tls_encodedpointr Úopenssl_assertÚNULLÚgcZ OPENSSL_freeÚbuffer)rZucharppÚresÚdatarrrrBs z"_X25519PublicKey._raw_public_bytes)NN)Ú__name__Ú __module__Ú __qualname__rrrrrrrr s (r c@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú_X25519PrivateKeycCs||_||_dS)N)r r )rrrrrrrQsz_X25519PrivateKey.__init__cCsz|jjƒ}|jjj||jƒ}|jj|dkƒ|jjj||jjjƒ}|jj||jjjkƒ|jjj ||jjj ƒ}t |j|ƒS)Né) r Ú_create_mem_bio_gcr!Zi2d_PUBKEY_bior r"Zd2i_PUBKEY_biorr#r$Z EVP_PKEY_freer )rÚbior&rrrrÚ public_keyUs z_X25519PrivateKey.public_keycCs"t|tƒstdƒ‚t|j|j|ƒS)Nz(peer_public_key must be X25519PublicKey.)Ú isinstancer Ú TypeErrorrr r )rZpeer_public_keyrrrÚexchangebs z_X25519PrivateKey.exchangecCs‚|tjjks|tjjkrN|tjjk s>|tjjk s>t|tjƒ rFtdƒ‚|jƒS|tj krl|tjj k rltdƒ‚|j j ||||j dƒS)NzaWhen using Raw both encoding and format must be Raw and encryption_algorithm must be NoEncryptionz0format must be PKCS8 when encoding is PEM or DER)rrrrZ PrivateFormatr0Z NoEncryptionrÚ_raw_private_bytesrZPKCS8r Z_private_key_bytesr )rrrZencryption_algorithmrrrÚ private_bytesjs      z_X25519PrivateKey.private_bytescCs||jjƒ}|jjj||j|jjj|jjjd|jjj|jjjƒ}|jj|dkƒ|jj|ƒ}|jjt |ƒdkƒ|t d…S)Nrr,é0) r r-r!Zi2d_PKCS8PrivateKey_bior rr#r"Z _read_mem_bioÚlenÚ_X25519_KEY_SIZE)rr.r&Zpkcs8rrrr3‡s  z$_X25519PrivateKey._raw_private_bytesN)r(r)r*rr/r2r4r3rrrrr+Os  r+)Ú __future__rrrrZ cryptographyrZ*cryptography.hazmat.backends.openssl.utilsrZcryptography.hazmat.primitivesrZ0cryptography.hazmat.primitives.asymmetric.x25519rr r7Zregister_interfaceÚobjectr r+rrrrÚs   :