### Index Key from Start Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/shorthash/siphash24/struct.Key.html Allows accessing the byte contents of a Key as a slice starting from a specific index. Use with caution to avoid timing attacks. ```rust fn index(&self, _index: RangeFrom) -> &[u8] ``` ```rust type Output = [u8] ``` -------------------------------- ### Streaming Authentication with State Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/index.html This example demonstrates authenticating data in parts using a streaming interface. It's useful for large data or when data arrives in chunks. Ensure the key is securely generated. ```rust use sodiumoxide::crypto::auth; use sodiumoxide::randombytes; let key = randombytes::randombytes(123); let data_part_1 = b"some data"; let data_part_2 = b"some other data"; let mut state = auth::State::init(&key); state.update(data_part_1); state.update(data_part_2); let tag1 = state.finalize(); let data_2_part_1 = b"some datasome "; let data_2_part_2 = b"other data"; let mut state = auth::State::init(&key); state.update(data_2_part_1); state.update(data_2_part_2); let tag2 = state.finalize(); assert_eq!(tag1, tag2); ``` -------------------------------- ### Index> for Salt Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.Salt.html Allows indexing into the Salt with a range starting from usize. ```APIDOC ## Index> for Salt ### Description Allows a user to access the byte contents of an object as a slice using a `RangeFrom`. WARNING: It might be tempting to do comparisons on objects by using `x[a..] == y[a..]`. This will open up for timing attacks when comparing for example authenticator tags. Because of this only use the comparison functions exposed by the sodiumoxide API. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (RangeFrom) - The range to index. ### Request Body None ### Response #### Success Response (200) - `Output` (`&[u8]`) - The byte slice corresponding to the index range. ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` -------------------------------- ### Implement Index> for Tag Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512256/struct.Tag.html Allows indexing a Tag from a starting point to access its byte contents as a slice. Use sodiumoxide API for comparisons to prevent timing attacks. ```rust impl Index> for Tag fn index(&self, _index: RangeFrom) -> &[u8] ``` -------------------------------- ### Initialize SHA-256 Hashing State Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/hash/sha256/struct.State.html Constructs and initializes a new `State` for SHA-256 hashing. This is the starting point for multi-part hash computations. ```rust pub fn new() -> Self ``` -------------------------------- ### AEAD Combined Mode Example Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/index.html Demonstrates the combined mode of AEAD encryption and decryption using `seal()` and `open()`. The plaintext and additional data are combined into ciphertext. ```APIDOC ## AEAD Combined Mode Example ### Description This example shows how to use the combined mode for AEAD operations. The `seal` function encrypts the message and includes additional data, and `open` decrypts it while verifying the integrity. ### Code ```rust use sodiumoxide::crypto::aead; let k = aead::gen_key(); let n = aead::gen_nonce(); let m = b"Some plaintext"; let ad = b"Some additional data"; let c = aead::seal(m, Some(ad), &n, &k); let m2 = aead::open(&c, Some(ad), &n, &k).unwrap(); assert_eq!(&m[..], &m2[..]); ``` ``` -------------------------------- ### Implement Index> for Seed Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/kx/x25519blake2b/struct.Seed.html Allows accessing bytes from a starting index to the end of the `Seed` as a slice. Use sodiumoxide's comparison functions to avoid timing attacks. ```rust fn index(&self, _index: RangeFrom) -> &[u8] ``` -------------------------------- ### Implement Index> for Nonce Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/secretbox/xsalsa20poly1305/struct.Nonce.html Allows accessing a byte range starting from a specific index to the end of the Nonce. Warning: Avoid direct byte comparisons to prevent timing attacks; use provided comparison functions. ```rust impl Index> for Nonce fn index(&self, _index: RangeFrom) -> &[u8] ``` -------------------------------- ### Get libsodium major version Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/version/fn.version_major.html Returns the major version from libsodium. No setup or imports are required. ```rust pub fn version_major() -> usize ``` -------------------------------- ### Sign and verify data with sodiumoxide Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/sign/index.html Demonstrates the standard workflow for generating a keypair, signing a message, and verifying the signature. ```rust use sodiumoxide::crypto::sign; let (pk, sk) = sign::gen_keypair(); let data_to_sign = b"some data"; let signed_data = sign::sign(data_to_sign, &sk); let verified_data = sign::verify(&signed_data, &pk).unwrap(); assert!(data_to_sign == &verified_data[..]); ``` -------------------------------- ### Function sodiumoxide::init Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/fn.init.html Initializes the sodium library and configures primitives for optimal performance and thread-safety. ```APIDOC ## Function sodiumoxide::init ### Description Initializes the sodium library and chooses faster versions of the primitives if possible. This function also makes the random number generation functions (gen_key, gen_keypair, gen_nonce, randombytes, randombytes_into) thread-safe. ### Response - **Result<(), ()>** - Returns Ok if initialization succeeded and Err if it failed. ``` -------------------------------- ### Get libsodium version string Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/version/fn.version_string.html Call `version_string()` to retrieve the version of the linked libsodium library. No setup or imports are required. ```rust pub fn version_string() -> &'static str ``` -------------------------------- ### Accessing STRPREFIX constant Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/scryptsalsa208sha256/constant.STRPREFIX.html Represents the prefix that all HashedPasswords start with. ```rust pub const STRPREFIX: &[u8]; ``` -------------------------------- ### Encrypt and decrypt using the simple interface Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/box_/index.html Demonstrates basic usage of seal and open functions for public-key authenticated encryption. Requires generating keypairs and a nonce before processing data. ```rust use sodiumoxide::crypto::box_; let (ourpk, oursk) = box_::gen_keypair(); // normally theirpk is sent by the other party let (theirpk, theirsk) = box_::gen_keypair(); let nonce = box_::gen_nonce(); let plaintext = b"some data"; let ciphertext = box_::seal(plaintext, &nonce, &theirpk, &oursk); let their_plaintext = box_::open(&ciphertext, &nonce, &ourpk, &theirsk).unwrap(); assert!(plaintext == &their_plaintext[..]); ``` -------------------------------- ### Encrypt and Decrypt Data with Secretbox Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/secretbox/index.html Demonstrates the basic workflow of generating a key and nonce, sealing plaintext, and verifying the decrypted output. ```rust use sodiumoxide::crypto::secretbox; let key = secretbox::gen_key(); let nonce = secretbox::gen_nonce(); let plaintext = b"some data"; let ciphertext = secretbox::seal(plaintext, &nonce, &key); let their_plaintext = secretbox::open(&ciphertext, &nonce, &key).unwrap(); assert!(plaintext == &their_plaintext[..]); ``` -------------------------------- ### GET /crypto/stream/xchacha20/gen_nonce Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/stream/xchacha20/fn.gen_nonce.html Generates a random nonce for XChaCha20 cryptographic operations. ```APIDOC ## GET /crypto/stream/xchacha20/gen_nonce ### Description Randomly generates a nonce for use with XChaCha20. This function is thread-safe provided that `sodiumoxide::init()` has been called once before usage. ### Method GET ### Endpoint sodiumoxide::crypto::stream::xchacha20::gen_nonce ### Response #### Success Response (200) - **Nonce** (Object) - A randomly generated nonce object. ``` -------------------------------- ### GET /version/minor Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/version/fn.version_minor.html Retrieves the minor version number of the linked libsodium library. ```APIDOC ## GET /version/minor ### Description Returns the minor version from the linked libsodium library as a usize. ### Method GET ### Endpoint sodiumoxide::version::version_minor() ### Response #### Success Response (200) - **version** (usize) - The minor version number of libsodium. ``` -------------------------------- ### Initialization and Padding Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/all.html Functions for initializing the library and for padding/unpadding data. ```APIDOC ## init ### Description Initializes the Sodium Oxide library. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly defined in the provided text. ### Request Example None provided. ### Response None provided. ## padding::pad ### Description Pads data according to a specified scheme. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly defined in the provided text. ### Request Example None provided. ### Response None provided. ## padding::unpad ### Description Removes padding from data. ### Method Not applicable (function call) ### Endpoint Not applicable (function call) ### Parameters None explicitly defined in the provided text. ### Request Example None provided. ### Response None provided. ``` -------------------------------- ### Index> for HashedPassword Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.HashedPassword.html Allows indexing into HashedPassword from a starting index to the end. ```APIDOC ## Index> for HashedPassword ### Description Allows accessing a portion of the `HashedPassword` as a byte slice from a given start index to the end. **WARNING**: Direct comparison of slices obtained this way can lead to timing attacks. Use dedicated comparison functions from the `sodiumoxide` API for security. ### Method `fn index(&self, _index: RangeFrom) -> &[u8]` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (RangeFrom) - The range starting from a specific index to the end. ### Request Body None ### Request Example None ### Response #### Success Response (200) - `&[u8]` - A byte slice representing the specified range of the hashed password. ### Response Example None ``` -------------------------------- ### Initialize Aes256Gcm Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/aes256gcm/struct.Aes256Gcm.html Creates a new Aes256Gcm instance. Requires `sodiumoxide::init()` to have been called. Returns an error if the runtime does not support AES. ```rust pub fn new() -> Result ``` -------------------------------- ### Generate Key and Authenticate Data (Simple Interface) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/index.html Use this for basic authentication tasks. It requires generating a key, authenticating data, and then verifying the tag. ```rust use sodiumoxide::crypto::auth; let key = auth::gen_key(); let data_to_authenticate = b"some data"; let tag = auth::authenticate(data_to_authenticate, &key); assert!(auth::verify(&tag, data_to_authenticate, &key)); ``` -------------------------------- ### Accessing the STRPREFIX constant Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2id13/constant.STRPREFIX.html Represents the prefix that all HashedPasswords start with when using the argon2id13 algorithm. ```rust pub const STRPREFIX: &'static [u8]; ``` -------------------------------- ### Initialization Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/index.html The init function must be called to initialize the sodium library and ensure thread safety for all cryptographic functions. ```APIDOC ## init() ### Description Initializes the sodium library and chooses faster versions of the primitives if possible. This function must be called during program execution to ensure that all functions, including random-number generation, are thread-safe. ### Method Function Call ### Response - **Result** (bool) - Returns true if initialization was successful. ``` -------------------------------- ### Get Major Version Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/version/fn.version_major.html Retrieves the major version number of the underlying libsodium library. ```APIDOC ## GET /version/major ### Description Returns the major version number from the libsodium library. ### Method GET ### Endpoint /version/major ### Parameters None ### Request Body None ### Response #### Success Response (200) - **version** (usize) - The major version number of libsodium. #### Response Example ```json { "version": 1 } ``` ``` -------------------------------- ### GET /crypto/stream/chacha20/gen_key Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/stream/chacha20/fn.gen_key.html Generates a random key for symmetric encryption using the ChaCha20 stream cipher. ```APIDOC ## GET /crypto/stream/chacha20/gen_key ### Description Generates a random key for symmetric encryption. This function is thread-safe provided that `sodiumoxide::init()` has been called once before use. ### Method GET ### Endpoint sodiumoxide::crypto::stream::chacha20::gen_key ### Response #### Success Response (200) - **Key** (Object) - A randomly generated key for symmetric encryption. ``` -------------------------------- ### Implement Indexing for Key (RangeFull) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Enables accessing the entire Key as a byte slice using full range indexing (e.g., `key[]`). Direct slice comparisons are discouraged due to timing attack risks; utilize sodiumoxide's secure comparison methods. ```rust type Output = [u8] ``` ```rust fn index(&self, _index: RangeFull) -> &[u8] ``` -------------------------------- ### Index> for HashedPassword Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.HashedPassword.html Allows indexing into HashedPassword with a range to get a byte slice. ```APIDOC ## Index> for HashedPassword ### Description Allows accessing a portion of the `HashedPassword` as a byte slice using a range. **WARNING**: Direct comparison of slices obtained this way can lead to timing attacks. Use dedicated comparison functions from the `sodiumoxide` API for security. ### Method `fn index(&self, _index: Range) -> &[u8]` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (Range) - The range to index into. ### Request Body None ### Request Example None ### Response #### Success Response (200) - `&[u8]` - A byte slice representing the specified range of the hashed password. ### Response Example None ``` -------------------------------- ### Generate Key Pairs and Session Keys for Key Exchange Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/kx/index.html Demonstrates the client and server-side operations for generating key pairs and deriving session keys using the kx module. Ensure keys are exchanged between parties before deriving session keys. ```rust use sodiumoxide::crypto::kx; // client-side let (client_pk, client_sk) = kx::gen_keypair(); // server-side let (server_pk, server_sk) = kx::gen_keypair(); // client and server exchanges client_pk and server_pk // client deduces the two session keys rx1 and tx1 let (rx1, tx1) = match kx::client_session_keys(&client_pk, &client_sk, &server_pk) { Ok((rx, tx)) => (rx, tx), Err(()) => panic!("bad server signature"), }; // server performs the same operation let (rx2, tx2) = match kx::server_session_keys(&server_pk, &server_sk, &client_pk) { Ok((rx, tx)) => (rx, tx), Err(()) => panic!("bad client signature"), }; assert!(rx1==tx2); assert!(rx2==tx1); ``` -------------------------------- ### Get Type ID Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/hash/sha256/struct.State.html Retrieves the `TypeId` of the current object. This is useful for runtime type identification. ```rust pub fn type_id(&self) -> TypeId ``` -------------------------------- ### Clone for Salt Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.Salt.html Allows creating a copy of a Salt instance. ```APIDOC ## Clone for Salt ### Description Returns a copy of the value. ### Method `clone` ### Endpoint N/A (Trait Implementation) ### Parameters None ### Request Body None ### Response #### Success Response (200) - `Salt` - A new Salt instance that is a copy of the original. ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` ```APIDOC ## clone_from for Salt ### Description Performs copy-assignment from a source Salt. ### Method `clone_from` ### Endpoint N/A (Trait Implementation) ### Parameters - `source` (Salt) - The Salt to copy from. ### Request Body None ### Response #### Success Response (200) None (modifies the instance in place) ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` -------------------------------- ### Nonce Implementations Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/stream/xchacha20/struct.Nonce.html Details on the implementations and methods available for the Nonce struct. ```APIDOC ## Implementations for Nonce ### `from_slice(bs: &[u8]) -> Option` #### Description Creates a `Nonce` object from a byte slice. #### Parameters - **bs** (slice of u8) - The byte slice to create the nonce from. #### Returns - `Some(Nonce)` if the byte slice has the correct length (24 bytes). - `None` if the byte slice length is not equal to 24. ### `increment_le(&self) -> Nonce` #### Description Treats the nonce as an unsigned little-endian number and returns an incremented version of it. #### Warning This method does not check for arithmetic overflow. It is the caller's responsibility to ensure that any given nonce value is only used once. Failure to do so will break cryptographic security guarantees. #### Returns A new `Nonce` object with the incremented value. ### `increment_le_inplace(&mut self)` #### Description Treats the nonce as an unsigned little-endian number and increments it in place. #### Warning This method does not check for arithmetic overflow. It is the caller's responsibility to ensure that any given nonce value is only used once. Failure to do so will break cryptographic security guarantees. ``` -------------------------------- ### Get Sodiumoxide Version String Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/version/fn.version_string.html Retrieves the version string of the underlying libsodium library used by sodiumoxide. ```APIDOC ## GET /version ### Description Retrieves the version string from libsodium. ### Method GET ### Endpoint /version ### Parameters None ### Request Example None ### Response #### Success Response (200) - **version** (string) - The version string of the libsodium library. ``` -------------------------------- ### Generate and Use a Shorthash Key Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/shorthash/index.html Demonstrates how to generate a secret key and compute a hash digest for given data using the `shorthash` function. Ensure the `shorthash` feature is enabled. ```rust use sodiumoxide::crypto::shorthash; let key = shorthash::gen_key(); let data_to_hash = b"some data"; let digest = shorthash::shorthash(data_to_hash, &key); ``` -------------------------------- ### Index for HashedPassword Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.HashedPassword.html Allows indexing into HashedPassword with a full range to get the entire byte slice. ```APIDOC ## Index for HashedPassword ### Description Allows accessing the entire `HashedPassword` as a byte slice. **WARNING**: Direct comparison of slices obtained this way can lead to timing attacks. Use dedicated comparison functions from the `sodiumoxide` API for security. ### Method `fn index(&self, _index: RangeFull) -> &[u8]` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (RangeFull) - The full range. ### Request Body None ### Request Example None ### Response #### Success Response (200) - `&[u8]` - A byte slice representing the entire hashed password. ### Response Example None ``` -------------------------------- ### Stream Initialization and Operations Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/secretstream/xchacha20poly1305/struct.Stream.html Provides methods for initializing a push stream, encrypting messages, and finalizing the stream. ```APIDOC ## POST /secretstream/xchacha20poly1305/Stream/init_push ### Description Initializes an `Stream` for pushing (encrypting) data using a provided `key`. It returns the `Stream` object and a `Header` necessary for the recipient to initialize their `Stream`. ### Method POST ### Endpoint /secretstream/xchacha20poly1305/Stream/init_push ### Parameters #### Request Body - **key** (Key) - Required - The secret key for encryption. ### Response #### Success Response (200) - **stream** (Stream) - The initialized stream object. - **header** (Header) - The header required for the receiving end. #### Response Example ```json { "stream": "", "header": "" } ``` ## POST /secretstream/xchacha20poly1305/Stream/push ### Description Encrypts a message `m` along with an optional `tag` and optional additional authenticated data `ad`. The encrypted message is returned as a `Vec`. ### Method POST ### Endpoint /secretstream/xchacha20poly1305/Stream/push ### Parameters #### Request Body - **m** (slice of u8) - Required - The message to encrypt. - **ad** (Option<&[u8]>) - Optional - Additional data to authenticate. - **tag** (Tag) - Required - The tag associated with the message. ### Response #### Success Response (200) - **encrypted_message** (Vec) - The resulting ciphertext. #### Response Example ```json { "encrypted_message": "" } ``` ## POST /secretstream/xchacha20poly1305/Stream/push_to_vec ### Description Encrypts a message `m` with an optional `tag` and optional additional authenticated data `ad`. The encrypted message is written directly to the provided `out` vector. ### Method POST ### Endpoint /secretstream/xchacha20poly1305/Stream/push_to_vec ### Parameters #### Request Body - **m** (slice of u8) - Required - The message to encrypt. - **ad** (Option<&[u8]>) - Optional - Additional data to authenticate. - **tag** (Tag) - Required - The tag associated with the message. - **out** (mutable reference to Vec) - Required - The vector to write the encrypted message to. ### Response #### Success Response (200) - **Result** (Result<(), ()>) - Ok(()) on success, Err(()) on failure. #### Response Example ```json { "result": "Ok(())" } ``` ## POST /secretstream/xchacha20poly1305/Stream/finalize ### Description Finalizes the stream by creating a ciphertext for an empty message with the `TAG_FINAL` tag. This method consumes the `Stream` and it cannot be used afterwards. It also authenticates optional additional data `ad`. ### Method POST ### Endpoint /secretstream/xchacha20poly1305/Stream/finalize ### Parameters #### Request Body - **ad** (Option<&[u8]>) - Optional - Additional data to authenticate. ### Response #### Success Response (200) - **finalized_ciphertext** (Vec) - The ciphertext representing the end of the stream. #### Response Example ```json { "finalized_ciphertext": "" } ``` ``` -------------------------------- ### Implement Any for T Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/chacha20poly1305/struct.Tag.html This implementation allows any type T that is 'static and ?Sized to be treated as Any. It provides a way to get the TypeId of the object. ```rust impl Any for T where T: 'static + ?Sized, ``` ```rust pub fn type_id(&self) -> TypeId ``` -------------------------------- ### Key Trait Implementations Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/kdf/blake2b/struct.Key.html This section outlines the available trait implementations for the Key type, providing insights into its capabilities such as data conversion, cloning, debugging, serialization/deserialization, hashing, indexing, and comparison. ```APIDOC ## AsRef<[u8]> for Key ### Description Provides a way to reference the Key as a byte slice. ### Method `as_ref` ### Endpoint N/A (Trait Implementation) ### Parameters None ### Request Example None ### Response #### Success Response - `&[u8]` - A slice of bytes representing the Key. #### Response Example None ``` ```APIDOC ## Clone for Key ### Description Allows creating a copy of a Key. ### Method `clone` ### Endpoint N/A (Trait Implementation) ### Parameters None ### Request Example None ### Response #### Success Response - `Key` - A new Key instance that is a copy of the original. #### Response Example None ``` ```APIDOC ## Debug for Key ### Description Enables the Key type to be formatted for debugging purposes. ### Method `fmt` ### Endpoint N/A (Trait Implementation) ### Parameters - `formatter` (`&mut Formatter<'_>`) - The formatter to use. ### Request Example None ### Response #### Success Response - `Result` - Indicates success or failure of the formatting operation. #### Response Example None ``` ```APIDOC ## Deserialize<'de> for Key ### Description Allows deserializing a Key from a Serde deserializer. ### Method `deserialize` ### Endpoint N/A (Trait Implementation) ### Parameters - `deserializer` (`D`) - The Serde deserializer. ### Request Example None ### Response #### Success Response - `Result` - The deserialized Key or an error. #### Response Example None ``` ```APIDOC ## Hash for Key ### Description Enables hashing of the Key type. ### Method `hash`, `hash_slice` ### Endpoint N/A (Trait Implementation) ### Parameters - `state` (`&mut H`) - The hasher state. - `data` (`&[Self]`) - The slice of Keys to hash (for `hash_slice`). ### Request Example None ### Response #### Success Response None #### Response Example None ``` ```APIDOC ## Index> for Key ### Description Allows accessing a range of bytes within the Key. Use comparison functions from the sodiumoxide API for security. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (`Range`) - The range to index. ### Request Example None ### Response #### Success Response - `&[u8]` - A slice of bytes from the specified range. #### Response Example None ``` ```APIDOC ## Index> for Key ### Description Allows accessing bytes from a starting index to the end of the Key. Use comparison functions from the sodiumoxide API for security. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (`RangeFrom`) - The starting index. ### Request Example None ### Response #### Success Response - `&[u8]` - A slice of bytes from the specified index to the end. #### Response Example None ``` ```APIDOC ## Index for Key ### Description Allows accessing all bytes within the Key. Use comparison functions from the sodiumoxide API for security. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (`RangeFull`) - Represents the full range. ### Request Example None ### Response #### Success Response - `&[u8]` - A slice of all bytes in the Key. #### Response Example None ``` ```APIDOC ## Index> for Key ### Description Allows accessing bytes from the beginning up to a specified index. Use comparison functions from the sodiumoxide API for security. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (`RangeTo`) - The ending index (exclusive). ### Request Example None ### Response #### Success Response - `&[u8]` - A slice of bytes from the beginning up to the specified index. #### Response Example None ``` ```APIDOC ## Ord for Key ### Description Provides total ordering for the Key type. ### Method `cmp`, `max`, `min`, `clamp` ### Endpoint N/A (Trait Implementation) ### Parameters - `other` (`&Key` or `Key`) - The other Key to compare with. ### Request Example None ### Response #### Success Response - `Ordering` - The result of the comparison. - `Key` - The maximum or minimum Key. #### Response Example None ``` ```APIDOC ## PartialEq for Key ### Description Enables equality comparison between Key instances. ### Method `eq`, `ne` ### Endpoint N/A (Trait Implementation) ### Parameters - `other` (`&Key` or `&Rhs`) - The other Key to compare with. ### Request Example None ### Response #### Success Response - `bool` - `true` if equal, `false` otherwise. #### Response Example None ``` ```APIDOC ## PartialOrd for Key ### Description Provides partial ordering for the Key type. ### Method `partial_cmp`, `lt`, `le`, `ge`, `gt` ### Endpoint N/A (Trait Implementation) ### Parameters - `other` (`&Key`) - The other Key to compare with. ### Request Example None ### Response #### Success Response - `Option` - The result of the partial comparison. - `bool` - The result of the comparison operators. #### Response Example None ``` ```APIDOC ## Serialize for Key ### Description Allows serializing the Key type into a Serde serializer. ### Method `serialize` ### Endpoint N/A (Trait Implementation) ### Parameters - `serializer` (`S`) - The Serde serializer. ### Request Example None ### Response #### Success Response - `Result` - The result of the serialization. #### Response Example None ``` ```APIDOC ## Copy for Key ### Description Indicates that the Key type can be copied implicitly. ### Method Implicit copy operations. ### Endpoint N/A (Trait Implementation) ### Parameters None ### Request Example None ### Response None #### Response Example None ``` ```APIDOC ## Eq for Key ### Description Marks the Key type as having a total equality relation. ### Method Implicitly provided by `PartialEq`. ### Endpoint N/A (Trait Implementation) ### Parameters None ### Request Example None ### Response None #### Response Example None ``` -------------------------------- ### Any Trait Implementation Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/chacha20poly1305/struct.Key.html Implementation of the `Any` trait, providing a `type_id` method to get the unique type identifier of an object. ```APIDOC ## impl Any for T ### Description Implementation of the `Any` trait for any type `T` that is `'static` and `?Sized`. ### Method `type_id` ### Endpoint N/A (Trait implementation) ### Parameters None ### Request Body None ### Response #### Success Response (200) - **TypeId** (TypeId) - The unique identifier for the type of `self`. ### Response Example ```json { "type_id": "some_type_id_value" } ``` ``` -------------------------------- ### Implement Indexing for Key (RangeTo) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Allows accessing the beginning part of the Key as a byte slice using `RangeTo` indexing (e.g., `key[..b]`). Direct slice comparisons are susceptible to timing attacks; always use sodiumoxide's provided comparison functions for security. ```rust type Output = [u8] ``` ```rust fn index(&self, _index: RangeTo) -> &[u8] ``` -------------------------------- ### Get XChaCha20-Poly1305 Header Size Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/secretstream/xchacha20poly1305/constant.HEADERBYTES.html Use HEADERBYTES to determine the size of the header needed for encrypted streams. This header must precede the encrypted messages. ```rust pub const HEADERBYTES: usize = crypto_secretstream_xchacha20poly1305_HEADERBYTES as usize; // 0x0000_0000_0000_0018usize ``` -------------------------------- ### AEAD Detached Mode Example Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/index.html Illustrates the detached mode of AEAD encryption and decryption using `seal_detached()` and `open_detached()`. The ciphertext and authentication tag are handled separately. ```APIDOC ## AEAD Detached Mode Example ### Description This example demonstrates the detached mode for AEAD operations. The `seal_detached` function encrypts the message and returns a separate authentication tag. `open_detached` verifies the tag and decrypts the message. ### Code ```rust use sodiumoxide::crypto::aead; let k = aead::gen_key(); let n = aead::gen_nonce(); let mut m = [0x41, 0x42, 0x43, 0x44]; let m2 = m.clone(); let ad = b"Some additional data"; let t = aead::seal_detached(&mut m, Some(ad), &n, &k); aead::open_detached(&mut m, Some(ad), &t, &n, &k).unwrap(); assert_eq!(m, m2); ``` ``` -------------------------------- ### Index for Salt Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.Salt.html Allows indexing into the Salt with a full range. ```APIDOC ## Index for Salt ### Description Allows a user to access the byte contents of an object as a slice using a `RangeFull`. WARNING: It might be tempting to do comparisons on objects by using `x[] == y[]`. This will open up for timing attacks when comparing for example authenticator tags. Because of this only use the comparison functions exposed by the sodiumoxide API. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (RangeFull) - The full range to index. ### Request Body None ### Response #### Success Response (200) - `Output` (`&[u8]`) - The byte slice corresponding to the full range. ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` -------------------------------- ### GenericHash Module Overview Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/generichash/index.html Provides an overview of the GenericHash module's components. ```APIDOC ## Module sodiumoxide::crypto::generichash ### Description `GenericHash`. ### Structs #### `Digest` Represents a digest. #### `State` `State` contains the state for multi-part (streaming) hash computations. This allows the caller to process a message as a sequence of multiple chunks. ### Constants #### `DIGEST_MAX` Maximum of allowed bytes in a `Digest`. #### `DIGEST_MIN` Minimum of allowed bytes in a `Digest`. #### `KEY_MAX` Maximum of allowed bytes in a key. #### `KEY_MIN` Minimum of allowed bytes in a key. ### Functions #### `hash` `hash` computes a fingerprint of `data`. ``` -------------------------------- ### Implement Clone for Key Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Enables creating a copy of an existing Key. Note that direct comparison of keys using equality operators can be vulnerable to timing attacks; use sodiumoxide's comparison functions instead. ```rust fn clone(&self) -> Key ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Implement Indexing for Key (Range) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Allows accessing parts of the Key as byte slices using range indexing (e.g., `key[a..b]`). Use with caution, as direct slice comparisons can be vulnerable to timing attacks. Prefer sodiumoxide's dedicated comparison functions. ```rust type Output = [u8] ``` ```rust fn index(&self, _index: Range) -> &[u8] ``` -------------------------------- ### Implement Indexing for Key (RangeFrom) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Allows accessing the latter part of the Key as a byte slice using `RangeFrom` indexing (e.g., `key[a..]`). Be mindful of potential timing attack vulnerabilities when comparing slices; use sodiumoxide's comparison functions for security. ```rust type Output = [u8] ``` ```rust fn index(&self, _index: RangeFrom) -> &[u8] ``` -------------------------------- ### Key Creation from Slice Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/xchacha20poly1305_ietf/struct.Key.html Creates a Key instance from a byte slice, returning None if the slice length is not exactly 32 bytes. ```rust pub fn from_slice(bs: &[u8]) -> Option ``` -------------------------------- ### Index> for Salt Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.Salt.html Allows indexing into the Salt with a range up to usize. ```APIDOC ## Index> for Salt ### Description Allows a user to access the byte contents of an object as a slice using a `RangeTo`. WARNING: It might be tempting to do comparisons on objects by using `x[..b] == y[..b]`. This will open up for timing attacks when comparing for example authenticator tags. Because of this only use the comparison functions exposed by the sodiumoxide API. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (RangeTo) - The range to index. ### Request Body None ### Response #### Success Response (200) - `Output` (`&[u8]`) - The byte slice corresponding to the index range. ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` -------------------------------- ### Initialize Sodium Library Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/fn.init.html Initializes the sodium library. It attempts to use faster primitive versions if available and makes random number generation functions thread-safe. Returns `Ok` on success and `Err` on failure. ```rust pub fn init() -> Result<(), ()> ``` -------------------------------- ### Module sodiumoxide::crypto::hash::sha512 Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/hash/sha512/index.html Documentation for the SHA-512 hashing algorithm. ```APIDOC ## Module sodiumoxide::crypto::hash::sha512 ### Description `SHA-512`. There has been considerable degradation of public confidence in the security conjectures for many hash functions, including `SHA-512`. However, for the moment, there do not appear to be alternatives that inspire satisfactory levels of confidence. One can hope that NIST’s SHA-3 competition will improve the situation. ### Structs #### `Digest` - **Digest-structure**: Represents the structure for digest computations. #### `State` - **State**: Contains the state for multi-part (streaming) hash computations. This allows the caller to process a message as a sequence of multiple chunks. ### Constants #### `BLOCKBYTES` - **Block size**: Block size of the hash function. #### `DIGESTBYTES` - **Number of bytes**: Number of bytes in a `Digest`. ### Functions #### `hash` - **hash**: Hashes a message `m`. It returns a hash `h`. ``` -------------------------------- ### Index> for Salt Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/pwhash/argon2i13/struct.Salt.html Allows indexing into the Salt with a range of usize. ```APIDOC ## Index> for Salt ### Description Allows a user to access the byte contents of an object as a slice using a `Range`. WARNING: It might be tempting to do comparisons on objects by using `x[a..b] == y[a..b]`. This will open up for timing attacks when comparing for example authenticator tags. Because of this only use the comparison functions exposed by the sodiumoxide API. ### Method `index` ### Endpoint N/A (Trait Implementation) ### Parameters - `_index` (Range) - The range to index. ### Request Body None ### Response #### Success Response (200) - `Output` (`&[u8]`) - The byte slice corresponding to the index range. ### Response Example ``` // Example usage would depend on the context where Salt is used. ``` ``` -------------------------------- ### SipHash24 Functions Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/shorthash/siphash24/index.html Documentation for the functions used to generate keys and compute hashes with SipHash24. ```APIDOC ## Functions ### gen_key `gen_key()` randomly generates a key for shorthash. ### shorthash `shorthash` hashes a message `m` under a key `k`. It returns a hash `h`. ``` -------------------------------- ### Implement clone_into for T (Nightly) Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/aead/chacha20poly1305/struct.Tag.html This nightly-only experimental API allows using borrowed data to replace owned data, usually by cloning. It's an alternative to `to_owned` for in-place updates. ```rust pub fn clone_into(&self, target: &mut T) ``` -------------------------------- ### Implement Serialize for Key Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Enables serialization of a Key into various data formats using Serde. The serialization process will handle the 32-byte key data. ```rust fn serialize(&self, serializer: S) -> Result where S: Serializer, ``` -------------------------------- ### Blanket Implementations Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/kx/x25519blake2b/struct.PublicKey.html Covers various blanket implementations provided by the library, such as Any, Borrow, BorrowMut, From, Into, ToOwned, TryFrom, TryInto, and DeserializeOwned. ```APIDOC ## Blanket Implementations ### Description This section details the blanket implementations available in the library. Blanket implementations allow a trait to be implemented for a large number of types, often based on other trait bounds. ### Implementations #### `impl Any for T` ##### Description Provides the `Any` trait implementation for any type `T` that is `'static` and sized. ##### Methods - `type_id(&self) -> TypeId`: Gets the `TypeId` of `self`. #### `impl Borrow for T` ##### Description Implements the `Borrow` trait for `T` itself, allowing immutable borrowing. ##### Methods - `borrow(&self) -> &T`: Immutably borrows from an owned value. #### `impl BorrowMut for T` ##### Description Implements the `BorrowMut` trait for `T` itself, allowing mutable borrowing. ##### Methods - `borrow_mut(&mut self) -> &mut T`: Mutably borrows from an owned value. #### `impl From for T` ##### Description Provides a `From` implementation where a type can be converted from itself. ##### Methods - `from(t: T) -> T`: Performs the conversion. #### `impl Into for T where U: From` ##### Description Implements the `Into` trait for type `T` into type `U`, provided that `U` implements `From`. ##### Methods - `into(self) -> U`: Performs the conversion. #### `impl ToOwned for T where T: Clone` ##### Description Implements the `ToOwned` trait for types `T` that implement `Clone`. ##### Associated Types - `Owned = T`: The resulting type after obtaining ownership. ##### Methods - `to_owned(&self) -> T`: Creates owned data from borrowed data, usually by cloning. - `clone_into(&self, target: &mut T)`: Uses borrowed data to replace owned data, usually by cloning. (Nightly-only experimental API) #### `impl TryFrom for T where U: Into` ##### Description Implements the `TryFrom` trait for converting type `U` into type `T`, provided `U` can be converted into `T`. ##### Associated Types - `Error = Infallible`: The type returned in the event of a conversion error. ##### Methods - `try_from(value: U) -> Result>::Error>`: Performs the conversion. #### `impl TryInto for T where U: TryFrom` ##### Description Implements the `TryInto` trait for converting type `T` into type `U`, provided `U` can be converted from `T`. ##### Associated Types - `Error = >::Error`: The type returned in the event of a conversion error. ##### Methods - `try_into(self) -> Result>::Error>`: Performs the conversion. #### `impl DeserializeOwned for T where T: for<'de> Deserialize<'de>` ##### Description Implements `DeserializeOwned` for types `T` that implement `Deserialize` for any lifetime. ``` -------------------------------- ### Implement PartialEq for Key Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512/struct.Key.html Provides equality comparison for two Key instances. For security-sensitive comparisons, especially in contexts like authenticator tags, it is crucial to use the comparison functions provided by the sodiumoxide API to mitigate timing attacks. ```rust fn eq(&self, other: &Key) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Key Implementation: Indexing Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/stream/xchacha20/struct.Key.html Enables accessing the Key's byte contents as slices using standard Rust indexing. WARNING: Avoid direct byte-wise comparisons of keys using slices due to potential timing attack vulnerabilities; use sodiumoxide's provided comparison functions. ```rust type Output = [u8] fn index(&self, _index: Range) -> &[u8] ``` ```rust type Output = [u8] fn index(&self, _index: RangeFrom) -> &[u8] ``` ```rust type Output = [u8] fn index(&self, _index: RangeFull) -> &[u8] ``` ```rust type Output = [u8] fn index(&self, _index: RangeTo) -> &[u8] ``` -------------------------------- ### Perform hashing with sodiumoxide Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/hash/index.html Demonstrates both direct hashing of data and incremental hashing using the State API. ```rust use sodiumoxide::crypto::hash; let data_to_hash = b"some data"; let digest = hash::hash(data_to_hash); let mut hash_state = hash::State::new(); hash_state.update(b"some "); hash_state.update(b"data!"); let digest = hash_state.finalize(); ``` -------------------------------- ### Implement Index for Tag Source: https://docs.rs/sodiumoxide/0.2.7/sodiumoxide/crypto/auth/hmacsha512256/struct.Tag.html Allows indexing a Tag with a full range to access its byte contents as a slice. Use sodiumoxide API for comparisons to prevent timing attacks. ```rust impl Index for Tag fn index(&self, _index: RangeFull) -> &[u8] ```