pub struct Value<'a>(_);
Expand description

Algorithm parameter value string.

Parameter values are defined in the PHC string format specification.

Constraints

  • ASCII-encoded string consisting of the characters [a-zA-Z0-9/+.-] (lowercase letters, digits, and the minus sign)
  • Minimum length: 0 (i.e. empty values are allowed)
  • Maximum length: 64 ASCII characters (i.e. 64-bytes)

Additional Notes

The PHC spec allows for algorithm-defined maximum lengths for parameter values, however this library defines a Value::MAX_LENGTH of 64 ASCII characters.

Implementations§

§

impl<'a> Value<'a>

pub const MAX_LENGTH: usize = 64usize

Maximum length of an Value - 64 ASCII characters (i.e. 64-bytes).

This value is selected to match the maximum length of a Salt as this library internally uses this type to represent salts.

pub fn new(input: &'a str) -> Result<Value<'a>, Error>

Parse a Value from the provided str, validating it according to the PHC string format’s rules.

pub fn b64_decode<'b>(&self, buf: &'b mut [u8]) -> Result<&'b [u8], Error>

Attempt to decode a B64-encoded Value, writing the decoded result into the provided buffer, and returning a slice of the buffer containing the decoded result on success.

Examples of “B64”-encoded parameters in practice are the keyid and data parameters used by the Argon2 Encoding as described in the PHC string format specification.

pub fn as_str(&self) -> &'a str

Borrow this value as a str.

pub fn as_bytes(&self) -> &'a [u8]

Borrow this value as bytes.

pub fn len(&self) -> usize

Get the length of this value in ASCII characters.

pub fn is_empty(&self) -> bool

Is this value empty?

pub fn decimal(&self) -> Result<u32, Error>

Attempt to parse this Value as a PHC-encoded decimal (i.e. integer).

Decimal values are integers which follow the rules given in the “Decimal Encoding” section of the PHC string format specification.

The decimal encoding rules are as follows:

For an integer value x, its decimal encoding consist in the following:

  • If x < 0, then its decimal encoding is the minus sign - followed by the decimal encoding of -x.
  • If x = 0, then its decimal encoding is the single character 0.
  • If x > 0, then its decimal encoding is the smallest sequence of ASCII digits that matches its value (i.e. there is no leading zero).

Thus, a value is a valid decimal for an integer x if and only if all of the following hold true:

  • The first character is either a - sign, or an ASCII digit.
  • All characters other than the first are ASCII digits.
  • If the first character is - sign, then there is at least another character, and the second character is not a 0.
  • If the string consists in more than one character, then the first one cannot be a 0.

Note: this implementation does not support negative decimals despite them being allowed per the spec above. If you need to parse a negative number, please parse it from the string representation directly e.g. value.as_str().parse::<i32>()

pub fn is_decimal(&self) -> bool

Does this value parse successfully as a decimal?

Trait Implementations§

§

impl<'a> AsRef<str> for Value<'a>

§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
§

impl<'a> Clone for Value<'a>

§

fn clone(&self) -> Value<'a>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl<'a> Debug for Value<'a>

§

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

Formats the value using the given formatter. Read more
§

impl<'a> Display for Value<'a>

§

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

Formats the value using the given formatter. Read more
§

impl<'a> Hash for Value<'a>

§

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

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
§

impl<'a> Ord for Value<'a>

§

fn cmp(&self, other: &Value<'a>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
§

impl<'a> PartialEq<Value<'a>> for Value<'a>

§

fn eq(&self, other: &Value<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> PartialOrd<Value<'a>> for Value<'a>

§

fn partial_cmp(&self, other: &Value<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

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

impl<'a> TryFrom<&'a str> for Value<'a>

§

type Error = Error

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

fn try_from(input: &'a str) -> Result<Value<'a>, Error>

Performs the conversion.
§

impl<'a> TryFrom<&Value<'a>> for u32

§

type Error = Error

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

fn try_from(value: &Value<'a>) -> Result<u32, Error>

Performs the conversion.
§

impl<'a> TryFrom<Value<'a>> for u32

§

type Error = Error

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

fn try_from(value: Value<'a>) -> Result<u32, Error>

Performs the conversion.
§

impl<'a> Copy for Value<'a>

§

impl<'a> Eq for Value<'a>

§

impl<'a> StructuralEq for Value<'a>

§

impl<'a> StructuralPartialEq for Value<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Value<'a>

§

impl<'a> Send for Value<'a>

§

impl<'a> Sync for Value<'a>

§

impl<'a> Unpin for Value<'a>

§

impl<'a> UnwindSafe for Value<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsOut<T> for Twhere T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

§

impl<Q, K> Comparable<K> for Qwhere Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more