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
//! CRC-32C (Castagnoli), the ticket's transcription check.
//!
//! Pure, and small enough to be worth not taking a dependency for: this is
//! the bit-serial form, twelve lines, no lookup table. The ticket is the
//! only thing in the crate that needs a checksum and it is at most a
//! kilobyte, so a table-driven implementation would trade readability for
//! speed nobody can measure.
//!
//! What it is for, and is not: it catches a mistyped character or a misread
//! QR code. It is not a signature and does not resist tampering — anyone
//! able to alter a ticket in transit can recompute this trivially. The real
//! authentication is the endpoint key in the ticket plus the bearer token
//! that never rides in one.
/// The reflected form of polynomial `0x1EDC6F41`. Reflected because the
/// algorithm shifts right, which is what makes the bit-serial loop below
/// this short.
const POLY_REFLECTED: u32 = 0x82F6_3B78;
/// Both the initial value and the final XOR, per the CRC-32C definition.
const INIT_AND_XOROUT: u32 = 0xFFFF_FFFF;
/// CRC-32C of `data`.
///
/// `const` so the published check value can be asserted at compile time
/// rather than in a test that has to be run — see below.
pub const
// The published CRC-32C check value, asserted at compile time. This is the
// one number that proves the implementation is the algorithm the spec names
// rather than merely *a* CRC — every conforming implementation in every
// language agrees on it, which is exactly the property a cross-language wire
// format needs. As a `const` assertion it cannot be skipped, filtered out of
// a test run, or left unexecuted: a wrong constant fails the build.
const _: = assert!;