#[non_exhaustive]#[repr(i32)]pub enum Error {
Show 36 variants
OutputPtrNull = -1,
OutputTooShort = -2,
OutputTooLong = -3,
PwdTooShort = -4,
PwdTooLong = -5,
SaltTooShort = -6,
SaltTooLong = -7,
AdTooShort = -8,
AdTooLong = -9,
SecretTooShort = -10,
SecretTooLong = -11,
TimeTooSmall = -12,
TimeTooLarge = -13,
MemoryTooLittle = -14,
MemoryTooMuch = -15,
LanesTooFew = -16,
LanesTooMany = -17,
PwdPtrMismatch = -18,
SaltPtrMismatch = -19,
SecretPtrMismatch = -20,
AdPtrMismatch = -21,
MemoryAllocationError = -22,
FreeMemoryCbkNull = -23,
AllocateMemoryCbkNull = -24,
IncorrectParameter = -25,
IncorrectType = -26,
OutPtrMismatch = -27,
ThreadsTooFew = -28,
ThreadsTooMany = -29,
MissingArgs = -30,
EncodingFail = -31,
DecodingFail = -32,
ThreadFail = -33,
DecodingLengthFail = -34,
VerifyMismatch = -35,
OsRandom = -100,
}Expand description
An Argon2 error.
The discriminants are the C error codes, so error as i32 is the C value
(see Error::as_c_code).
Some variants are unreachable through this crate’s API but are kept so the
mapping from C codes is total (see Error::from_c_code):
Error::OutputPtrNull,Error::PwdPtrMismatch,Error::SaltPtrMismatch,Error::SecretPtrMismatch,Error::AdPtrMismatch— Rust uses slices, there are no null pointers with a non-zero length.Error::FreeMemoryCbkNull,Error::AllocateMemoryCbkNull,Error::MissingArgs— this crate has no allocator callbacks.Error::IncorrectType—crate::Algorithmis a closed enum.
§Ordering, and why this is #[non_exhaustive]
The derived Ord compares discriminants, so the C codes sort -35 ..= -1
and any crate-specific variant sorts below all of them. That is incidental,
not a guarantee — do not read meaning into the ordering.
Error::OsRandom is the first variant that is not a C code, and there
may be more later. #[non_exhaustive] is what keeps adding one from being a
breaking change for a downstream match; write a _ arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
OutputPtrNull = -1
ARGON2_OUTPUT_PTR_NULL (-1). Unreachable in Rust.
OutputTooShort = -2
ARGON2_OUTPUT_TOO_SHORT (-2). Output shorter than crate::params::MIN_OUTLEN.
OutputTooLong = -3
ARGON2_OUTPUT_TOO_LONG (-3). Output longer than crate::params::MAX_OUTLEN.
PwdTooShort = -4
ARGON2_PWD_TOO_SHORT (-4). Unreachable: MIN_PWD_LENGTH is 0.
PwdTooLong = -5
ARGON2_PWD_TOO_LONG (-5).
SaltTooShort = -6
ARGON2_SALT_TOO_SHORT (-6). Salt shorter than crate::params::MIN_SALT_LENGTH.
SaltTooLong = -7
ARGON2_SALT_TOO_LONG (-7).
AdTooShort = -8
ARGON2_AD_TOO_SHORT (-8). Unreachable: MIN_AD_LENGTH is 0.
AdTooLong = -9
ARGON2_AD_TOO_LONG (-9).
SecretTooShort = -10
ARGON2_SECRET_TOO_SHORT (-10). Unreachable: MIN_SECRET is 0.
SecretTooLong = -11
ARGON2_SECRET_TOO_LONG (-11).
TimeTooSmall = -12
ARGON2_TIME_TOO_SMALL (-12).
TimeTooLarge = -13
ARGON2_TIME_TOO_LARGE (-13).
MemoryTooLittle = -14
ARGON2_MEMORY_TOO_LITTLE (-14).
MemoryTooMuch = -15
ARGON2_MEMORY_TOO_MUCH (-15).
LanesTooFew = -16
ARGON2_LANES_TOO_FEW (-16).
LanesTooMany = -17
ARGON2_LANES_TOO_MANY (-17).
PwdPtrMismatch = -18
ARGON2_PWD_PTR_MISMATCH (-18). Unreachable in Rust.
SaltPtrMismatch = -19
ARGON2_SALT_PTR_MISMATCH (-19). Unreachable in Rust.
SecretPtrMismatch = -20
ARGON2_SECRET_PTR_MISMATCH (-20). Unreachable in Rust.
AdPtrMismatch = -21
ARGON2_AD_PTR_MISMATCH (-21). Unreachable in Rust.
MemoryAllocationError = -22
ARGON2_MEMORY_ALLOCATION_ERROR (-22). The block arena could not be allocated.
FreeMemoryCbkNull = -23
ARGON2_FREE_MEMORY_CBK_NULL (-23). Unreachable: no allocator callbacks.
AllocateMemoryCbkNull = -24
ARGON2_ALLOCATE_MEMORY_CBK_NULL (-24). Unreachable: no allocator callbacks.
IncorrectParameter = -25
ARGON2_INCORRECT_PARAMETER (-25).
IncorrectType = -26
ARGON2_INCORRECT_TYPE (-26). Unreachable: crate::Algorithm is a closed enum.
OutPtrMismatch = -27
ARGON2_OUT_PTR_MISMATCH (-27). The output slice length disagrees with
crate::Params::tag_len_bytes. The C never returns this code — its out
and outlen travel together — so the crate reuses it for this
Rust-only condition.
ThreadsTooFew = -28
ARGON2_THREADS_TOO_FEW (-28).
ThreadsTooMany = -29
ARGON2_THREADS_TOO_MANY (-29).
MissingArgs = -30
ARGON2_MISSING_ARGS (-30). Unreachable in Rust.
EncodingFail = -31
ARGON2_ENCODING_FAIL (-31). The PHC string did not fit the output buffer.
DecodingFail = -32
ARGON2_DECODING_FAIL (-32). The PHC string is malformed.
ThreadFail = -33
ARGON2_THREAD_FAIL (-33). A worker thread could not be started or panicked.
DecodingLengthFail = -34
ARGON2_DECODING_LENGTH_FAIL (-34).
VerifyMismatch = -35
ARGON2_VERIFY_MISMATCH (-35). The password does not match the hash.
OsRandom = -100
Not a C code: every OS entropy source failed. Crate-specific (-100),
the only variant that does not come from argon2.h; it exists
because the C never generates randomness and so has no code for it.
Implementations§
Source§impl Error
impl Error
Sourcepub const MIN_C_CODE: i32 = -35
pub const MIN_C_CODE: i32 = -35
The lowest C error code (ARGON2_VERIFY_MISMATCH).
This bounds the codes that come from argon2.h, not the
discriminants of this enum: crate-specific variants such as
Error::OsRandom deliberately sit below it so they can never collide
with a present or future C code.
Sourcepub const MAX_C_CODE: i32 = -1
pub const MAX_C_CODE: i32 = -1
The highest non-OK C error code (ARGON2_OUTPUT_PTR_NULL).
Sourcepub const fn as_c_code(&self) -> i32
pub const fn as_c_code(&self) -> i32
The numeric code the C reference returns for this condition.
For the crate-specific variants (see Error::MIN_C_CODE) there is no
such C code, and this returns the crate’s own value instead.
Sourcepub const fn from_c_code(code: i32) -> Option<Error>
pub const fn from_c_code(code: i32) -> Option<Error>
Inverse of Error::as_c_code.
Returns None for ARGON2_OK (0) and for any code that is not a
discriminant of this enum, so differential tests can turn a C return
value into a Result<(), Error>.
Every C code in -35..=-1 maps, plus the crate-specific codes below
Error::MIN_C_CODE — currently only -100 (Error::OsRandom),
which the C never returns. A differential test that wants strictly
the C’s range should bound itself with
MIN_C_CODE..=MAX_C_CODE
rather than assume this function rejects everything else.
use argon2_rust::Error;
// The discriminant *is* the C code, so the pair round-trips.
assert_eq!(Error::from_c_code(-35), Some(Error::VerifyMismatch));
assert_eq!(Error::VerifyMismatch.as_c_code(), -35);
// `ARGON2_OK` is `Ok(())` here, so 0 is not a variant...
assert_eq!(Error::from_c_code(0), None);
// ...and neither is -36, the code just below the end of the C's range.
// Being below that end is not on its own enough to predict `None`,
// as the `-100` case further down shows.
assert_eq!(Error::from_c_code(Error::MIN_C_CODE - 1), None);
// The crate's own codes sit below that range and still map, which is
// the caveat above: `None` does not mean "outside the C's codes".
assert_eq!(Error::from_c_code(-100), Some(Error::OsRandom));
assert!(Error::OsRandom.as_c_code() < Error::MIN_C_CODE);Trait Implementations§
impl Copy for Error
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()