
    5i/&                     8   d dl Z d dlmZ d dlmZmZ d dlmZ  G d d      Z G d d      Z	 G d	 d
e      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)    N)NativeResource)Union
NamedTuple)IntEnumc                   P    e Zd Zd Zed        Zed        Zed        Zd ZddZ	y)	Hashc                     || _         yz,
        don't call me, I'm private
        N)_hashselfnative_handles     o/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/awscrt/crypto.py__init__zHash.__init__        #
    c                  >    t        t        j                               S )zJ
        Creates a new instance of Hash, using the sha1 algorithm
        r   )r   _awscrtsha1_new r   r   r   zHash.sha1_new   s    
 '"2"2"455r   c                  >    t        t        j                               S )zL
        Creates a new instance of Hash, using the sha256 algorithm
        r   )r   r   
sha256_newr   r   r   r   zHash.sha256_new   s    
 '"4"4"677r   c                  >    t        t        j                               S )zJ
        Creates a new instance of Hash, using the md5 algorithm.
        r   )r   r   md5_newr   r   r   r   zHash.md5_new    s    
 '//"344r   c                 D    t        j                  | j                  |       y N)r   hash_updater   )r   to_hashs     r   updatezHash.update'       DJJ0r   c                 B    t        j                  | j                  |      S r   )r   hash_digestr   r   truncate_tos     r   digestzHash.digest*       ""4::{;;r   Nr   )
__name__
__module____qualname__r   staticmethodr   r   r   r    r&   r   r   r   r   r   
   sM    # 6 6 8 8 5 51<r   r   c                   0    e Zd Zd Zed        Zd ZddZy)HMACc                     || _         yr
   )_hmacr   s     r   r   zHMAC.__init__/   r   r   c                 @    t        t        j                  |             S )zq
        Creates a new instance of HMAC, using SHA256 HMAC as the algorithm and secret_key as the secret
        r   )r.   r   sha256_hmac_new)
secret_keys    r   r2   zHMAC.sha256_hmac_new5   s    
 '"9"9*"EFFr   c                 D    t        j                  | j                  |       y r   )r   hmac_updater0   )r   to_hmacs     r   r    zHMAC.update<   r!   r   c                 B    t        j                  | j                  |      S r   )r   hmac_digestr0   r$   s     r   r&   zHMAC.digest?   r'   r   Nr(   )r)   r*   r+   r   r,   r2   r    r&   r   r   r   r.   r.   .   s'    # G G1<r   r.   c                        e Zd ZdZdZ	 dZ	 dZy)RSAEncryptionAlgorithmRSA Encryption Algorithmr         N)r)   r*   r+   __doc__PKCS1_5OAEP_SHA256OAEP_SHA512r   r   r   r:   r:   C   s'    "G K Kr   r:   c                        e Zd ZdZdZ	 dZ	 dZy)RSASignatureAlgorithmr;   r   r<   r=   N)r)   r*   r+   r>   PKCS1_5_SHA256PKCS1_5_SHA1
PSS_SHA256r   r   r   rC   rC   V   s'    "N L Jr   rC   c            	       J    e Zd Z fdZedeeeee	f   dd fd       Z
edeeeee	f   dd fd       Zedeeee	f   dd fd       Zedeeee	f   dd fd       Zd	ed
eeee	f   defdZd	edeeee	f   defdZdedeeee	f   defdZdedeeee	f   deeee	f   defdZ xZS )RSAc                 0    t         |           || _        y r   superr   _bindingr   binding	__class__s     r   r   zRSA.__init__j       r   pem_datareturnc                 @    t        t        j                  |             S )z
        Creates a new instance of private RSA key pair from pem data.
        Raises ValueError if pem does not have private key object.
        rN   )rH   r   rsa_private_key_from_pem_datarQ   s    r   new_private_key_from_pem_dataz!RSA.new_private_key_from_pem_datan   s     7@@JKKr   c                 @    t        t        j                  |             S )z
        Creates a new instance of public RSA key pair from pem data.
        Raises ValueError if pem does not have public key object.
        rT   )rH   r   rsa_public_key_from_pem_datarV   s    r   new_public_key_from_pem_dataz RSA.new_public_key_from_pem_datav   s     7??IJJr   der_datac                 @    t        t        j                  |             S )z
        Creates a new instance of private RSA key pair from der data.
        Expects key in PKCS1 format.
        Raises ValueError if pem does not have private key object.
        rT   )rH   r   rsa_private_key_from_der_datar[   s    r   new_private_key_from_der_dataz!RSA.new_private_key_from_der_data~   s     7@@JKKr   c                 @    t        t        j                  |             S )z
        Creates a new instance of public RSA key pair from der data.
        Expects key in PKCS1 format.
        Raises ValueError if pem does not have public key object.
        rT   )rH   r   rsa_public_key_from_der_datar^   s    r   new_public_key_from_der_dataz RSA.new_public_key_from_der_data   s     7??IJJr   encryption_algorithm	plaintextc                 D    t        j                  | j                  ||      S )z8
        Encrypts data using a given algorithm.
        )r   rsa_encryptrL   )r   rc   rd   s      r   encryptzRSA.encrypt   s    
 ""4==2F	RRr   
ciphertextc                 D    t        j                  | j                  ||      S )z8
        Decrypts data using a given algorithm.
        )r   rsa_decryptrL   )r   rc   rh   s      r   decryptzRSA.decrypt   s    
 ""4==2F
SSr   signature_algorithmr&   c                 D    t        j                  | j                  ||      S )zu
        Signs data using a given algorithm.
        Note: function expects digest of the message, ex sha256
        )r   rsa_signrL   )r   rl   r&   s      r   signzRSA.sign   s     /BFKKr   	signaturec                 F    t        j                  | j                  |||      S zp
        Verifies signature against digest.
        Returns True if signature matches and False if not.
        )r   
rsa_verifyrL   )r   rl   r&   rp   s       r   verifyz
RSA.verify   s      !!$--1DfiXXr   )r)   r*   r+   r   r,   r   strbytes	bytearray
memoryviewrW   rZ   r_   rb   r:   rg   rk   rC   ro   boolrt   __classcell__rO   s   @r   rH   rH   i   s     Lc5)Z6W0X L]b L L KuS%J5V/W K\a K K LeY
6R0S LX] L L KuUIz5Q/R KW\ K KS,B S 	:!=>SCHST,B T!%J">?TDITL(= L5)Z78L=BLY*? YUIz9:Yy* <=YBFYr   rH   c                       e Zd ZdZdZ	 dZy)ED25519ExportFormatzED25519 Export formatr   r<   N)r)   r*   r+   r>   RAWOPENSSH_B64r   r   r   r}   r}      s    
C Kr   r}   c                   P     e Zd Z fdZedd       ZdedefdZdedefdZ	 xZ
S )ED25519c                 0    t         |           || _        y r   rJ   rM   s     r   r   zED25519.__init__   rP   r   rR   c                  >    t        t        j                               S )z?
        Generates a new instance of ED25159 key pair.
        rT   )r   r   ed25519_new_generater   r   r   new_generatezED25519.new_generate   s    
 w;;=>>r   export_formatc                 B    t        j                  | j                  |      S zE
        Exports public part of the key in specified format.
        )r   ed25519_export_public_keyrL   r   r   s     r   export_public_keyzED25519.export_public_key   s     00NNr   c                 B    t        j                  | j                  |      S r   )r   ed25519_export_private_keyrL   r   s     r   export_private_keyzED25519.export_private_key   s     11$--OOr   )rR   r   )r)   r*   r+   r   r,   r   r}   rv   r   r   rz   r{   s   @r   r   r      sJ      ? ?O/B Ou OP0C P Pr   r   c                       e Zd ZdZdZ	 dZy)ECTypezElliptic Curve Typer   r<   N)r)   r*   r+   r>   P_256P_384r   r   r   r   r      s    E Er   r   c                        e Zd ZdZdZ	 dZ	 dZy)ECExportFormatzEC Export formatr   r<   r=   N)r)   r*   r+   r>   SEC1PKCS8SPKIr   r   r   r   r      s'    D E Dr   r   c                   "    e Zd ZU eed<   eed<   y)ECRawSignaturersNr)   r*   r+   rv   __annotations__r   r   r   r   r          HHr   r   c                   "    e Zd ZU eed<   eed<   y)ECPublicCoordsxyNr   r   r   r   r   r      r   r   r   c                       e Zd Z fdZededd fd       Zedeee	e
f   dd fd       Zededefd       Zeded	edefd
       Zededefd       ZdedefdZdefdZdeee	e
f   defdZdeee	e
f   deee	e
f   defdZ xZS )ECc                 0    t         |           || _        y r   rJ   rM   s     r   r   zEC.__init__  rP   r   typerR   c                 @    t        t        j                  |             S )z:
        Generates a new instance of EC key pair.
        rT   )r   r   ec_new_generate)r   s    r   r   zEC.new_generate  s    
 '11$788r   r[   c                 @    t        t        j                  |             S )aW  
        Creates a new instance of EC key pair from der data.
        Will figure out what type of key it is without hint (i.e. pem header).
        Supports all formats specified in ECExportFormat.
        Expects raw bytes (i.e. strip b64 you get when reading pem).
        Raises ValueError if pem does not have private key object.
        rT   )r   r   ec_key_from_der_datar^   s    r   new_key_from_der_datazEC.new_key_from_der_data  s     '66x@AAr   rp   c                 L    t        j                  |       \  }}t        ||      S )z8
        Decodes ec signature into raw r and s.
        )r   r   )r   ec_decode_signaturer   )rp   r   r   s      r   decode_der_signaturezEC.decode_der_signature  s%    
 ,,Y7AQ''r   pad_toc                 .    t        j                  | |      S )a  
        Decodes ec signature into padded r || s.
        Both r and s are padded to the specified value and then concatenated.
        Typical format for jwt use case.
        Note: pad_to typically should equal to coord size. e.g 32 for P256 or 48 for P384
        )r   "ec_decode_signature_to_padded_pair)rp   r   s     r   #decode_der_signature_to_padded_pairz&EC.decode_der_signature_to_padded_pair!  s     99)VLLr   c                 ,    t        j                  |       S )z1
        Encodes raw signature into der.
        )r   ec_encode_signature)rp   s    r   encode_raw_signaturezEC.encode_raw_signature+  s    
 **955r   r   c                 B    t        j                  | j                  |      S )z6
        Exports the key in specified format.
        )r   ec_export_keyrL   r   s     r   
export_keyzEC.export_key2  s     $$T]]MBBr   c                 `    t        j                  | j                        \  }}t        ||      S )z.
        Get public coords of the key
        )r   r   )r   ec_get_public_coordsrL   r   )r   r   r   s      r   get_public_coordszEC.get_public_coords8  s)     --dmm<AQ''r   r&   c                 B    t        j                  | j                  |      S )z
        Signs data using a given algorithm.
        Returns DER encoded signature.
        Note: function expects digest of the message, ex sha256
        )r   ec_signrL   )r   r&   s     r   ro   zEC.sign?  s     t}}f55r   c                 D    t        j                  | j                  ||      S rr   )r   	ec_verifyrL   )r   r&   rp   s      r   rt   z	EC.verifyG  s       	BBr   )r)   r*   r+   r   r,   r   r   r   rv   rw   rx   r   r   r   intr   r   r   r   r   r   ro   ry   rt   rz   r{   s   @r   r   r     sH     96 9d 9 9 BeY
.J(K BPT B B ( (. ( ( Mu Mc Me M M 6 65 6 6C C5 C(> (65	:!=> 65 6CU5)Z#?@ Cy* <=CBFCr   r   )r   awscrtr   typingr   r   enumr   r   r.   r:   rC   rH   r}   r   r   r   r   r   r   r   r   r   <module>r      s     ! $ !< !<H< <*W &G &DY. DYN' Pn P2W W &Z 
Z 
KC KCr   