zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
U
ß=®d—$ã@sÖddlZddlZddlZddlmZddlmZddlmZddlmZddl    m
Z
ej e e fZejeZej ejeefZGdd    „d    ƒZGd
d „d eƒZGd d „d eƒZeeje dœdd„ZGdd„dƒZdS)éNé)Ú_base64_alphabet)Ú base64_decode)Ú base64_encode©Ú
want_bytes)Ú BadSignaturec@s6eZdZdZeeedœdd„Zeeeedœdd„ZdS)    ÚSigningAlgorithmzgSubclasses must implement :meth:`get_signature` to provide
    signature generation functionality.
    ©ÚkeyÚvalueÚreturncCs
tƒ‚dS)z2Returns the signature for the given key and value.N)ÚNotImplementedError©Úselfr r ©rúJd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\itsdangerous/signer.pyÚ get_signatureszSigningAlgorithm.get_signature)r r Úsigr cCst || ||¡¡S)zMVerifies the given signature matches the expected
        signature.
        )ÚhmacÚcompare_digestr)rr r rrrrÚverify_signaturesz!SigningAlgorithm.verify_signatureN)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ÚbytesrÚboolrrrrrr    sr    c@s"eZdZdZeeedœdd„ZdS)Ú NoneAlgorithmz`Provides an algorithm that does not perform any signing and
    returns an empty signature.
    r
cCsdS)Nórrrrrr%szNoneAlgorithm.get_signatureN)rrrrrrrrrrr src@sJeZdZUdZeejƒZej    e
d<d
ej    dœdd„Z e e e dœdd    „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)rÚnewr"Údigest)rr r Úmacrrrr7szHMACAlgorithm.get_signature)N)rrrrÚ staticmethodÚhashlibÚsha1r!Ú_tÚAnyÚ__annotations__r#rrrrrrr )s
r ©Ú
secret_keyr cCs&t|ttfƒrt|ƒgSdd„|DƒS)NcSsg|] }t|ƒ‘qSrr)Ú.0ÚsrrrÚ
<listcomp>@sz#_make_keys_list.<locals>.<listcomp>)Ú
isinstanceÚstrrr)r0rrrÚ_make_keys_list<s
r6c@sÖeZdZUdZeejƒZej    e
d<dZ e e
d<de eeeje ejej    ejedœd    d
„Zeed œd d „ƒZdeedœdd„Zeedœdd„Zeedœdd„Zeeedœdd„Zeedœdd„Zeedœdd„ZdS) ÚSigneraÖA 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-concatÚdefault_key_derivationóitsdangerous.Signeró.N)r0ÚsaltÚsepÚkey_derivationr"Ú    algorithmcCs†t|ƒ|_t|ƒ|_|jtkr&tdƒ‚|dk    r8t|ƒ}nd}||_|dkrP|j}||_|dkrd|j    }||_
|dkr|t |j
ƒ}||_ 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:) r6Ú secret_keysrr=rÚ
ValueErrorr<r9r>r!r"r r?)rr0r<r=r>r"r?rrrr#xs&
 
 
ÿ
 
zSigner.__init__)r cCs
|jdS)zThe newest (last) entry in the :attr:`secret_keys` list. This
        is for compatibility from before key rotation support was added.
        éÿÿÿÿ)r@)rrrrr0¦szSigner.secret_keyr/cCs´|dkr|jd}nt|ƒ}|jdkrBt t| |j|¡ ¡¡S|jdkrlt t| |jd|¡ ¡¡S|jdkršt    j
||jd}|  |j¡| ¡S|jdkr¨|St d    ƒ‚dS)
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.
 
        :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.
        NrBÚconcatr8ssignerr)r%ÚnonezUnknown key derivation method) r@rr>r,Úcastrr"r<r'rr&ÚupdateÚ    TypeError)rr0r(rrrÚ
derive_key­s"  
 
ÿ
 
zSigner.derive_key)r r cCs&t|ƒ}| ¡}|j ||¡}t|ƒS)z*Returns the signature for the given value.)rrHr?rr)rr r rrrrrÎszSigner.get_signaturecCst|ƒ}||j| |¡S)zSigns the given string.)rr=r)rr rrrÚsignÕsz Signer.sign)r rr cCs`z t|ƒ}Wntk
r"YdSXt|ƒ}t|jƒD]$}| |¡}|j |||¡r6dSq6dS)z+Verifies the signature for the given value.FT)rÚ    ExceptionrÚreversedr@rHr?r)rr rr0r rrrrÚs 
zSigner.verify_signature)Ú signed_valuer cCs^t|ƒ}|j|kr$td|j›dƒ‚| |jd¡\}}| ||¡rF|Std|›d|d‚dS)zUnsigns the given string.zNo z found in valuerz
Signature z does not match)ÚpayloadN)rr=rÚrsplitr)rrLr rrrrÚunsignës
 z Signer.unsigncCs,z| |¡WdStk
r&YdSXdS)znOnly validates the given signed value. Returns ``True`` if
        the signature exists and is valid.
        TFN)rOr)rrLrrrÚvalidateùs
 
zSigner.validate)r:r;NNN)N)rrrrr)r*r+r!r,r-r.r9r5Ú _t_secret_keyÚ_t_opt_str_bytesÚ _t_str_bytesÚOptionalr    r#Úpropertyrr0rHrrIrrrOrPrrrrr7Cs0
+ ù
ù .!r7)r*rÚtypingr,ÚencodingrrrrÚexcrÚUnionr5rrSrTrRÚIterablerQr    rr ÚListr6r7rrrrÚ<module>s