### Get KeyId Length Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Returns the length of the KeyId in bytes. This is a constant time operation. ```rust pub const fn len(&self) -> usize ``` -------------------------------- ### Get Reference to Ok Value Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use `as_ref` to convert a `&Result` into a `Result<&T, &E>`, providing immutable references to the contained values without consuming the original Result. ```rust let x: Result = Ok(2); assert_eq!(x.as_ref(), Ok(&2)); let x: Result = Err("Error"); assert_eq!(x.as_ref(), Err(&"Error")); ``` -------------------------------- ### Get Default Block Value Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Returns the default value for a Block, which is an instance initialized with zeros. This is equivalent to calling `Block::new()`. ```rust fn default() -> Self ``` -------------------------------- ### Get Memory Block Size Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Provides the size of the memory block in bytes. This is a constant value representing 1024 bytes. ```rust pub const SIZE: usize = 1_024usize ``` -------------------------------- ### Argon2 Default Memory Cost Constant Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Defines the default memory cost for Argon2, specified in 1 KiB blocks. This is a recommended starting point for memory usage. ```rust pub const DEFAULT_M_COST: u32 = 19_456u32 ``` -------------------------------- ### Safely Get Ok Value (Never Panics) in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use into_ok for Result types where the error is uninhabitable (!). This method is guaranteed not to panic and can serve as a compile-time safeguard. ```rust fn only_good_news() -> Result { Ok("this is fine".into()) } let s: String = only_good_news().into_ok(); println!("{s}"); ``` -------------------------------- ### Unwrap Ok Value in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use unwrap to get the contained Ok value. Panics if the value is an Err, with a panic message provided by the Err's value. ```rust let x: Result = Ok(2); assert_eq!(x.unwrap(), 2); ``` -------------------------------- ### Get Mutable Reference to Ok or Err Value Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use `as_mut` to convert a `&mut Result` into a `Result<&mut T, &mut E>`, providing mutable references to the contained values. This allows in-place modification of the Result's content. ```rust fn mutate(r: &mut Result) { match r.as_mut() { Ok(v) => *v = 42, Err(e) => *e = 0, } } let mut x: Result = Ok(2); mutate(&mut x); assert_eq!(x.unwrap(), 42); let mut x: Result = Err(13); mutate(&mut x); assert_eq!(x.unwrap_err(), 0); ``` -------------------------------- ### Argon2 Initialization Methods Source: https://docs.rs/argon2/latest/argon2/struct.Argon2.html Constructors for creating an Argon2 context, with or without a secret key. ```rust pub fn new(algorithm: Algorithm, version: Version, params: Params) -> Self ``` ```rust pub fn new_with_secret( secret: &'key [u8], algorithm: Algorithm, version: Version, params: Params, ) -> Result ``` -------------------------------- ### Get Block's Own Type Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Specifies that the `Output` type for the `Same` trait is the type itself. This is part of a blanket implementation. ```rust type Output = T ``` -------------------------------- ### Argon2 Initialization Source: https://docs.rs/argon2/latest/argon2/struct.Argon2.html Methods for creating a new Argon2 context with optional secret keys. ```APIDOC ## Argon2::new ### Description Create a new Argon2 context with specified algorithm, version, and parameters. ### Method Constructor ### Parameters - **algorithm** (Algorithm) - Required - The Argon2 algorithm variant. - **version** (Version) - Required - The Argon2 version. - **params** (Params) - Required - The default set of parameters. ## Argon2::new_with_secret ### Description Create a new Argon2 context with an optional secret key (pepper). ### Parameters - **secret** (&[u8]) - Required - The secret key. - **algorithm** (Algorithm) - Required - The Argon2 algorithm variant. - **version** (Version) - Required - The Argon2 version. - **params** (Params) - Required - The default set of parameters. ``` -------------------------------- ### Generic CloneToUninit Implementation for KeyId Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Shows the nightly-only experimental implementation of `CloneToUninit` for types that implement `Clone`, applicable to KeyId. ```rust impl CloneToUninit for T where T: Clone, ``` ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Type ID Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Retrieves the `TypeId` of the Block. This is part of the `Any` trait implementation and is useful for dynamic type checking. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Generic Borrow and BorrowMut Implementations for KeyId Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Demonstrates the generic implementations of `Borrow` and `BorrowMut` traits, which are applicable to KeyId. ```rust impl Borrow for T where T: ?Sized, ``` ```rust fn borrow(&self) -> &T ``` ```rust impl BorrowMut for T where T: ?Sized, ``` ```rust fn borrow_mut(&mut self) -> &mut T ``` -------------------------------- ### Create New ParamsBuilder Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Initializes a new ParamsBuilder with the default Argon2 parameters. ```rust pub const fn new() -> Self ``` -------------------------------- ### Argon2 Get Block Count Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Calculates and returns the total number of memory blocks required for Argon2 based on the configured `m_cost` and `p_cost`. ```rust pub const fn block_count(&self) -> usize ``` -------------------------------- ### into_ok() - Unfailing Ok Extraction (Nightly) Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the contained `Ok` value. This method is guaranteed not to panic and can be used as a compile-time safeguard. ```APIDOC ## GET /api/products ### Description Retrieves a list of all available products. ### Method GET ### Endpoint /api/products ### Parameters #### Query Parameters - **category** (string) - Optional - Filter products by category. - **sort_by** (string) - Optional - Field to sort the products by (e.g., 'price', 'name'). - **order** (string) - Optional - Sort order ('asc' or 'desc'). Defaults to 'asc'. ### Response #### Success Response (200) - **products** (array) - An array of product objects. - **product_id** (string) - Unique identifier for the product. - **name** (string) - Name of the product. - **price** (number) - Price of the product. - **category** (string) - Category the product belongs to. #### Response Example ```json { "products": [ { "product_id": "prod_001", "name": "Laptop", "price": 1200.00, "category": "Electronics" }, { "product_id": "prod_002", "name": "Desk Chair", "price": 250.50, "category": "Furniture" } ] } ``` ``` -------------------------------- ### Generic CloneToUninit Implementation (Nightly) Source: https://docs.rs/argon2/latest/argon2/enum.Version.html An experimental, nightly-only implementation of `CloneToUninit`. This trait allows cloning a value into uninitialized memory. ```rust impl CloneToUninit for T where T: Clone, { unsafe fn clone_to_uninit(&self, dest: *mut u8) } ``` -------------------------------- ### Argon2 Get Output Length Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the configured output length (digest size in bytes) for Argon2, if specified. Defaults to 32 bytes. ```rust pub const fn output_len(&self) -> Option ``` -------------------------------- ### Generic From for T Implementation Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Illustrates the generic `From` for `T` implementation, which is a standard identity conversion. ```rust impl From for T ``` -------------------------------- ### Argon2 Get Parallelism Cost Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the degree of parallelism (number of threads) configured for Argon2. The value must be between 1 and (2^24)-1. ```rust pub const fn p_cost(&self) -> u32 ``` -------------------------------- ### Argon2 Get Time Cost Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the number of iterations (time cost) configured for Argon2. The value must be between 1 and (2^32)-1. ```rust pub const fn t_cost(&self) -> u32 ``` -------------------------------- ### Recommended expect Message Style in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Provides guidance on crafting effective `expect` messages, focusing on why the `Result` *should* be `Ok`. This improves debugging by clearly stating the expected condition. ```rust let path = std::env::var("IMPORTANT_PATH") .expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`"); ``` -------------------------------- ### Blanket Implementations Source: https://docs.rs/argon2/latest/argon2/struct.PasswordHash.html Demonstrates blanket implementations provided by the Rust standard library and potentially extended by the Argon2 crate for generic types. ```APIDOC ## Blanket Implementations ### impl Any for T where T: 'static + ?Sized, #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ### impl Borrow for T where T: ?Sized, #### fn borrow(&self) -> &T Immutably borrows from an owned value. ### impl BorrowMut for T where T: ?Sized, #### fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. ### impl CloneToUninit for T where T: Clone, #### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ### impl From for T #### fn from(t: T) -> T Returns the argument unchanged. ### impl Into for T where U: From, #### fn into(self) -> U Calls `U::from(self)`. ### impl Same for T #### type Output = T Should always be `Self`. ### impl ToOwned for T where T: Clone, #### type Owned = T The resulting type after obtaining ownership. #### fn to_owned(&self) -> T Creates owned data from borrowed data, usually by cloning. #### fn clone_into(&self, target: &mut T) Uses borrowed data to replace owned data, usually by cloning. ### impl ToString for T where T: Display + ?Sized, #### fn to_string(&self) -> String Converts the given value to a `String`. ### impl TryFrom for T where U: Into, #### type Error = Infallible The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> Performs the conversion. ### impl TryInto for T where U: TryFrom, #### type Error = >::Error The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Argon2 Get Memory Cost Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the memory size in kibibytes configured for Argon2. The value must be between 8*`p_cost` and (2^32)-1. ```rust pub const fn m_cost(&self) -> u32 ``` -------------------------------- ### Argon2 Get Associated Data Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the associated data as a byte slice. This field is not part of the current Argon2 standard and should not be used for non-legacy work. ```rust pub fn data(&self) -> &[u8] ``` -------------------------------- ### Argon2 New Parameters Constructor Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Creates new Argon2 parameters with specified memory cost, time cost, parallelism, and optional output length. Ensure values are within the defined constraints. ```rust pub const fn new( m_cost: u32, t_cost: u32, p_cost: u32, output_len: Option, ) -> Result ``` -------------------------------- ### CloneToUninit Trait Source: https://docs.rs/argon2/latest/argon2/struct.AssociatedData.html The `CloneToUninit` trait allows for copy-assignment from self to an uninitialized memory location. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Endpoint N/A (Trait method) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response N/A ### Error Handling N/A ``` -------------------------------- ### Get Immutable Slice of Block Data Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Converts the Block into an immutable slice of 64-bit unsigned integers. This provides read-only access to the block's data. ```rust fn as_ref(&self) -> &[u64] ``` -------------------------------- ### expect Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the contained Ok value, or panics if the result is Err. ```APIDOC ## expect(self, msg: &str) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err` with the provided message. ### Parameters - **msg** (&str) - Required - The message to include in the panic if the result is an error. ``` -------------------------------- ### Get Mutable Slice of Block Data Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Converts the Block into a mutable slice of 64-bit unsigned integers. This allows in-place modification of the block's data. ```rust fn as_mut(&mut self) -> &mut [u64] ``` -------------------------------- ### fn product Source: https://docs.rs/argon2/latest/argon2/type.Result.html Calculates the product of all elements in an iterator of Results, short-circuiting on the first Err encountered. ```APIDOC ## fn product ### Description Takes each element in the Iterator: if it is an Err, no further elements are taken, and the Err is returned. Should no Err occur, the product of all elements is returned. ### Parameters #### Path Parameters - **iter** (Iterator>) - Required - The iterator containing Result values to multiply. ### Response #### Success Response (200) - **Result** - The product of all elements if all are Ok, otherwise the first Err encountered. ``` -------------------------------- ### Clone to Uninitialized Memory (Nightly) Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Nightly-only experimental API to clone the Block's data into uninitialized memory. Use with caution as it is unsafe. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Create New Zero-Initialized Block Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Returns a new Block instance initialized with zeros. This is the default state for a memory block. ```rust pub fn new() -> Self ``` -------------------------------- ### Create Argon2 Context Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Generates a new `Argon2` context using the specified algorithm and version, based on the current builder configuration. ```rust pub fn context( &self, algorithm: Algorithm, version: Version, ) -> Result> ``` -------------------------------- ### Safely Get Err Value (Never Panics) in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use into_err for Result types where the success value is uninhabitable (!). This method is guaranteed not to panic and can serve as a compile-time safeguard. ```rust fn only_bad_news() -> Result { Err("Oops, it failed".into()) } let error: String = only_bad_news().into_err(); println!("{error}"); ``` -------------------------------- ### Generic TryFrom for T Implementation Source: https://docs.rs/argon2/latest/argon2/enum.Version.html A blanket implementation of `TryFrom` for `T` where `U` implements `Into`. This provides a fallible conversion mechanism. ```rust impl TryFrom for T where U: Into, { type Error = Infallible; } ``` -------------------------------- ### Unwrap Error Value in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use unwrap_err to get the contained Err value. Panics if the value is an Ok, with a custom panic message provided by the Ok's value. ```rust let x: Result = Err("emergency failure"); assert_eq!(x.unwrap_err(), "emergency failure"); ``` -------------------------------- ### Block Implementations Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Core implementations for the Block struct, including new block creation. ```APIDOC ### impl Block #### `new()` ```rust pub fn new() -> Self ``` Returns a Block initialized with zeros. ``` -------------------------------- ### Argon2 Get Key ID Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Retrieves the key identifier as a byte slice. This field is for PHC string format compatibility and is cryptographically ignored. It is not part of the current Argon2 standard. ```rust pub fn keyid(&self) -> &[u8] ``` -------------------------------- ### KeyId Methods Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Methods available for the KeyId struct. ```APIDOC ## Methods ### `new` ```rust pub fn new(slice: &[u8]) -> Result ``` Create a new KeyId from a slice. ### `from_b64` ```rust pub fn from_b64(s: &str) -> Result ``` Decode KeyId from a B64 string. ### `as_bytes` ```rust pub fn as_bytes(&self) -> &[u8] ``` Borrow the inner value as a byte slice. ### `len` ```rust pub const fn len(&self) -> usize ``` Get the length in bytes. ### `is_empty` ```rust pub const fn is_empty(&self) -> bool ``` Is this value empty? ``` -------------------------------- ### Unwrap or Default Value in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use unwrap_or_default to get the contained Ok value or a default value if the Result is Err. This is useful for providing fallback values when parsing or converting data. ```rust let good_year_from_input = "1909"; let bad_year_from_input = "190blarg"; let good_year = good_year_from_input.parse().unwrap_or_default(); let bad_year = bad_year_from_input.parse().unwrap_or_default(); assert_eq!(1909, good_year); assert_eq!(0, bad_year); ``` -------------------------------- ### Trait Implementations for Version Source: https://docs.rs/argon2/latest/argon2/enum.Version.html Details the trait implementations for the Version enum, including Clone, Debug, Default, From for u32, Ord, PartialEq, PartialOrd, and TryFrom for Version. ```APIDOC ## Trait Implementations ### impl Clone for Version #### fn clone(&self) -> Version Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ### impl Debug for Version #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Default for Version #### fn default() -> Version Returns the “default value” for a type. ### impl From for u32 #### fn from(version: Version) -> u32 Converts to this type from the input type. ### impl Ord for Version #### fn cmp(&self, other: &Version) -> Ordering This method returns an `Ordering` between `self` and `other`. #### fn max(self, other: Self) -> Self Compares and returns the maximum of two values. #### fn min(self, other: Self) -> Self Compares and returns the minimum of two values. #### fn clamp(self, min: Self, max: Self) -> Self Restrict a value to a certain interval. ### impl PartialEq for Version #### fn eq(&self, other: &Version) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. #### fn ne(&self, other: &Rhs) -> bool Tests for `!=`. ### impl PartialOrd for Version #### fn partial_cmp(&self, other: &Version) -> Option This method returns an ordering between `self` and `other` values if one exists. #### fn lt(&self, other: &Rhs) -> bool Tests less than (for `self` and `other`) and is used by the `<` operator. #### fn le(&self, other: &Rhs) -> bool Tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. #### fn gt(&self, other: &Rhs) -> bool Tests greater than (for `self` and `other`) and is used by the `>` operator. #### fn ge(&self, other: &Rhs) -> bool Tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. ### impl TryFrom for Version #### type Error = Error The type returned in the event of a conversion error. #### fn try_from(version_id: u32) -> Result Performs the conversion. ### impl Copy for Version ### impl Eq for Version ### impl StructuralPartialEq for Version ``` -------------------------------- ### Expect Error Value and Panic with Message in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use expect_err to get the contained Err value. Panics if the value is an Ok, with a message including the provided string and the Ok's content. ```rust let x: Result = Ok(10); x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10` ``` -------------------------------- ### Provide default value with unwrap_or Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the contained Ok value or a provided default. Arguments are evaluated eagerly. ```rust let default = 2; let x: Result = Ok(9); assert_eq!(x.unwrap_or(default), 9); let x: Result = Err("error"); assert_eq!(x.unwrap_or(default), default); ``` -------------------------------- ### unwrap Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the contained Ok value, or panics if the result is Err. ```APIDOC ## unwrap(self) -> T ### Description Returns the contained `Ok` value, consuming the `self` value. Panics if the value is an `Err`. ``` -------------------------------- ### Mutably Dereference Result in Rust Source: https://docs.rs/argon2/latest/argon2/type.Result.html Shows `as_deref_mut` for converting `&mut Result` to `Result<&mut ::Target, &mut E>`, enabling mutable borrowing of the inner value. The example modifies the string in place. ```rust let mut s = "HELLO".to_string(); let mut x: Result = Ok("hello".to_string()); let y: Result<&mut str, &mut u32> = Ok(&mut s); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); let mut i = 42; let mut x: Result = Err(42); let y: Result<&mut str, &mut u32> = Err(&mut i); assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y); ``` -------------------------------- ### Default ParamsBuilder Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Provides the default parameters for Argon2, which are recommended for general use. ```rust pub const DEFAULT: ParamsBuilder ``` -------------------------------- ### TryFrom Implementations for Params Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Conversions for the Params structure using the TryFrom trait. ```APIDOC ## TryFrom<&'a PasswordHash<'a>> for Params ### Description Converts a PasswordHash reference into a Params structure. Requires the `password-hash` crate feature. ### Method try_from ### Parameters #### Request Body - **hash** (&'a PasswordHash<'a>) - Required - The password hash to convert. ## TryFrom for ParamsString ### Description Converts a Params structure into a ParamsString. Requires the `password-hash` crate feature. ### Method try_from ### Parameters #### Request Body - **params** (Params) - Required - The parameters to convert. ## TryFrom for Params ### Description Converts a ParamsBuilder into a Params structure. ### Method try_from ### Parameters #### Request Body - **builder** (ParamsBuilder) - Required - The builder instance to convert. ``` -------------------------------- ### Convert Result to Option with Ok Value Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use `ok` to convert a `Result` into an `Option`, consuming the Result and discarding any error value. This is useful when you only care about the success value. ```rust let x: Result = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result = Err("Nothing here"); assert_eq!(x.ok(), None); ``` -------------------------------- ### Argon2 Default Parameters Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Provides the default Argon2 parameters, which are recommended for general use. These defaults balance security and performance. ```rust pub const DEFAULT: Self ``` -------------------------------- ### KeyId Copy and Eq Implementations Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Implements the `Copy` and `Eq` traits for KeyId, indicating that KeyId values can be copied and are guaranteed to be totally equatable. ```rust impl Copy for KeyId ``` ```rust impl Eq for KeyId ``` -------------------------------- ### RECOMMENDED_SALT_LEN Constant Source: https://docs.rs/argon2/latest/argon2/constant.RECOMMENDED_SALT_LEN.html Provides the recommended salt length in bytes for secure password hashing. ```APIDOC ## RECOMMENDED_SALT_LEN ### Description Recommended salt length for password hashing in bytes. ### Value 16 (usize) ``` -------------------------------- ### Build Argon2 Params Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Finalizes the configuration by building the `Params` struct. This method performs validation checks and returns a `Result`. ```rust pub const fn build(&self) -> Result ``` -------------------------------- ### Map Ok Value or Return Default (Experimental) Source: https://docs.rs/argon2/latest/argon2/type.Result.html Use `map_or_default` to apply a function to the `Ok` value or return the default value of the return type if the Result is `Err`. This is an experimental API. ```rust #![feature(result_option_map_or_default)] let x: Result<_, &str> = Ok("foo"); let y: Result<&str, _> = Err("bar"); assert_eq!(x.map_or_default(|x| x.len()), 3); assert_eq!(y.map_or_default(|y| y.len()), 0); ``` -------------------------------- ### PasswordHash Methods Source: https://docs.rs/argon2/latest/argon2/struct.PasswordHash.html Methods for parsing, generating, and verifying password hashes. ```APIDOC ## PasswordHash Methods ### new(s: &'a str) -> Result, Error> Parses a password hash from a string in the PHC string format. ### parse(s: &'a str, encoding: Encoding) -> Result, Error> Parses a password hash from the given Encoding. ### generate(phf: impl PasswordHasher, password: impl AsRef<[u8]>, salt: impl Into>) -> Result, Error> Generates a password hash using the supplied algorithm. ### verify_password(&self, phfs: &[&dyn PasswordVerifier], password: impl AsRef<[u8]>) -> Result<(), Error> Verifies this password hash using the specified set of supported PasswordHasher trait objects. ### serialize(&self) -> PasswordHashString Serializes this PasswordHash as a PasswordHashString. ``` -------------------------------- ### Return alternative Result with or Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the provided Result if the current one is Err, otherwise returns the Ok value. Arguments are evaluated eagerly. ```rust let x: Result = Ok(2); let y: Result = Err("late error"); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("early error"); let y: Result = Ok(2); assert_eq!(x.or(y), Ok(2)); let x: Result = Err("not a 2"); let y: Result = Err("late error"); assert_eq!(x.or(y), Err("late error")); let x: Result = Ok(2); let y: Result = Ok(100); assert_eq!(x.or(y), Ok(2)); ``` -------------------------------- ### Argon2 Params From for Argon2<'key> Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Implements the `From` trait to convert owned Argon2 `Params` into an `Argon2` hasher instance. This consumes the parameters. ```rust fn from(params: Params) -> Self ``` -------------------------------- ### Set Memory Cost (m_cost) Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Configures the memory size for Argon2, expressed in kibibytes. The value must be between 8 times the parallelism cost and (2^32)-1. ```rust pub fn m_cost(&mut self, m_cost: u32) -> &mut Self ``` -------------------------------- ### unwrap() - Extracting Ok Value Source: https://docs.rs/argon2/latest/argon2/type.Result.html Retrieves the contained `Ok` value. Panics if the `Result` is an `Err`. ```APIDOC ## GET /api/users ### Description Retrieves the contained `Ok` value. Panics if the `Result` is an `Err`. ### Method GET ### Endpoint /api/users ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user to retrieve. #### Query Parameters - **include_details** (boolean) - Optional - Whether to include detailed user information. ### Request Example ```json { "query": { "include_details": true } } ``` ### Response #### Success Response (200) - **user_id** (string) - The unique identifier for the user. - **username** (string) - The user's chosen username. - **email** (string) - The user's email address. #### Response Example ```json { "user_id": "123e4567-e89b-12d3-a456-426614174000", "username": "johndoe", "email": "johndoe@example.com" } ``` ``` -------------------------------- ### and() - Chaining Results Source: https://docs.rs/argon2/latest/argon2/type.Result.html Returns the second `Result` if the first is `Ok`, otherwise returns the `Err` of the first. Arguments are eagerly evaluated. ```APIDOC ## PUT /api/products/{product_id} ### Description Updates an existing product's details. ### Method PUT ### Endpoint /api/products/{product_id} ### Parameters #### Path Parameters - **product_id** (string) - Required - The ID of the product to update. #### Request Body - **name** (string) - Optional - Updated product name. - **price** (number) - Optional - Updated product price. - **category** (string) - Optional - Updated product category. ### Request Example ```json { "price": 22.50 } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message. #### Response Example ```json { "message": "Product updated successfully." } ``` ``` -------------------------------- ### ParamsBuilder API Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html This section details the methods available on the ParamsBuilder struct for configuring Argon2 hashing parameters. ```APIDOC ## Struct ParamsBuilder ### Description Builder for Argon2 `Params`. ### Methods #### `DEFAULT` Default parameters (recommended). #### `new()` Create a new builder with the default parameters. #### `m_cost(m_cost: u32)` Set memory size, expressed in kibibytes, between 8*`p_cost` and (2^32)-1. #### `t_cost(t_cost: u32)` Set number of iterations, between 1 and (2^32)-1. #### `p_cost(p_cost: u32)` Set degree of parallelism, between 1 and (2^24)-1. #### `keyid(keyid: KeyId)` Set key identifier. #### `data(data: AssociatedData)` Set associated data. #### `output_len(len: usize)` Set length of the output (in bytes). #### `build() -> Result` Get the finished `Params`. This performs validations to ensure that the given parameters are valid and compatible with each other, and will return an error if they are not. #### `context(algorithm: Algorithm, version: Version) -> Result>` Create a new `Argon2` context using the provided algorithm/version. ``` -------------------------------- ### Argon2 Params Methods Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Methods available for the Params struct, including creation, getters, and trait implementations. ```APIDOC ### impl Params #### Constructor - **`DEFAULT`**: `Self` - Returns the default parameters (recommended). - **`new(m_cost: u32, t_cost: u32, p_cost: u32, output_len: Option) -> Result`** - Creates new parameters. - Arguments: - `m_cost`: memory size in 1 KiB blocks. Between 8*`p_cost` and (2^32)-1. - `t_cost`: number of iterations. Between 1 and (2^32)-1. - `p_cost`: degree of parallelism. Between 1 and (2^24)-1. - `output_len`: size of the KDF output in bytes. Default 32. #### Getters - **`m_cost(&self) -> u32`**: Returns the memory size in kibibytes. Between 8*`p_cost` and (2^32)-1. - **`t_cost(&self) -> u32`**: Returns the number of iterations. Between 1 and (2^32)-1. - **`p_cost(&self) -> u32`**: Returns the degree of parallelism. Between 1 and (2^24)-1. - **`keyid(&self) -> &[u8]`**: Returns the key identifier (byte slice between 0 and 8 bytes). Defaults to an empty byte slice. Note: This field is for legacy PHC string format and not part of the current Argon2 standard. - **`data(&self) -> &[u8]`**: Returns the associated data (byte slice between 0 and 32 bytes). Defaults to an empty byte slice. Note: This field is not part of the current Argon2 standard. - **`output_len(&self) -> Option`**: Returns the length of the output in bytes. - **`block_count(&self) -> usize`**: Returns the number of blocks required given the configured `m_cost` and `p_cost`. ### Trait Implementations - **`Clone`**: Allows cloning `Params` instances. - **`Debug`**: Allows formatting `Params` for debugging. - **`Default`**: Provides a default `Params` instance. - **`From<&Params> for Argon2<'key>`**: Converts `Params` to `Argon2`. - **`From for Argon2<'key>`**: Converts `Params` to `Argon2`. - **`PartialEq`**: Allows comparing `Params` instances for equality. - **`TryFrom<&Params> for ParamsString`** (requires `password-hash` feature): Converts `Params` to `ParamsString`. ``` -------------------------------- ### KeyId PartialOrd Implementation Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Implements the `PartialOrd` trait for KeyId, enabling partial ordering comparisons between KeyId values. Includes methods for `partial_cmp`, `lt`, `le`, `gt`, and `ge`. ```rust fn partial_cmp(&self, other: &KeyId) -> Option ``` ```rust fn lt(&self, other: &Rhs) -> bool ``` ```rust fn le(&self, other: &Rhs) -> bool ``` ```rust fn gt(&self, other: &Rhs) -> bool ``` ```rust fn ge(&self, other: &Rhs) -> bool ``` -------------------------------- ### KeyId PartialEq Implementation Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Implements the `PartialEq` trait for KeyId, allowing equality checks between KeyId values. ```rust fn eq(&self, other: &KeyId) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### try_from Function Source: https://docs.rs/argon2/latest/argon2/enum.Version.html The core function for attempting a conversion from one type to another, returning a Result. ```APIDOC #### fn try_from(value: U) -> Result>::Error> ### Description This function attempts to create an instance of type `T` from a given value of type `U`. It returns a `Result` which is either `Ok(T)` if the conversion is successful or `Err(>::Error)` if the conversion fails. ### Method `try_from` ### Endpoint N/A (This is a function within an `impl` block, not an API endpoint) ### Parameters - **value** (U) - Required - The value of type `U` to convert from. ### Request Body N/A ### Response - **Result>::Error>** - A `Result` containing either the successfully converted value of type `T` or an error. ### Response Example ```json { "success": true, "value": "converted_value_of_T" } ``` ### Error Handling - **Conversion Error**: If the conversion from `U` to `T` is not possible, an error of type `>::Error` is returned. ``` -------------------------------- ### Create KeyId from Slice Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Creates a new KeyId from a byte slice. This function returns a Result, indicating potential errors during creation. ```rust pub fn new(slice: &[u8]) -> Result ``` -------------------------------- ### KeyId Trait Implementations Source: https://docs.rs/argon2/latest/argon2/struct.KeyId.html Implementations of various traits for the KeyId struct. ```APIDOC ## Trait Implementations ### `AsRef<[u8]>` #### `as_ref` ```rust fn as_ref(&self) -> &[u8] ``` Converts this type into a shared reference of the (usually inferred) input type. ### `Clone` #### `clone` ```rust fn clone(&self) -> KeyId ``` Returns a duplicate of the value. #### `clone_from` ```rust fn clone_from(&mut self, source: &Self) ``` Performs copy-assignment from `source`. ### `Debug` #### `fmt` ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` Formats the value using the given formatter. ### `Default` #### `default` ```rust fn default() -> KeyId ``` Returns the “default value” for a type. ### `FromStr` #### `Err` ```rust type Err = Error ``` The associated error which can be returned from parsing. #### `from_str` ```rust fn from_str(s: &str) -> Result ``` Parses a string `s` to return a value of this type. ### `Hash` #### `hash` ```rust fn hash<__H: Hasher>(&self, state: &mut __H) ``` Feeds this value into the given `Hasher`. #### `hash_slice` ```rust fn hash_slice(data: &[Self], state: &mut H) where H: Hasher, Self: Sized, ``` Feeds a slice of this type into the given `Hasher`. ### `Ord` #### `cmp` ```rust fn cmp(&self, other: &KeyId) -> Ordering ``` This method returns an `Ordering` between `self` and `other`. #### `max` ```rust fn max(self, other: Self) -> Self where Self: Sized, ``` Compares and returns the maximum of two values. #### `min` ```rust fn min(self, other: Self) -> Self where Self: Sized, ``` Compares and returns the minimum of two values. #### `clamp` ```rust fn clamp(self, min: Self, max: Self) -> Self where Self: Sized, ``` Restrict a value to a certain interval. ### `PartialEq` #### `eq` ```rust fn eq(&self, other: &KeyId) -> bool ``` Tests for `self` and `other` values to be equal, and is used by `==`. #### `ne` ```rust fn ne(&self, other: &Rhs) -> bool ``` Tests for `!=`. ### `PartialOrd` #### `partial_cmp` ```rust fn partial_cmp(&self, other: &KeyId) -> Option ``` This method returns an ordering between `self` and `other` values if one exists. #### `lt` ```rust fn lt(&self, other: &Rhs) -> bool ``` Tests less than (for `self` and `other`) and is used by the `<` operator. #### `le` ```rust fn le(&self, other: &Rhs) -> bool ``` Tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. #### `gt` ```rust fn gt(&self, other: &Rhs) -> bool ``` Tests greater than (for `self` and `other`) and is used by the `>` operator. #### `ge` ```rust fn ge(&self, other: &Rhs) -> bool ``` Tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. ### `TryFrom<&[u8]>` #### `Error` ```rust type Error = Error ``` The type returned in the event of a conversion error. #### `try_from` ```rust fn try_from(bytes: &[u8]) -> Result ``` Performs the conversion. ### `Copy` ### `Eq` ### `StructuralPartialEq` ``` -------------------------------- ### ParamsBuilder Implementations Source: https://docs.rs/argon2/latest/argon2/struct.ParamsBuilder.html Details on trait implementations for the ParamsBuilder struct. ```APIDOC ### Trait Implementations for ParamsBuilder #### `impl Clone for ParamsBuilder` - `clone(&self) -> ParamsBuilder`: Returns a duplicate of the value. - `clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. #### `impl Debug for ParamsBuilder` - `fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. #### `impl Default for ParamsBuilder` - `default() -> Self`: Returns the “default value” for a type. #### `impl PartialEq for ParamsBuilder` - `eq(&self, other: &ParamsBuilder) -> bool`: Tests for `self` and `other` values to be equal. - `ne(&self, other: &Rhs) -> bool`: Tests for `!=`. #### `impl TryFrom for Params` - `type Error = Error` - `try_from(builder: ParamsBuilder) -> Result`: Performs the conversion. #### `impl Eq for ParamsBuilder` #### `impl StructuralPartialEq for ParamsBuilder` ``` -------------------------------- ### Argon2 Params From<&Params> for Argon2<'key> Source: https://docs.rs/argon2/latest/argon2/struct.Params.html Implements the `From` trait to convert Argon2 `Params` into an `Argon2` hasher instance. This allows using custom parameters for hashing. ```rust fn from(params: &Params) -> Self ``` -------------------------------- ### Conversion Traits Implementation Source: https://docs.rs/argon2/latest/argon2/enum.Error.html Details regarding the conversion traits implemented for Argon2 types. ```APIDOC ## Trait Implementations ### ToString - **fn to_string(&self) -> String**: Converts the given value to a `String`. ### TryFrom - **type Error = Infallible**: The type returned in the event of a conversion error. - **fn try_from(value: U) -> Result>::Error>**: Performs the conversion. ### TryInto - **type Error = >::Error**: The type returned in the event of a conversion error. - **fn try_into(self) -> Result>::Error>**: Performs the conversion. ``` -------------------------------- ### Verify Password Functionality Source: https://docs.rs/argon2/latest/argon2/trait.PasswordVerifier.html The `verify_password` method computes the password hash using the provided password and parameters from the hash, then compares the result. This is the core function for checking if a given password matches a stored hash. ```rust fn verify_password( &self, password: &[u8], hash: &PasswordHash<'_>, ) -> Result<(), Error> ``` -------------------------------- ### Argon2 Version PartialEq Implementation Source: https://docs.rs/argon2/latest/argon2/enum.Version.html Enables the `PartialEq` trait for the `Version` enum, allowing instances to be compared for equality. ```rust impl PartialEq for Version { fn eq(&self, other: &Version) -> bool } ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Password Hashing Methods Source: https://docs.rs/argon2/latest/argon2/struct.Argon2.html Methods for hashing passwords into output buffers, including variants for explicit memory management. ```rust pub fn hash_password_into( &self, pwd: &[u8], salt: &[u8], out: &mut [u8], ) -> Result<()> ``` ```rust pub fn hash_password_into_with_memory( &self, pwd: &[u8], salt: &[u8], out: &mut [u8], memory_blocks: impl AsMut<[Block]>, ) -> Result<()> ``` -------------------------------- ### Block Struct Source: https://docs.rs/argon2/latest/argon2/struct.Block.html Details about the Block struct, its purpose, and its size. ```APIDOC ## Struct Block ### Summary ```rust pub struct Block(/* private fields */); ``` ### Description Structure for the (1 KiB) memory block implemented as 128 64-bit words. ### Constants #### `SIZE` ```rust pub const SIZE: usize = 1_024usize ``` Memory block size in bytes. ``` -------------------------------- ### Parameter Accessor Source: https://docs.rs/argon2/latest/argon2/struct.Argon2.html Retrieves the default configured parameters for the Argon2 instance. ```rust pub const fn params(&self) -> &Params ``` -------------------------------- ### Result Conversion Methods Source: https://docs.rs/argon2/latest/argon2/type.Result.html Methods for converting Result types into Option types or references. ```APIDOC ## pub fn ok(self) -> Option ### Description Converts from Result to Option, consuming self and discarding the error. ### Response - **Option** - The success value if Ok, otherwise None. ## pub fn err(self) -> Option ### Description Converts from Result to Option, consuming self and discarding the success value. ### Response - **Option** - The error value if Err, otherwise None. ```