gaseto/error
The errors Gaseto returns.
case gaseto.decrypt(token, key, gaseto.new_rules()) {
Ok(token) -> Ok(gaseto.subject(token))
Error(error.Expired(_)) -> Error("Please log in again")
Error(_) -> Error("Invalid token")
}
Types
What is wrong with a registered claim in a token.
pub type ClaimFormatError {
NotAString
NotAnRfc3339Time
}
Constructors
-
NotAStringThe spec defines the registered claims as strings (Registered Claims).
-
NotAnRfc3339TimeThe spec requires times in RFC 3339, with an uppercase “T” and “Z” (Registered Claims).
Why decode_footer could not decode a footer: it broke a limit in
FooterRules, or the decoder failed.
pub type FooterDecodingError {
FooterTooLong(length: Int, max_length: Int)
FooterTooDeep(depth: Int, max_depth: Int)
FooterHasTooManyKeys(key_count: Int, max_keys: Int)
FooterIsMalformed
FooterDecodeFailed(error: json.DecodeError)
}
Constructors
-
FooterTooLong(length: Int, max_length: Int)The footer is longer than
FooterRulesallows. -
FooterTooDeep(depth: Int, max_depth: Int)The footer is nested deeper than
FooterRulesallows. -
FooterHasTooManyKeys(key_count: Int, max_keys: Int)The footer has more keys than
FooterRulesallows. -
FooterIsMalformedThe brackets or quotes do not match, so the footer is not valid JSON.
-
FooterDecodeFailed(error: json.DecodeError)The footer passed the checks, but the decoder failed.
Why a key could not be loaded from hex or PEM.
pub type KeyLoadingError {
NotHex
WrongLength(expected: Int, found: Int)
OutsideCurveRange
NotACompressedPoint
NotOnCurve
PublicHalfDoesNotMatchSeed
SmallOrderPublicKey
InvalidPem
UnexpectedKeyFailure(reason: String)
}
Constructors
-
NotHexThe key is not written as hex.
-
WrongLength(expected: Int, found: Int)The key has the wrong number of bytes. The spec sets the size of a local key (version 3, Encrypt, version 4, Encrypt) and of a version 3 secret key (version 3, Sign) and public key (version 3, Verify). The version 4 key sizes come from Ed25519.
-
OutsideCurveRangeThe version 3 secret key is out of range. Version 3 uses the P-384 elliptic curve (NIST SP 800-186, section 3.2.1.4), and a secret key is a number that must be at least 1 and less than the curve’s order, a fixed number that comes with the curve (FIPS 186-5, section 6.4.1).
-
NotACompressedPointA version 3 public key must start with 02 or 03, because the spec requires a compressed point (version 3, Verify).
-
NotOnCurveThe version 3 public key is not a point on the P-384 elliptic curve (NIST SP 800-186, section 3.2.1.4), so it cannot be a real public key.
-
PublicHalfDoesNotMatchSeedThe second half of a version 4 secret key is not the public key of its first half.
-
SmallOrderPublicKeyThe version 4 public key is one of a few special values that would let anyone forge tokens for it. The spec writes the check as libsodium’s
crypto_sign_verify_detached, which refuses these keys (version 4, Verify). -
InvalidPemThe text is not one PEM key of the kind needed: an Ed25519 key for version 4, or a P-384 key for version 3. Keys protected by a password are not read.
-
UnexpectedKeyFailure(reason: String)This should never happen. It means a bug in Gaseto or a library it uses.
reasonsays which step failed.
Why encrypt or sign could not create a token.
pub type TokenCreationError {
ReservedClaimName(name: String)
RepeatedKeyInClaim(name: String)
UnexpectedCreationFailure(reason: String)
}
Constructors
-
ReservedClaimName(name: String)A claim of your own uses one of the registered names (
iss,sub,aud,exp,nbf,iatorjti). The spec reserves these names (Registered Claims). -
RepeatedKeyInClaim(name: String)A claim of your own holds an object that repeats a key. The spec requires unique key names (Payload Processing).
-
UnexpectedCreationFailure(reason: String)This should never happen. It means a bug in Gaseto or a library it uses.
reasonsays which step failed.
Why a token’s format cannot be read. unverified_footer returns it
directly; decrypt and verify wrap it in InvalidFormat.
pub type TokenFormatError {
UnknownVersion(version: String)
UnsupportedVersion(version: String)
UnknownPurpose(purpose: String)
WrongNumberOfSegments
EmptyFooterSegment
NotBase64Url
BodyTooShort
}
Constructors
-
UnknownVersion(version: String)The version is not one the spec defines (Message Format).
-
UnsupportedVersion(version: String) -
UnknownPurpose(purpose: String)The purpose is not
localorpublic, the only ones the spec allows (Message Format). -
WrongNumberOfSegmentsA token has three or four parts separated by dots (Message Format).
-
EmptyFooterSegmentThe token ends with a dot but no footer. The spec only adds the dot when there is a footer (version 4, Encrypt).
-
NotBase64UrlA part is not strict, unpadded base64url, as the spec requires (Base64 Decoding).
-
BodyTooShortThe token is too short to hold its nonce, tag or signature.
Why decrypt or verify refused a token.
pub type TokenValidationError {
TokenTooLong(length: Int, max_length: Int)
InvalidFormat(error: TokenFormatError)
UnexpectedVersion(expected: String, found: String)
UnexpectedPurpose(expected: String, found: String)
TokenNotAuthentic
InvalidPayload
InvalidClaim(name: String, error: ClaimFormatError)
MissingExpiration
Expired(expired_at: timestamp.Timestamp)
NotYetValid(valid_from: timestamp.Timestamp)
IssuedInTheFuture(issued_at: timestamp.Timestamp)
UnexpectedClaim(
name: String,
expected: String,
found: option.Option(String),
)
UnexpectedValidationFailure(reason: String)
}
Constructors
-
TokenTooLong(length: Int, max_length: Int)The token is longer than the rules allow. See
allow_token_length. -
InvalidFormat(error: TokenFormatError)The token cannot be read.
-
UnexpectedVersion(expected: String, found: String)The token’s version is not the key’s version, for example
"v4"and"v3". The spec requires a key to be used only with its own version (Algorithm Lucidity). -
UnexpectedPurpose(expected: String, found: String)A
"local"token was given where a"public"one was expected, or the other way around. The spec requires a key to be used only for its own purpose (Algorithm Lucidity). -
TokenNotAuthenticThe tag or signature does not match. Either the token was changed, or the key or implicit assertion is wrong. On purpose, it does not say which.
-
InvalidPayloadThe payload is not UTF-8 text, is not a JSON object, or repeats a key. The spec requires a JSON object with unique key names (Payload Processing).
-
InvalidClaim(name: String, error: ClaimFormatError)A registered claim has the wrong format.
-
MissingExpirationThe token has no
expclaim. The spec recommends requiring one by default (Default Expiration Claims), sonew_rulesdoes. Useallow_no_expirationto accept such tokens. -
Expired(expired_at: timestamp.Timestamp)The token expired at this time.
-
NotYetValid(valid_from: timestamp.Timestamp)The token is not valid until this time (its
nbfclaim). -
IssuedInTheFuture(issued_at: timestamp.Timestamp)The token says it was issued in the future (its
iatclaim). -
UnexpectedClaim( name: String, expected: String, found: option.Option(String), )A claim does not have the value the rules expect.
-
UnexpectedValidationFailure(reason: String)This should never happen. It means a bug in Gaseto or a library it uses.
reasonsays which step failed.