
    ]fv                         d dl Z d dlZ	 d dlmZ ddZn# e$ r d dlmZ ddZY nw xY wddZ	d Z
d Zd	 Zd
 Zd Zd Zd ZdS )    N)int_to_bytesc                 &    t          | |pd           S )N)_long_to_bytes)n	blocksizes     </var/www/html/env/lib/python3.11/site-packages/jose/utils.pylong_to_bytesr	   	   s    a!2d333    )int_to_stringc                     t          |           }|dk    r|S t          |          |k    sJ |t          |          z
  }d|z  |z   S )Nr       )r   len)r   r   retpaddings       r   r	   r	      sT    Q>>Js88y((((#c((*GW$s**r
   c                 l    t          j        t          | |                                        d          S )N   =)base64urlsafe_b64encoder	   strip)datasizes     r   long_to_base64r      s+    #M$$=$=>>DDTJJJr
   c                 \    t          d                    d | D                       d          S )N c                     g | ]}d |z  S )z%02x ).0bytes     r   
<listcomp>z#int_arr_to_long.<locals>.<listcomp>   s    666$666r
      )intjoin)arrs    r   int_arr_to_longr$      s-    rww66#66677<<<r
   c                    t          | t                    r|                     d          } t          j        t          |           dz             }t          t          j        dt          |          z  |                    S )Nasciis   ==z%sB)

isinstancestrencoder   urlsafe_b64decodebytesr$   structunpackr   )r   _ds     r   base64_to_longr/   "   sf    $ ${{7## 
	!%++"5	6	6B6=R"==>>>r
   c                      ||                      d                                                    }t          t          |          dz            }|d|         }t	          |          }|                    d          S )a  Helper method for calculating an access token
    hash, as described in http://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken

    Its value is the base64url encoding of the left-most half of the hash of the octets
    of the ASCII representation of the access_token value, where the hash algorithm
    used is the hash algorithm used in the alg Header Parameter of the ID Token's JOSE
    Header. For instance, if the alg is RS256, hash the access_token value with SHA-256,
    then take the left-most 128 bits and base64url encode them. The at_hash value is a
    case sensitive string.

    Args:
        access_token (str): An access token string.
        hash_alg (callable): A callable returning a hash object, e.g. hashlib.sha256

    utf-8   N)r)   digestr!   r   base64url_encodedecode)access_tokenhash_alghash_digestcut_at	truncatedat_hashs         r   calculate_at_hashr<   +   st      (<..w7788??AAK[!!A%&&FGVG$Iy))G>>'"""r
   c                 p    t          |           dz  }|dk    r| dd|z
  z  z  } t          j        |           S )zwHelper method to base64url_decode a string.

    Args:
        input (str): A base64url_encoded string to decode.

       r   r   )r   r   r*   )inputrems     r   base64url_decoderA   B   s@     e**q.C
QwwS!!#E***r
   c                 R    t          j        |                               dd          S )zwHelper method to base64url_encode a string.

    Args:
        input (str): A base64url_encoded string to encode.

    r   r
   )r   r   replace)r?   s    r   r4   r4   Q   s%     #E**224===r
   c                 2    | j         dz  dz  dz  | j        z   S )zHelper method to determine the total number of seconds
    from a timedelta.

    Args:
        delta (timedelta): A timedelta to convert to seconds.
       <   )daysseconds)deltas    r   timedelta_total_secondsrJ   [   s!     :?R"$u}44r
   c                     t          | t                    r| S t          | t                    r|                     dd          S t	          dt          |            d          )zCoerce **s** to bytes.r1   strictznot expecting type '')r'   r+   r(   r)   	TypeErrortype)ss    r   ensure_binaryrQ   e   sa     !U !S +xx***
5477555
6
66r
   )r   )r   r,   cryptography.utilsr   r   r	   ImportErrorecdsa.ecdsar   r   r$   r/   r<   rA   r4   rJ   rQ   r   r
   r   <module>rU      s    +AAAAAA4 4 4 4 4  
+ 
+ 
+;;;;;;+ + + + + +
+K K K K= = =? ? ?# # #.+ + +> > >5 5 57 7 7 7 7s   
 ''