
    jn                     p    S SK r S SKrS SKrS SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr   " S S5      rg)	    N)AESGCM)OAEPMGF1)RSAPublicNumbers)SHA1)default_backendc            	           \ rS rSrSrSrSrSS\S\S\SS	4S
 jjrS\S\	4S jr
S\S\4S jrS rS\	S\4S jrS\S\S\S\4S jrS\4S jrS\S\4S jrS\S\4S jrSrg	)	CseAmazon	            jwk_nkey_idprovider_idreturnNc                 (    Xl         X l        X0l        g )N)_CseAmazon__jwkN_CseAmazon__keyId_CseAmazon__providerId)selfr   r   r   s       6C:\xampp\htdocs\CheckFili\Apis\Gencookie\amazon\cse.py__init__CseAmazon.__init__   s    '    passwordc                 ,    U R                  U5      nU R                  U5      nSU[        R                  " U5      R                  S5      [        R                  " U5      R                  S5      S.$ ! [         a  nS[        U5      S.s S nA$ S nAff = f)NTutf-8)statuspayloadencryptedPasswordencryptedPasswordCheckF)r   description)_CseAmazon__encryptMessagebase64	b64encodedecode	Exceptionstr)r   r   enc1enc2errors        r   encryptCseAmazon.encrypt   s    
	@((2D((2D#%+%5%5d%;%B%B7%K*0*:*:4*@*G*G*P	   	@#CJ??	@s   A.A1 1
B;BBBsc                 ^    [         R                  " USS[        U5      S-  -
  S-  -  -   5      $ )N=   )r%   urlsafe_b64decodelen)r   r/   s     r   __b64UrlDecodeCseAmazon.__b64UrlDecode!   s.    ''CAA
Na3G,H(HIIr   c                     [         R                  U R                  U R                  5      S5      n[         R                  U R                  S5      S5      n[	        X!5      R                  [        5       5      $ )NbigAQAB)int
from_bytes_CseAmazon__b64UrlDecoder   r   
public_keyr   )r   nes      r   __importPublicKeyCseAmazon.__importPublicKey$   sU    NN4..t{{;UCNN4..v6>%001BCCr   contextc           	         U(       d  [         R                  " SS5      $ [        UR                  5       5      n[         R                  " S[	        U5      5      nU Hp  u  pEUR                  S5      UR                  S5      pvU[         R                  " S[	        U5      5      U-   [         R                  " S[	        U5      5      -   U-   -  nMr     U$ )N>Hr   r   )structpacksorteditemsr4   encode)r   rB   rH   resultkeyvaluekbvbs           r   __serializeEncryptionContext&CseAmazon.__serializeEncryptionContext)   s    ;;tQ''w}}'T3u:.JCZZ(%,,w*?fkk$B025D#b'8RRUWWWF   r   encrypted_keyc                    UR                  S5      nUR                  S5      n[        R                  " S[        U5      5      U-   [        R                  " S[        U5      5      -   U-   [        R                  " S[        U5      5      -   U-   $ )Nr   rD   )rI   rE   rF   r4   )r   r   r   rQ   pbrM   s         r   __serializeEncryptedDataKey%CseAmazon.__serializeEncryptedDataKey3   s|    (]]7#KKc"g&+KKc"g&')+,KKc-0124AB	
r   c                     [        S5      $ )N   )bytes)r   s    r   __buildHeaderIvCseAmazon.__buildHeaderIv<   s    Ryr   seqc                 `    [         R                  " SS5      [         R                  " SU5      -   $ )Nz>Qr   >I)rE   rF   )r   r[   s     r   __buildFrameIvCseAmazon.__buildFrameIv?   s#    {{4#fkk$&<<<r   c           	      t   [         R                  " S5      n[         R                  " S5      nU R                  5       nUR                  U[	        [        [        5       S9[        5       S S95      nU R                  U R                  U R                  U5      n[        5       nUR                  U R                  5        UR                  U R                  5        UR                  [        R                   " SU R"                  5      5        UR                  U5        UR                  U R%                  0 5      5        UR                  [        R                   " SS5      5        UR                  U5        UR                  S5        UR                  [        R                   " SS5      5        UR                  S	5        UR                  [        R                   " S['        U5      S-   5      5        [)        U5      n[+        U5      n	U R-                  5       n
U	R                  U
S
U5      nUR/                  S5      nU R1                  S5      n[        R                   " SS5      n[        R                   " SS5      n[        R                   " S['        U5      5      nU	R                  XS
5      nUU
-   U-   U-   U-   U-   U-   U-   $ )N   )	algorithm)mgfrb   labelrD   r      r]   r   rW   r   r   l    )osurandom_CseAmazon__importPublicKeyr-   r   r   r   %_CseAmazon__serializeEncryptedDataKeyr   r   	bytearrayappend_CseAmazon__VERSION_CseAmazon__TYPEextendrE   rF   _CseAmazon__ALGORITHM_ID&_CseAmazon__serializeEncryptionContextr4   rX   r   _CseAmazon__buildHeaderIvrI   _CseAmazon__buildFrameIv)r   r   
message_iddata_keyr=   encrypted_data_keyedk_serializedheader
raw_headeraesgcm	header_ivheader_auth_tagpassword_bytesframe_ivfinal_frame_markerseq_num_bytescontent_len_bytesencrypted_contents                     r   __encryptMessageCseAmazon.__encryptMessageB   s7   ZZ^
::b>++-
'//TDF+tvTJ

 99t||-?
 dnn%dkk"fkk$(;(;<=j!d77;<fkk$*+n%afkk$*+bfkk$H(9:;6]
!((*	 ..CD!1&&q)#[[z:D!,"KKc..AB"NN8SI   	
   		
r   )__jwkN__keyId__providerId)zsi:md5)__name__
__module____qualname____firstlineno__ro   rl   rm   r)   r   dictr-   rX   r<   rh   rp   ri   rq   r:   rr   r$   __static_attributes__ r   r   r
   r
   	   s    NIF(c (3 (S (PT (
@ @ @J J JD
D U 
s 
C 
X] 
bg 
 =# =% =3
 3
 3
r   r
   )r%   rf   rE   +cryptography.hazmat.primitives.ciphers.aeadr   1cryptography.hazmat.primitives.asymmetric.paddingr   r   -cryptography.hazmat.primitives.asymmetric.rsar   %cryptography.hazmat.primitives.hashesr   cryptography.hazmat.backendsr   r
   r   r   r   <module>r      s&      > H J 6 8l
 l
r   