o
    [h                     @   s   d dl Z d dlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 G d	d
 d
eZG dd deZG dd deZG dd deZdS )    N   )constant_time_compare)_base64_alphabet)base64_decode)base64_encode)
want_bytes)BadSignaturec                   @   s    e Zd ZdZdd Zdd ZdS )SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
    signature generation functionality.
    c                 C   s   t  )z2Returns the signature for the given key and value.)NotImplementedErrorselfkeyvalue r   z/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/itsdangerous/signer.pyget_signature   s   zSigningAlgorithm.get_signaturec                 C   s   t || ||S )zMVerifies the given signature matches the expected
        signature.
        )r   r   )r   r   r   sigr   r   r   verify_signature   s   z!SigningAlgorithm.verify_signatureN)__name__
__module____qualname____doc__r   r   r   r   r   r   r	      s    r	   c                   @   s   e Zd ZdZdd ZdS )NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    c                 C   s   dS )N    r   r   r   r   r   r   !   s   zNoneAlgorithm.get_signatureN)r   r   r   r   r   r   r   r   r   r      s    r   c                   @   s,   e Zd ZdZeejZdddZdd Z	dS )HMACAlgorithmz*Provides signature generation using HMACs.Nc                 C   s   |d u r| j }|| _d S N)default_digest_methoddigest_method)r   r   r   r   r   __init__-   s   
zHMACAlgorithm.__init__c                 C   s   t j||| jd}| S )N)msg	digestmod)hmacnewr   digest)r   r   r   macr   r   r   r   2   s   zHMACAlgorithm.get_signaturer   )
r   r   r   r   staticmethodhashlibsha1r   r   r   r   r   r   r   r   %   s
    

r   c                   @   sb   e Zd ZdZeejZdZ					dddZ	dd Z
d	d
 Zdd Zdd Zdd Zdd ZdS )Signera  This class can sign and unsign bytes, validating the signature
    provided.

    Salt can be used to namespace the hash, so that a signed string is
    only valid for a given namespace. Leaving this at the default value
    or re-using a salt value across different parts of your application
    where the same signed value in one part can mean something different
    in another part is a security risk.

    See :ref:`the-salt` for an example of what the salt is doing and how
    you can utilize it.

    .. versionadded:: 0.14
        ``key_derivation`` and ``digest_method`` were added as arguments
        to the class constructor.

    .. versionadded:: 0.18
        ``algorithm`` was added as an argument to the class constructor.
    django-concatN.c                 C   s|   t || _t || _| jtv rtd|d u rdn|| _|d u r#| j}|| _|d u r-| j}|| _	|d u r9t
| j	}|| _d S )NzThe given separator cannot be used because it may be contained in the signature itself. Alphanumeric characters and `-_=` must not be used.zitsdangerous.Signer)r   
secret_keysepr   
ValueErrorsaltdefault_key_derivationkey_derivationr   r   r   	algorithm)r   r+   r.   r,   r0   r   r1   r   r   r   r   [   s    
	



zSigner.__init__c                 C   s   t | j}| jdkr| || j  S | jdkr%| |d | j  S | jdkr<tj| j| jd}|| | S | jdkrD| jS t	d)a+  This method is called to derive the key. The default key
        derivation choices can be overridden here. Key derivation is not
        intended to be used as a security method to make a complex key
        out of a short password. Instead you should use large random
        secret keys.
        concatr)   s   signerr!   )r    nonezUnknown key derivation method)
r   r.   r0   r   r+   r#   r!   r"   update	TypeError)r   r.   r$   r   r   r   
derive_keyw   s   





zSigner.derive_keyc                 C   s&   t |}|  }| j||}t|S )z*Returns the signature for the given value.)r   r6   r1   r   r   )r   r   r   r   r   r   r   r      s   zSigner.get_signaturec                 C   s   t |t | j | | S )zSigns the given string.)r   r,   r   )r   r   r   r   r   sign   s   zSigner.signc                 C   s:   |   }zt|}W n
 ty   Y dS w | j|||S )z+Verifies the signature for the given value.F)r6   r   	Exceptionr1   r   )r   r   r   r   r   r   r   r      s   zSigner.verify_signaturec                 C   sX   t |}t | j}||vrtd| j ||d\}}| ||r$|S td| |d)zUnsigns the given string.zNo %r found in valuer   zSignature %r does not match)payload)r   r,   r   rsplitr   )r   signed_valuer,   r   r   r   r   r   unsign   s   
zSigner.unsignc                 C   s&   z|  | W dS  ty   Y dS w )znOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.
        TF)r<   r   )r   r;   r   r   r   validate   s   
zSigner.validate)Nr*   NNN)r   r   r   r   r%   r&   r'   r   r/   r   r6   r   r7   r   r<   r=   r   r   r   r   r(   7   s     

	r(   )r&   r!   Z_compatr   encodingr   r   r   r   excr   objectr	   r   r   r(   r   r   r   r   <module>   s    	