U a$@sddlZddlZddlZddlmZddlmZddlmZddlmZddl m Z ej e e fZejeZej ejeefZGdd d ZGd d d eZGd d d eZeeje dddZGdddZdS)N)_base64_alphabet) base64_decode) base64_encode want_bytes) BadSignaturec@s6eZdZdZeeedddZeeeedddZdS) SigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide signature generation functionality. keyvaluereturncCs tdS)z2Returns the signature for the given key and value.N)NotImplementedErrorselfr r rTC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-w3tduf5e\itsdangerous\signer.py get_signatureszSigningAlgorithm.get_signature)r r sigr cCst||||S)zMVerifies the given signature matches the expected signature. )hmaccompare_digestr)rr r rrrrverify_signaturesz!SigningAlgorithm.verify_signatureN)__name__ __module__ __qualname____doc__bytesrboolrrrrrr sr c@s"eZdZdZeeedddZdS) NoneAlgorithmz`Provides an algorithm that does not perform any signing and returns an empty signature. r cCsdS)Nrrrrrr%szNoneAlgorithm.get_signatureN)rrrrrrrrrrr src@sJeZdZUdZeejZej e d<d ej dddZ e e e ddd Z dS) HMACAlgorithmz*Provides signature generation using HMACs.default_digest_methodN) digest_methodcCs|dkr|j}||_dS)N)r!r")rr"rrr__init__1szHMACAlgorithm.__init__r cCstj|||jd}|S)N)msg digestmod)rnewr"digest)rr r macrrrr7szHMACAlgorithm.get_signature)N)rrrr staticmethodhashlibsha1r!_tAny__annotations__r#rrrrrrr )s r  secret_keyr cCs&t|ttfrt|gSdd|DS)NcSsg|] }t|qSrr).0srrr @sz#_make_keys_list..) isinstancestrrr)r0rrr_make_keys_list<s r6c@seZdZUdZeejZej e d<dZ e e d<de eeeje ejej ejedd d Zeed d d ZdeedddZeedddZeedddZeeedddZeedddZeedddZdS) SigneraA signer securely signs bytes, then unsigns them to verify that the value hasn't been changed. The secret key should be a random string of ``bytes`` and should not be saved to code or version control. Different salts should be used to distinguish signing in different contexts. See :doc:`/concepts` for information about the security of the secret key and salt. :param secret_key: The secret key to sign and verify with. Can be a list of keys, oldest to newest, to support key rotation. :param salt: Extra key to combine with ``secret_key`` to distinguish signatures in different contexts. :param sep: Separator between the signature and value. :param key_derivation: How to derive the signing key from the secret key and salt. Possible values are ``concat``, ``django-concat``, or ``hmac``. Defaults to :attr:`default_key_derivation`, which defaults to ``django-concat``. :param digest_method: Hash function to use when generating the HMAC signature. Defaults to :attr:`default_digest_method`, which defaults to :func:`hashlib.sha1`. Note that the security of the hash alone doesn't apply when used intermediately in HMAC. :param algorithm: A :class:`SigningAlgorithm` instance to use instead of building a default :class:`HMACAlgorithm` with the ``digest_method``. .. versionchanged:: 2.0 Added support for key rotation by passing a list to ``secret_key``. .. versionchanged:: 0.18 ``algorithm`` was added as an argument to the class constructor. .. versionchanged:: 0.14 ``key_derivation`` and ``digest_method`` were added as arguments to the class constructor. r! django-concatdefault_key_derivationitsdangerous.Signer.N)r0saltsepkey_derivationr" algorithmcCst||_t||_|jtkr&td|dk r8t|}nd}||_|dkrP|j}||_|dkrd|j }||_ |dkr|t |j }||_ dS)NzThe given separator cannot be used because it may be contained in the signature itself. ASCII letters, digits, and '-_=' must not be used.r:) r6 secret_keysrr=r ValueErrorr<r9r>r!r"r r?)rr0r<r=r>r"r?rrrr#xs&     zSigner.__init__)r cCs |jdS)zThe newest (last) entry in the :attr:`secret_keys` list. This is for compatibility from before key rotation support was added. )r@)rrrrr0szSigner.secret_keyr/cCs|dkr|jd}nt|}|jdkrBtt||j|S|jdkrltt||jd|S|jdkrt j ||jd}| |j|S|jdkr|St d dS) aThis 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. :param secret_key: A specific secret key to derive from. Defaults to the last item in :attr:`secret_keys`. .. versionchanged:: 2.0 Added the ``secret_key`` parameter. NrBconcatr8ssignerr)r%nonezUnknown key derivation method) r@rr>r,castrr"r<r'rr&update TypeError)rr0r(rrr derive_keys"       zSigner.derive_key)r r cCs&t|}|}|j||}t|S)z*Returns the signature for the given value.)rrHr?rr)rr r rrrrrszSigner.get_signaturecCst|}||j||S)zSigns the given string.)rr=r)rr rrrsignsz Signer.sign)r rr cCs`z t|}Wntk r"YdSXt|}t|jD]$}||}|j|||r6dSq6dS)z+Verifies the signature for the given value.FT)r Exceptionrreversedr@rHr?r)rr rr0r rrrrs  zSigner.verify_signature) signed_valuer cCs^t|}|j|kr$td|jd||jd\}}|||rF|Std|d|ddS)zUnsigns the given string.zNo z found in valuerz Signature z does not match)payloadN)rr=rrsplitr)rrLr rrrrunsigns  z Signer.unsigncCs,z||WdStk r&YdSXdS)znOnly validates the given signed value. Returns ``True`` if the signature exists and is valid. TFN)rOr)rrLrrrvalidates  zSigner.validate)r:r;NNN)N)rrrrr)r*r+r!r,r-r.r9r5 _t_secret_key_t_opt_str_bytes _t_str_bytesOptionalr r#propertyrr0rHrrIrrrOrPrrrrr7Cs0 +   .!r7)r*rtypingr,encodingrrrrexcrUnionr5rrSrTrRIterablerQr rr Listr6r7rrrrs