
    ,Ii
                         S SK JrJrJrJr  S SKrS SKrS SKrS SKrS SK	r	S SK
JrJrJrJr  S SKrS SKrSrS rS rS rS	S jrg)
    )print_functionunicode_literalsabsolute_importdivisionN)ensure_textensure_binarydata_to_string	is_base64zprivate-encrypted-c                 :    U R                  [        5      (       a  gg)zS
is_encrypted_channel() checks if the channel is encrypted by verifying the prefix
TF)
startswithENCRYPTED_PREFIX)channels    3/venv/lib/python3.13/site-packages/pusher/crypto.pyis_encrypted_channelr      s     *++    c                 D   U b  Ub  [        S5      eU b<  [        R                  " S5        [        U 5      S:X  a  [	        U S5      $ [        S5      eUbM  [        U5      (       a2  [        R                  " U5      n[        U5      S:X  a  U$ [        S5      e[        S5      eg)	z
parse_master_key validates, parses and returns the bytes of the encryption master key
from the constructor arguments.
At present there is a deprecated "raw" key and a suggested base64 encoding.
NzDo not provide both encryption_master_key and encryption_master_key_base64. encryption_master_key is deprecated, provide only encryption_master_key_base64zP`encryption_master_key` is deprecated, please use `encryption_master_key_base64`    encryption_master_keyz+encryption_master_key must be 32 bytes longzNencryption_master_key_base64 must be a base64 string which decodes to 32 bytesz1encryption_master_key_base64 must be valid base64)
ValueErrorwarningswarnlenr   r
   base64	b64decode)r   encryption_master_key_base64decodeds      r   parse_master_keyr   #   s     (-I-U a b 	b (hi$%+ !68OPPJKK#/122&&'CDG7|r! !qrrPQQr   c                 n    Uc  [        S5      eX-   n[        R                  " U5      R                  5       $ )z
generate_shared_secret() takes a six.binary_type (python2 str or python3 bytes) channel name and encryption_master_key
and returns the sha256 hash in six.binary_type format
zNo master key was provided for use with encrypted channels. Please provide encryption_master_key_base64 as an argument to the Pusher SDK)r   hashlibsha256digest)r   r   hashables      r   generate_shared_secretr#   A   s?    
 $  d  e  	e.H>>(#**,,r   c                    [        U S5      n [        X5      n[        R                  R	                  U5      nUcB  [        R
                  R                  [        R                  R                  R                  5      nO[        US5      n[        R                  " U5      nUR                  UR                  S5      U5      nUR                  n[        R                  " U5      n	UR                  S5      U	R                  S5      S.$ )zK
encrypt() encrypts the provided payload specified in the 'data' parameter
r   noncezutf-8)r%   
ciphertext)r   r#   naclsecret	SecretBoxutilsrandom
NONCE_SIZEr   	b64encodeencryptencoder&   decode)
r   datar   r%   shared_secretbox	nonce_b64	encryptedcipher_textcipher_text_b64s
             r   r.   r.   L   s     GY/G*7JM
++


.C}

!!$++"7"7"B"BCeW-   'I DKK0%8I &&K&&{3O !''0@V@VW^@_aar   )N)
__future__r   r   r   r   r   r'   r   binasciir   pusher.utilr   r   r	   r
   nacl.secret
nacl.utilsr   r   r   r#   r.    r   r   <module>r>      sO             ( <	-br   