Struct bonsaidb::local::argon2::password_hash::Value
pub struct Value<'a>(/* private fields */);
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>
impl<'a> Value<'a>
pub const MAX_LENGTH: usize = 64usize
pub const MAX_LENGTH: usize = 64usize
pub fn new(input: &'a str) -> Result<Value<'a>, Error>
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>
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 decimal(&self) -> Result<u32, Error>
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
pub fn is_decimal(&self) -> bool
Does this value parse successfully as a decimal?
Trait Implementations§
§impl<'a> Ord for Value<'a>
impl<'a> Ord for Value<'a>
§impl<'a> PartialOrd for Value<'a>
impl<'a> PartialOrd for Value<'a>
§fn partial_cmp(&self, other: &Value<'a>) -> Option<Ordering>
fn partial_cmp(&self, other: &Value<'a>) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl<'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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CallHasher for T
impl<T> CallHasher for T
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.