Skip to main content

Error

Enum Error 

Source
#[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):

§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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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.

Source

pub const MAX_C_CODE: i32 = -1

The highest non-OK C error code (ARGON2_OUTPUT_PTR_NULL).

Source

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.

Source

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);
Source

pub const fn message(&self) -> &'static str

The message argon2_error_message() returns for this code, verbatim.

Kept byte-identical to src/argon2.c so differential tests can compare the strings too.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Error

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Error

Source§

impl Error for Error

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl Hash for Error

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Error

Source§

fn cmp(&self, other: &Error) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Error) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Error

Source§

fn partial_cmp(&self, other: &Error) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.