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
"""Compare release digests using only in-memory values.
Where a digest arrives from an untrusted source, :func:`constant_time_equal`
compares it without revealing, through timing, how much of the expected value
a guess matched. File reads and hashing live in :mod:`release_digest_files`.
Behavioural coverage lives in ``scripts/release/tests/test_release_digest.py``.
"""
"""Report that a digest could not be read or did not match."""
"""Report bytes whose digest is not the one recorded for them."""
"""Compare two digest strings without exiting early on a mismatch.
Parameters
----------
left
One digest, usually the freshly computed one.
right
The other digest, usually the one a registry or a sidecar recorded.
Returns
-------
bool
Whether the two are equal, compared as bytes.
Notes
-----
:func:`hmac.compare_digest` is used rather than ``==``. A published digest
is not a secret, so this hides nothing here; it keeps the comparison
independent of how many leading characters agree, which matters once the
same helper is reused for values that are not public. Case is ignored,
because ``sha256sum`` writes lowercase while other producers emit
uppercase.
Examples
--------
>>> constant_time_equal("AB" * 32, "ab" * 32)
True
>>> constant_time_equal("ab" * 32, "ab" * 31 + "cd")
False
"""
return