3 lá˜_ˆã@s„ddlmZmZmZddlmZddlmZddlm Z ddl m Z m Z dZ eje ƒGdd„deƒƒZeje ƒGd d „d eƒƒZd S) é)Úabsolute_importÚdivisionÚprint_function)Úutils)Ú_evp_pkey_derive)Ú serialization)ÚX25519PrivateKeyÚX25519PublicKeyé c@s$eZdZdd„Zdd„Zdd„ZdS)Ú_X25519PublicKeycCs||_||_dS)N)Ú_backendÚ _evp_pkey)ÚselfÚbackendÚevp_pkey©rú/usr/lib64/python3.6/x25519.pyÚ__init__sz_X25519PublicKey.__init__cCsV|tjjks|tjjkr@|tjjk s0|tjjk r8tdƒ‚|jƒS|jj||||jdƒS)Nz3When using Raw both encoding and format must be Raw) rÚEncodingÚRawÚ PublicFormatÚ ValueErrorÚ_raw_public_bytesr 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Údatarrrr,s z"_X25519PublicKey._raw_public_bytesN)Ú__name__Ú __module__Ú __qualname__rrrrrrrr sr c@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú_X25519PrivateKeycCs||_||_dS)N)r r )rrrrrrr;sz_X25519PrivateKey.__init__cCsz|jjƒ}|jjj||jƒ}|jj|dkƒ|jjj||jjjƒ}|jj||jjjkƒ|jjj ||jjj ƒ}t |j|ƒS)Né) r Ú_create_mem_bio_gcrZi2d_PUBKEY_bior rZd2i_PUBKEY_biorr r!Z EVP_PKEY_freer )rÚbior#rrrrÚ public_key?s z_X25519PrivateKey.public_keycCs"t|tƒstdƒ‚t|j|j|ƒS)Nz(peer_public_key must be X25519PublicKey.)Ú isinstancer Ú TypeErrorrr r )rZpeer_public_keyrrrÚexchangeLs z_X25519PrivateKey.exchangecCsf|tjjks|tjjkrN|tjjk s>|tjjk s>t|tjƒ rFtdƒ‚|jƒS|j j |||||j dƒS)NzcWhen using Raw both encoding and format must be Raw and encryption_algorithm must be NoEncryption()) rrrrZ PrivateFormatr-Z NoEncryptionrÚ_raw_private_bytesr Z_private_key_bytesr )rrrZencryption_algorithmrrrÚ private_bytesRs     z_X25519PrivateKey.private_bytescCs||jjƒ}|jjj||j|jjj|jjjd|jjj|jjjƒ}|jj|dkƒ|jj|ƒ}|jjt |ƒdkƒ|t d…S)Nrr)é0) r r*rZi2d_PKCS8PrivateKey_bior rr rZ _read_mem_bioÚlenÚ_X25519_KEY_SIZE)rr+r#Zpkcs8rrrr0is   z$_X25519PrivateKey._raw_private_bytesN)r%r&r'rr,r/r1r0rrrrr(9s  r(N)Z __future__rrrZ cryptographyrZ*cryptography.hazmat.backends.openssl.utilsrZcryptography.hazmat.primitivesrZ0cryptography.hazmat.primitives.asymmetric.x25519rr r4Zregister_interfaceÚobjectr r(rrrrÚs   %