Format: application/x-python-code
⬇ Download File (8.8 KB)
   1  o
   2  
   3  .'h�%�@s�ddlmZddlmZddlZddlZddlZddl	m
   4  Z
   5  ddl	mZddl	mZddl	m
   6  Z
   7  ddlmZGd	d
   8  �d
   9  �ZGdd�de�Zdddd�ZGdd�de�Zddd�ZGdd�d�ZdS) �)�annotationsN�)�_base64_alphabet)�
  10  base64_decode)�
  11  base64_encode��
  12  want_bytes)�BadSignaturec@s$eZdZdZd
  13  dd�Zdd
  14  d�ZdS)�SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
  15      signature generation functionality.
  16      �key�bytes�value�returncCst��)z2Returns the signature for the given key and value.)�NotImplementedError��selfrr
  17  �r�IC:\Users\shubh\Videos\agent\nova\Lib\site-packages\itsdangerous/signer.py�
  18  get_signatureszSigningAlgorithm.get_signature�sig�boolcCst�||�||��S)zMVerifies the given signature matches the expected
  19          signature.
  20          )�hmac�compare_digestr)rrr
  21  rrrr�verify_signaturesz!SigningAlgorithm.verify_signatureN�rrr
  22  rrr)rrr
  23  rrrrr)�__name__�
  24  __module__�__qualname__�__doc__rrrrrrr
  25  s
  26  r
  27  c@seZdZdZd	dd�ZdS)
  28  �
  29  NoneAlgorithmz`Provides an algorithm that does not perform any signing and
  30      returns an empty signature.
  31      rrr
  32  rcCsdS)N�rrrrrr$szNoneAlgorithm.get_signatureNr)rrrrrrrrrrsrr �stringrr�t.AnycCs
  33  t�|�S)z�Don't access ``hashlib.sha1`` until runtime. FIPS builds may not include
  34      SHA-1, in which case the import and use as a default would fail before the
  35      developer can configure something else.
  36      )�hashlib�sha1)r!rrr�
  37  _lazy_sha1(�
  38  r%c@s8eZdZUdZee�Zded<dddd�Zddd
  39  �Z	dS)�
  40  HMACAlgorithmz*Provides signature generation using HMACs.r"�default_digest_methodN�
  41  digest_methodcCs|dur|j}||_dS�N)r(r))rr)rrr�__init__8s
  42  zHMACAlgorithm.__init__rrr
  43  rcCstj|||jd�}|��S)N)�msg�	digestmod)r�newr)�digest)rrr
  44  �macrrrr>szHMACAlgorithm.get_signaturer*)r)r"r)
  45  rrrr�staticmethodr%r(�__annotations__r+rrrrrr'0s
  46  
  47  r'�
  48  secret_key�7str | bytes | cabc.Iterable[str] | cabc.Iterable[bytes]�list[bytes]cCs&t|ttf�rt|�gSdd�|D�S)NcSsg|]}t|��qSrr)�.0�srrr�
  49  <listcomp>Isz#_make_keys_list.<locals>.<listcomp>)�
  50  isinstance�strrr)r3rrr�_make_keys_listCs
  51  r;c@s�eZdZUdZee�Zded<dZded<								d,d-dd�Z	e
  52  d.dd��Zd/d0dd�Zd1dd �Z
  53  d1d!d"�Zd2d%d&�Zd3d(d)�Zd4d*d+�Zd	S)5�Signera�A signer securely signs bytes, then unsigns them to verify that
  54      the value hasn't been changed.
  55  
  56      The secret key should be a random string of ``bytes`` and should not
  57      be saved to code or version control. Different salts should be used
  58      to distinguish signing in different contexts. See :doc:`/concepts`
  59      for information about the security of the secret key and salt.
  60  
  61      :param secret_key: The secret key to sign and verify with. Can be a
  62          list of keys, oldest to newest, to support key rotation.
  63      :param salt: Extra key to combine with ``secret_key`` to distinguish
  64          signatures in different contexts.
  65      :param sep: Separator between the signature and value.
  66      :param key_derivation: How to derive the signing key from the secret
  67          key and salt. Possible values are ``concat``, ``django-concat``,
  68          or ``hmac``. Defaults to :attr:`default_key_derivation`, which
  69          defaults to ``django-concat``.
  70      :param digest_method: Hash function to use when generating the HMAC
  71          signature. Defaults to :attr:`default_digest_method`, which
  72          defaults to :func:`hashlib.sha1`. Note that the security of the
  73          hash alone doesn't apply when used intermediately in HMAC.
  74      :param algorithm: A :class:`SigningAlgorithm` instance to use
  75          instead of building a default :class:`HMACAlgorithm` with the
  76          ``digest_method``.
  77  
  78      .. versionchanged:: 2.0
  79          Added support for key rotation by passing a list to
  80          ``secret_key``.
  81  
  82      .. versionchanged:: 0.18
  83          ``algorithm`` was added as an argument to the class constructor.
  84  
  85      .. versionchanged:: 0.14
  86          ``key_derivation`` and ``digest_method`` were added as arguments
  87          to the class constructor.
  88      r"r(�
  89  django-concatr:�default_key_derivation�itsdangerous.Signer�.Nr3r4�salt�str | bytes | None�sep�str | bytes�key_derivation�
  90  str | Noner)�t.Any | None�	algorithm�SigningAlgorithm | NonecCs�t|�|_t|�|_|jtvrtd��|durt|�}nd}||_|dur(|j}||_|dur2|j	}||_
  91  |dur>t|j
  92  �}||_dS)Nz�The given separator cannot be used because it may be contained in the signature itself. ASCII letters, digits, and '-_=' must not be used.r?)
  93  r;�secret_keysrrCr�
  94  ValueErrorrAr>rEr(r)r'rH)rr3rArCrEr)rHrrrr+�s&
  95  
  96  
  97  �
  98  
  99  
 100  zSigner.__init__rrcCs
 101  |jdS)z�The newest (last) entry in the :attr:`secret_keys` list. This
 102          is for compatibility from before key rotation support was added.
 103          �����)rJ)rrrrr3�r&zSigner.secret_keycCs�|dur
 104  |jd}nt|�}|jdkr!t�t|�|j|����S|jdkr6t�t|�|jd|����S|jdkrMt	j
 105  ||jd�}|�|j�|��S|jdkrT|Std	��)
 106  a�This method is called to derive the key. The default key
 107          derivation choices can be overridden here. Key derivation is not
 108          intended to be used as a security method to make a complex key
 109          out of a short password. Instead you should use large random
 110          secret keys.
 111  
 112          :param secret_key: A specific secret key to derive from.
 113              Defaults to the last item in :attr:`secret_keys`.
 114  
 115          .. versionchanged:: 2.0
 116              Added the ``secret_key`` parameter.
 117          NrL�concatr=ssignerr)r-�nonezUnknown key derivation method)
 118  rJrrE�t�castrr)rAr/rr.�update�	TypeError)rr3r0rrr�
 119  derive_key�s 
 120  
 121  
 122  �
 123  
 124  zSigner.derive_keyr
 125  cCs&t|�}|��}|j�||�}t|�S)z*Returns the signature for the given value.)rrSrHrr)rr
 126  rrrrrr�szSigner.get_signaturecCst|�}||j|�|�S)zSigns the given string.)rrCr)rr
 127  rrr�sign�szSigner.signrrcCs^zt|�}Wn
 128  tyYdSwt|�}t|j�D]}|�|�}|j�|||�r,dSqdS)z+Verifies the signature for the given value.FT)r�	Exceptionr�reversedrJrSrHr)rr
 129  rr3rrrrr�s�
 130  �zSigner.verify_signature�signed_valuecCsZt|�}|j|vrtd|j�d���|�|jd�\}}|�||�r#|Std|�d�|d��)zUnsigns the given string.zNo z found in valuerz
 131  Signature z does not match)�payload)rrCr	�rsplitr)rrWr
 132  rrrr�unsign�s
 133  z
 134  Signer.unsigncCs&z|�|�WdStyYdSw)znOnly validates the given signed value. Returns ``True`` if
 135          the signature exists and is valid.
 136          TF)rZr	)rrWrrr�validates
 137  �zSigner.validate)r?r@NNN)r3r4rArBrCrDrErFr)rGrHrI)rrr*)r3rBrr)r
 138  rDrr)r
 139  rDrrDrr)rWrDrr)rWrDrr)rrrrr1r%r(r2r>r+�propertyr3rSrrTrrZr[rrrrr<Ls$
 140  +�.
 141  !
 142  
 143  
 144  r<)r )r!rrr")r3r4rr5)�
 145  __future__r�collections.abc�abcZcabcr#r�typingrO�encodingrrrr�excr	r
 146  rr%r'r;r<rrrr�<module>s 	
 147