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
// SPDX-License-Identifier: MIT OR Apache-2.0
use std::fmt;
/// Errors produced by the text soft-binding algorithms.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
/// Input has too little content for the requested algorithm (e.g. not
/// enough word boundaries to place a watermark payload).
ContentTooShort,
/// A fingerprint value could not be produced.
GenerationFailed(String),
/// A fingerprint comparison failed.
MatchFailed(String),
/// Reed-Solomon erasure coding/decoding failed.
Coding(String),
/// The watermark payload was present but its content-binding HMAC did not
/// verify against the recomputed content hash (transfer or tamper).
TagMismatch,
/// The watermark could not be recovered (too many stripped positions).
WatermarkUnrecoverable,
/// A caller-supplied argument was malformed.
InvalidInput(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::ContentTooShort => {
write!(f, "text content too short for this soft-binding algorithm")
}
Self::GenerationFailed(s) => write!(f, "fingerprint generation failed: {s}"),
Self::MatchFailed(s) => write!(f, "fingerprint match failed: {s}"),
Self::Coding(s) => write!(f, "reed-solomon coding failed: {s}"),
Self::TagMismatch => write!(
f,
"watermark content-binding tag did not verify (transferred or modified content)"
),
Self::WatermarkUnrecoverable => {
write!(
f,
"watermark could not be recovered from remaining positions"
)
}
Self::InvalidInput(s) => write!(f, "invalid input: {s}"),
}
}
}
impl std::error::Error for Error {}