
    ?h
                         d dl mZmZmZmZ d dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZmZmZ d dlZd dlZdZd Zd Zd Zd	dZy)
    )print_functionunicode_literalsabsolute_importdivisionN)ensure_textensure_binarydata_to_string	is_base64zprivate-encrypted-c                 0    | j                  t              ryy)z[
    is_encrypted_channel() checks if the channel is encrypted by verifying the prefix
    TF)
startswithENCRYPTED_PREFIX)channels    N/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/pusher/crypto.pyis_encrypted_channelr      s     *+    c                 *   | |t        d      | :t        j                  d       t        |       dk(  rt	        | d      S t        d      |Ft        |      r0t        j                  |      }t        |      dk(  r|S t        d      t        d      y)	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&&'CDG7|r! !qrrPQQr   c                 l    |t        d      | |z   }t        j                  |      j                         S )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   sB    
 $  d  e  	e..H>>(#**,,r   c                    t        | d      } t        | |      }t        j                  j	                  |      }|Bt        j
                  j                  t        j                  j                  j                        }nt        |d      }t        j                  |      }|j                  |j                  d      |      }|j                  }t        j                  |      }	|j                  d      |	j                  d      dS )zS
    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*74I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   