Debian Codegraph @

docs/signer.rst

raw
1 .. module:: itsdangerous.signer
2
3 Signing Interface
4 =================
5
6 The most basic interface is the signing interface. The :class:`Signer`
7 class can be used to attach a signature to a specific string:
8
9 .. code-block:: python
10
11 from itsdangerous import Signer
12 s = Signer("secret-key")
13 s.sign("my string")
14 b'my string.wh6tMHxLgJqB6oY1uT73iMlyrOA'
15
16 The signature is appended to the string, separated by a dot. To validate
17 the string, use the :meth:`~Signer.unsign` method:
18
19 .. code-block:: python
20
21 s.unsign(b"my string.wh6tMHxLgJqB6oY1uT73iMlyrOA")
22 b'my string'
23
24 If unicode strings are provided, an implicit encoding to UTF-8 happens.
25 However after unsigning you won't be able to tell if it was unicode or
26 a bytestring.
27
28 If the value is changed, the signature will no longer match, and
29 unsigning will raise a :exc:`~itsdangerous.exc.BadSignature` exception:
30
31 .. code-block:: python
32
33 s.unsign(b"different string.wh6tMHxLgJqB6oY1uT73iMlyrOA")
34 Traceback (most recent call last):
35 ...
36 BadSignature: Signature does not match
37
38 To record and validate the age of a signature, see :doc:`/timed`.
39
40 .. autoclass:: Signer
41 :members:
42
43
44 Signing Algorithms
45 ------------------
46
47 .. autoclass:: NoneAlgorithm
48
49 .. autoclass:: HMACAlgorithm