#[non_exhaustive]pub enum Error {
Syntax {
offset: usize,
reason: &'static str,
},
TrailingContent {
offset: usize,
},
DuplicateMember {
name: String,
offset: usize,
},
StringNotScalar {
offset: usize,
reason: &'static str,
},
UnsafeInteger {
token: String,
},
NonIntegerNumber {
token: String,
},
NonFiniteNumber {
token: String,
},
TooDeep {
limit: usize,
offset: usize,
},
Canonicalization {
detail: String,
},
TooLarge {
len: usize,
limit: usize,
},
}Expand description
Why a document was refused.
Every variant is a refusal, never a repair. A canonicalizer that repairs its input produces bytes two parties can disagree about, which is the whole failure canonicalization exists to remove.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Syntax
The bytes are not one syntactically valid JSON value.
Fields
TrailingContent
A complete JSON value was followed by something other than whitespace.
DuplicateMember
An object repeated a member name.
Collapsing a repeat to last-wins is a split-view attack: two parties read the same bytes as two different documents, and a signature over either reading verifies.
Fields
StringNotScalar
A string literal’s bytes do not denote a sequence of Unicode scalar values: an unpaired surrogate escape, a surrogate escape pair that is not high-then-low, a raw control character, invalid UTF-8 (which includes an overlong form and a surrogate encoded directly in UTF-8), or, under the I-JSON profile, a Unicode noncharacter.
The check runs on the raw bytes before any decode, because a decoder cannot report it afterwards: a decoder that substitutes U+FFFD leaves three distinct wire strings canonicalizing to identical bytes.
UnsafeInteger
An integer outside the range where an IEEE-754 double is exact, refused under the I-JSON safe-integer profile.
NonIntegerNumber
A number with a fractional part, refused under the integers-only tightening of the I-JSON profile.
NonFiniteNumber
A number token whose value is not finite as an IEEE-754 double, so RFC 8785 has no serialization for it.
TooDeep
Nesting exceeded the configured depth cap.
The cap refuses rather than recursing. Without it a crafted document overflows the stack, which is not catchable and happens before any signature is checked.
Fields
Canonicalization
The delegate refused to serialize a document this crate admitted.
Unreachable for an admitted document, and present rather than a panic:
serde_json_canonicalizer returns a serde_json::Error that is neither
Clone nor Eq, so it is carried as its rendered text. A caller that
sees this variant is looking at a disagreement between the admission
layer and the canonicalizer, which is a defect in one of them and not a
statement about the input.
TooLarge
The input exceeded the configured size cap.
A depth cap bounds the stack; a size cap bounds the heap. Both are needed, because a depth limit alone leaves memory use proportional to input length.
Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()