[−][src]Struct password_hash::Value
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: 48 ASCII characters (i.e. 48-bytes)
Additional Notes
The PHC spec allows for algorithm-defined maximum lengths for parameter
values, however in the interest of interoperability this library defines a
Value::max_len
of 48 ASCII characters.
Implementations
impl<'a> Value<'a>
[src]
pub const fn max_len() -> usize
[src]
Maximum length of an Value
- 48 ASCII characters (i.e. 48-bytes).
This value is selected based on the maximum value size used in the
Argon2 Encoding as described in the PHC string format specification.
Namely the data
parameter, when encoded as B64, can be up to 43
characters.
This implementation rounds that up to 48 as a safe maximum limit.
pub fn new(input: &'a str) -> Result<Self, ParseError>
[src]
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], B64Error>
[src]
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
[src]
Borrow this value as a str
.
pub fn as_bytes(&self) -> &'a [u8]
[src]
Borrow this value as bytes.
pub fn len(&self) -> usize
[src]
Get the length of this value in ASCII characters.
pub fn is_empty(&self) -> bool
[src]
Is this value empty?
pub fn decimal(&self) -> Result<Decimal, ParseError>
[src]
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
[src]
Does this value parse successfully as a decimal?
Trait Implementations
impl<'a> AsRef<str> for Value<'a>
[src]
impl<'a> Clone for Value<'a>
[src]
fn clone(&self) -> Value<'a>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<'a> Copy for Value<'a>
[src]
impl<'a> Debug for Value<'a>
[src]
impl<'a> Display for Value<'a>
[src]
impl<'a> Eq for Value<'a>
[src]
impl<'a> Hash for Value<'a>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'a> Ord for Value<'a>
[src]
fn cmp(&self, other: &Value<'a>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<'a> PartialEq<Value<'a>> for Value<'a>
[src]
impl<'a> PartialOrd<Value<'a>> for Value<'a>
[src]
fn partial_cmp(&self, other: &Value<'a>) -> Option<Ordering>
[src]
fn lt(&self, other: &Value<'a>) -> bool
[src]
fn le(&self, other: &Value<'a>) -> bool
[src]
fn gt(&self, other: &Value<'a>) -> bool
[src]
fn ge(&self, other: &Value<'a>) -> bool
[src]
impl<'a> StructuralEq for Value<'a>
[src]
impl<'a> StructuralPartialEq for Value<'a>
[src]
impl<'a> TryFrom<&'_ Value<'a>> for Decimal
[src]
type Error = ParseError
The type returned in the event of a conversion error.
fn try_from(value: &Value<'a>) -> Result<Decimal, ParseError>
[src]
impl<'a> TryFrom<&'a str> for Value<'a>
[src]
type Error = ParseError
The type returned in the event of a conversion error.
fn try_from(input: &'a str) -> Result<Self, ParseError>
[src]
impl<'a> TryFrom<Value<'a>> for Decimal
[src]
type Error = ParseError
The type returned in the event of a conversion error.
fn try_from(value: Value<'a>) -> Result<Decimal, ParseError>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,