### Get Type ID Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Gets the `TypeId` of the `SecretBox` or its inner type `T`. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId> ``` -------------------------------- ### Initialize SecretBox with Constructor Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Creates a SecretBox using a constructor function. The implementation attempts to zeroize the locally constructed value before copying it to the heap to minimize exposure. ```rust pub fn init_with(ctr: impl FnOnce() -> S) -> Self> ``` -------------------------------- ### Try Initialize SecretBox with Fallible Constructor Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Similar to init_with, but the constructor can return a Result. It's recommended to use Self::new or Self::init_with_mut when possible. ```rust pub fn try_init_with(ctr: impl FnOnce() -> Result) -> Result ``` -------------------------------- ### SecretBox Creation Methods Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides methods for creating instances of SecretBox, including initialization with pre-boxed values, in-place initialization, and construction via a closure. ```APIDOC ### impl SecretBox #### pub fn new(boxed_secret: Box) -> Self Create a secret value using a pre-boxed value. ### impl SecretBox #### pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self Create a secret value using a function that can initialize the value in-place. ### impl SecretBox #### pub fn init_with(ctr: impl FnOnce() -> S) -> Self Create a secret value using the provided function as a constructor. **Note:** using `Self::new` or `Self::init_with_mut` is preferable when possible, since this method’s safety relies on empiric evidence and may be violated on some targets. #### pub fn try_init_with(ctr: impl FnOnce() -> Result) -> Result Same as `Self::init_with`, but the constructor can be fallible. **Note:** using `Self::new` or `Self::init_with_mut` is preferable when possible, since this method’s safety relies on empyric evidence and may be violated on some targets. ``` -------------------------------- ### Initialize SecretBox with Constructor Function Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Creates a secret value using a provided constructor function. It's recommended to use Self::new or Self::init_with_mut when possible. ```rust pub fn init_with(ctr: impl FnOnce() -> S) -> Self ``` -------------------------------- ### Initialize SecretBox with In-place Function Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Creates a secret value using a function that can initialize the value in-place. ```rust pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self ``` -------------------------------- ### Initialize SecretBox In-Place Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Creates a SecretBox by initializing the secret value in-place using a provided closure. This method is suitable when the secret needs to be set up directly within the SecretBox. ```rust pub fn init_with_mut(ctr: impl FnOnce(&mut S)) -> Self> ``` -------------------------------- ### Create SecretBox from Pre-boxed Value Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Constructs a SecretBox using a value that has already been boxed. ```rust pub fn new(boxed_secret: Box) -> Self ``` -------------------------------- ### SecretBox Trait Implementations Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Details the various trait implementations for SecretBox, including Clone, Debug, Default, Deserialize, Drop, ExposeSecret, ExposeSecretMut, From, Serialize, and Zeroize. ```APIDOC ## Trait Implementations ### impl Clone for SecretBox #### fn clone(&self) -> Self Returns a duplicate of the value. #### fn clone_from(&mut self, source: &Self) Performs copy-assignment from `source`. ### impl Debug for SecretBox #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. ### impl Default for SecretBox #### fn default() -> Self Returns the “default value” for a type. ### impl<'de, T> Deserialize<'de> for SecretBox Available on **crate feature`serde`** only. #### fn deserialize(deserializer: D) -> Result Deserialize this value from the given Serde deserializer. ### impl Drop for SecretBox #### fn drop(&mut self) Executes the destructor for this type. ### impl ExposeSecret for SecretBox #### fn expose_secret(&self) -> &S Expose secret: this is the only method providing access to a secret. ### impl ExposeSecretMut for SecretBox #### fn expose_secret_mut(&mut self) -> &mut S Expose secret: this is the only method providing access to a secret. ### impl From> for SecretBox #### fn from(source: Box) -> Self Converts to this type from the input type. ### impl Serialize for SecretBox Available on **crate feature`serde`** only. #### fn serialize(&self, serializer: S) -> Result Serialize this value into the given Serde serializer. ### impl Zeroize for SecretBox #### fn zeroize(&mut self) Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler. ### impl ZeroizeOnDrop for SecretBox ``` -------------------------------- ### Create SecretBox with Pre-boxed Value Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Creates a new SecretBox using a pre-boxed secret value. This is a straightforward way to wrap an existing boxed secret. ```rust pub fn new(boxed_secret: Box) -> Self> ``` -------------------------------- ### Serialize SecretBox Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Serializes a SecretBox into a Serde serializer. Available only when the 'serde' feature is enabled. Requires T to be Zeroize, SerializableSecret, Serialize, and Sized. ```rust fn serialize(&self, serializer: S) -> Result where S: Serializer, ``` -------------------------------- ### Conversion Traits (From, Into, TryFrom, TryInto) Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Standard library traits for type conversions, including fallible and infallible conversion patterns. ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ## fn into(self) -> U ### Description Calls `U::from(self)` to perform a conversion. ## fn try_from(value: U) -> Result>::Error> ### Description Performs a fallible conversion from type U to type T. ## fn try_into(self) -> Result>::Error> ### Description Performs a fallible conversion into type U. ``` -------------------------------- ### Convert Box to SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Converts a `Box` directly into a `SecretBox`. This is equivalent to calling `SecretBox::new`. ```rust fn from(source: Box) -> Self> ``` -------------------------------- ### SecretBox API Source: https://docs.rs/secrecy/latest/secrecy/type.SecretString.html Methods for initializing and managing secret values within a SecretBox container. ```APIDOC ## SecretBox Methods ### init_with Creates a secret value using a constructor function. It attempts to zeroize the locally constructed value before copying to the heap. ### try_init_with Similar to `init_with`, but supports fallible constructors. ### new Creates a secret value using a pre-boxed value. ### init_with_mut Creates a secret value using a function that initializes the value in-place. ### expose_secret Provides read-only access to the underlying secret. ### expose_secret_mut Provides mutable access to the underlying secret. ``` -------------------------------- ### CloneToUninit Trait Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides an experimental method for performing copy-assignment from a type to an uninitialized memory location. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ### Parameters - **dest** (*mut u8) - Required - A pointer to the uninitialized memory location where the data will be copied. ``` -------------------------------- ### Expose SecretBox Content Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Provides immutable access to the secret content within the SecretBox. Requires S to be Zeroize. ```rust fn expose_secret(&self) -> &S ``` -------------------------------- ### Convert Box to SecretBox Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Converts a Box into a SecretBox. Requires S to be Zeroize. ```rust fn from(source: Box) -> Self ``` -------------------------------- ### Serde Support for SecretBox Source: https://docs.rs/secrecy/latest/secrecy/index.html When the `serde` feature is enabled, SecretBox can be deserialized. Serialization is opt-in via the `SerializableSecret` marker trait to prevent accidental exfiltration. ```APIDOC ## Serde Support When the `serde` feature of this crate is enabled, the `SecretBox` type will receive a `Deserialize` impl for all `SecretBox` types where `T: DeserializeOwned`. This allows _loading_ secret values from data deserialized from `serde` (be careful to clean up any intermediate secrets when doing this, e.g. the unparsed input!) To prevent exfiltration of secret values via `serde`, by default `SecretBox` does _not_ receive a corresponding `Serialize` impl. If you would like types of `SecretBox` to be serializable with `serde`, you will need to impl the `SerializableSecret` marker trait on `T`. ``` -------------------------------- ### Expose Mutable SecretBox Content Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Provides mutable access to the secret content within the SecretBox. Requires S to be Zeroize. ```rust fn expose_secret_mut(&mut self) -> &mut S ``` -------------------------------- ### Drop SecretBox Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Executes the destructor for SecretBox, ensuring memory is zeroized. Requires S to be Zeroize. ```rust fn drop(&mut self) ``` -------------------------------- ### Clone From SecretSlice Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Performs copy-assignment from a source SecretSlice. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Format SecretBox for Debugging Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Formats the SecretBox value for debugging purposes. Requires S to be Zeroize. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### SecretBox Implementation Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecret.html Implementation of the ExposeSecret trait for SecretBox, requiring the inner type to implement Zeroize. ```rust impl ExposeSecret for SecretBox ``` -------------------------------- ### Format SecretBox for Debug Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Formats the SecretBox for debugging purposes. This implementation requires the inner secret type `S` to implement `Zeroize`. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result> ``` -------------------------------- ### Deserialize SecretBox Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Deserializes a SecretBox from a Serde deserializer. Available only when the 'serde' feature is enabled. Requires T to be Zeroize, Clone, DeserializeOwned, and Sized. ```rust fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, ``` -------------------------------- ### Clone From SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Performs copy-assignment from a source SecretBox to the current one. This is part of the `Clone` trait implementation. ```rust fn clone_from(&mut self, source: &Self)> ``` -------------------------------- ### Zeroize SecretBox Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Zeroes out the SecretBox's memory using compiler-intrinsics to prevent optimization. Requires S to be Zeroize. ```rust fn zeroize(&mut self) ``` -------------------------------- ### Default SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides a default value for SecretBox. This requires the inner secret type `S` to implement `Zeroize` and `Default`. ```rust fn default() -> Self> ``` -------------------------------- ### ExposeSecret Required Method Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecret.html The primary method for accessing the underlying secret. This is the only intended way to retrieve the secret value from the wrapper. ```rust fn expose_secret(&self) -> &S ``` -------------------------------- ### Convert Vec to SecretSlice Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Converts a Vec into a SecretSlice. Requires S to be Zeroize. ```rust fn from(vec: Vec) -> Self ``` -------------------------------- ### Trait ExposeSecretMut Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecretMut.html Documentation for the ExposeSecretMut trait, which allows mutable access to an inner secret. ```APIDOC ## Trait ExposeSecretMut ### Description Expose a mutable reference to an inner secret. ### Required Methods #### fn expose_secret_mut(&mut self) -> &mut S Expose secret: this is the only method providing access to a secret. ### Implementors #### impl ExposeSecretMut for SecretBox ``` -------------------------------- ### Clone SecretSlice Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Returns a duplicate of the SecretSlice. Requires S to be CloneableSecret and Zeroize. ```rust fn clone(&self) -> Self ``` -------------------------------- ### Type Aliases for Secrets Source: https://docs.rs/secrecy/latest/secrecy/index.html Provides convenient type aliases for common secret types like slices and strings. ```APIDOC ## Type Aliases ### `SecretSlice` Secret slice type. ### `SecretString` Secret string type. ``` -------------------------------- ### Default SecretSlice Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Returns the default value for SecretSlice. Requires S to be Zeroize. ```rust fn default() -> Self ``` -------------------------------- ### SecretBox Wrapper Type Source: https://docs.rs/secrecy/latest/secrecy/index.html The SecretBox type is a wrapper designed to limit accidental exposure of secret values and ensure they are securely wiped from memory upon dropping. It is intended for sensitive data such as passwords, cryptographic keys, access tokens, or other credentials. ```APIDOC ## Struct: SecretBox ### Description Wrapper type for values that contains secrets, which attempts to limit accidental exposure and ensure secrets are wiped from memory when dropped. (e.g. passwords, cryptographic keys, access tokens or other credentials) ### Fields This struct does not expose its fields directly. Access to the inner secret is managed through traits like `ExposeSecret` and `ExposeSecretMut`. ``` -------------------------------- ### Traits for Secret Handling Source: https://docs.rs/secrecy/latest/secrecy/index.html Defines traits for managing secret data, including marking secrets that can be cloned, exposing secrets by reference or mutable reference, and enabling serde serialization. ```APIDOC ## Traits ### `CloneableSecret` Marker trait for secrets which are allowed to be cloned. ### `ExposeSecret` Expose a reference to an inner secret. ### `ExposeSecretMut` Expose a mutable reference to an inner secret. ### `SerializableSecret` `serde` marker trait for secret types which can be `Serialize`-d by `serde`. ``` -------------------------------- ### Clone SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Returns a duplicate of the SecretBox. This implementation requires the inner secret type `S` to implement `CloneableSecret`. ```rust fn clone(&self) -> Self> ``` -------------------------------- ### Trait ExposeSecret Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecret.html Documentation for the ExposeSecret trait used to expose references to inner secrets. ```APIDOC ## Trait ExposeSecret ### Description A trait for exposing a reference to an inner secret. This is the primary method for accessing protected data within the secrecy crate. ### Methods #### fn expose_secret(&self) -> &S Expose secret: this is the only method providing access to a secret. ### Implementors - impl ExposeSecret for SecretBox ``` -------------------------------- ### SecretSlice API Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Type alias and implementation details for SecretSlice, used for handling secret slices. ```APIDOC ## SecretSlice ### Description A type alias for `SecretBox<[S]>` which supports helpful trait implementations for secret slices. ### Definition `pub type SecretSlice = SecretBox<[S]>;` ### Key Implementations - **From>**: The preferred method for construction from a vector. - **Clone**: Implemented where S: CloneableSecret + Zeroize. - **Default**: Implemented where S: Zeroize. ``` -------------------------------- ### Define SecretBox Struct Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Defines the SecretBox struct which wraps a secret value. It has private fields to prevent direct access. ```rust pub struct SecretBox { /* private fields */ } ``` -------------------------------- ### Zeroize SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Zeroes out the SecretBox from memory using Rust intrinsics to prevent compiler optimizations from removing the zeroization. This ensures the secret is securely wiped. ```rust fn zeroize(&mut self)> ``` -------------------------------- ### SecretSlice Struct Definition Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html The underlying struct definition for SecretSlice, which is a wrapper for secret data. ```rust pub struct SecretSlice { /* private fields */ } ``` -------------------------------- ### Define SecretString struct Source: https://docs.rs/secrecy/latest/secrecy/type.SecretString.html The internal structure definition for SecretString. ```rust pub struct SecretString { /* private fields */ } ``` -------------------------------- ### Expose Mutable Secret Value Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides mutable access to the inner secret value. Use with caution to avoid accidental exposure. ```rust fn expose_secret_mut(&mut self) -> &mut S> ``` -------------------------------- ### SerializableSecret Trait Source: https://docs.rs/secrecy/latest/secrecy/trait.SerializableSecret.html Details about the SerializableSecret trait, which allows secret types to be serialized using serde when the 'serde' feature is enabled. ```APIDOC ## Trait SerializableSecret ### Description Marker trait for secret types which can be `Serialize`-d by `serde`. When the `serde` feature of this crate is enabled and types are marked with this trait, they receive a `Serialize` impl for `SecretBox`. (NOTE: all types which impl `DeserializeOwned` receive a `Deserialize` impl) This is done deliberately to prevent accidental exfiltration of secrets via `serde` serialization. If you really want to have `serde` serialize those types, use the `serialize_with` attribute to specify a serializer that exposes the secret. ### Available on `crate feature`serde` only. ### Dyn Compatibility This trait is **not** dyn compatible. _In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe._ ### Implementors (No specific implementors listed in the provided text) ``` -------------------------------- ### Borrow SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Immutably borrows the inner secret value from the `SecretBox`. This is part of the `Borrow` trait implementation. ```rust fn borrow(&self) -> &T> ``` -------------------------------- ### SecretBox Struct Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html The SecretBox struct is a wrapper type for values containing secrets, designed to minimize accidental exposure and ensure secrets are securely wiped from memory. ```APIDOC ## Struct SecretBox ### Description Wrapper type for values that contains secrets, which attempts to limit accidental exposure and ensure secrets are wiped from memory when dropped. (e.g. passwords, cryptographic keys, access tokens or other credentials) Access to the secret inner value occurs through the `ExposeSecret` or `ExposeSecretMut` traits, which provide methods for accessing the inner secret value. ``` -------------------------------- ### Expose Secret Value Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides immutable access to the inner secret value. This is the primary method for reading the secret. ```rust fn expose_secret(&self) -> &S> ``` -------------------------------- ### SecretString Type Source: https://docs.rs/secrecy/latest/secrecy/type.SecretString.html The SecretString type is an alias for SecretBox, designed to store sensitive string data securely. ```APIDOC ## SecretString ### Description A type alias for `SecretBox` that provides secure storage for sensitive strings. It supports conversion from `String` and `&str`. ### Type Definition `pub type SecretString = SecretBox;` ``` -------------------------------- ### ToOwned Trait Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Provides methods for creating owned data from borrowed data. ```APIDOC ## fn to_owned(&self) -> T ### Description Creates owned data from borrowed data, usually by cloning. ## fn clone_into(&self, target: &mut T) ### Description Uses borrowed data to replace owned data, usually by cloning. ``` -------------------------------- ### Borrow Mutably SecretBox Source: https://docs.rs/secrecy/latest/secrecy/struct.SecretBox.html Mutably borrows the inner secret value from the `SecretBox`. This is part of the `BorrowMut` trait implementation. ```rust fn borrow_mut(&mut self) -> &mut T> ``` -------------------------------- ### Core Goals of the Secrecy Crate Source: https://docs.rs/secrecy/latest/secrecy/index.html The primary goals of the secrecy crate are to make secret access explicit and auditable, prevent accidental leakage through channels like debug logging, and ensure secrets are securely wiped from memory upon drop. ```APIDOC ## Goals - Make secret access explicit and easy-to-audit via the `ExposeSecret` and `ExposeSecretMut` traits. - Prevent accidental leakage of secrets via channels like debug logging. - Ensure secrets are wiped from memory on drop securely (using the `zeroize` crate). Presently this crate favors a simple, `no_std`-friendly, safe i.e. `forbid(unsafe_code)`-based implementation and does not provide more advanced memory protection mechanisms e.g. ones based on `mlock(2)`/`mprotect(2)`. Those who don’t mind `std` and `libc` dependencies should consider using the `secrets` crate. ``` -------------------------------- ### Define SerializableSecret Trait Source: https://docs.rs/secrecy/latest/secrecy/trait.SerializableSecret.html This trait marks secret types that can be serialized by serde. It requires the 'serde' feature flag to be enabled. Use 'serialize_with' to explicitly serialize secrets if needed. ```rust pub trait SerializableSecret: Serialize { } ``` -------------------------------- ### Define SecretString type alias Source: https://docs.rs/secrecy/latest/secrecy/type.SecretString.html Defines the SecretString type as a SecretBox containing a string slice. ```rust pub type SecretString = SecretBox; ``` -------------------------------- ### Trait: CloneableSecret Source: https://docs.rs/secrecy/latest/secrecy/trait.CloneableSecret.html A marker trait for secrets which are allowed to be cloned. It requires the type to implement Clone and Zeroize. ```APIDOC ## Trait CloneableSecret ### Description Marker trait for secrets which are allowed to be cloned. This trait is not dyn compatible. ### Definition ```rust pub trait CloneableSecret: Clone + Zeroize { } ``` ### Implementations This trait is implemented for the following primitive types: - i8, i16, i32, i64, i128, isize - u8, u16, u32, u64, u128, usize ``` -------------------------------- ### Define SecretSlice Type Alias Source: https://docs.rs/secrecy/latest/secrecy/type.SecretSlice.html Defines SecretSlice as a type alias for SecretBox<[S]>, providing helpful trait implementations for secret slices. ```rust pub type SecretSlice = SecretBox<[S]>; ``` -------------------------------- ### Define ExposeSecretMut Trait in Rust Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecretMut.html Defines the ExposeSecretMut trait, which provides mutable access to an inner secret. This is the primary method for accessing secrets. ```rust pub trait ExposeSecretMut { // Required method fn expose_secret_mut(&mut self) -> &mut S; } ``` -------------------------------- ### Define CloneableSecret trait Source: https://docs.rs/secrecy/latest/secrecy/trait.CloneableSecret.html Marker trait for secrets which are allowed to be cloned. ```rust pub trait CloneableSecret: Clone + Zeroize { } ``` -------------------------------- ### ExposeSecret Trait Definition Source: https://docs.rs/secrecy/latest/secrecy/trait.ExposeSecret.html Defines the interface for accessing an inner secret value. Implementations must provide the expose_secret method to return a reference to the secret. ```rust pub trait ExposeSecret { // Required method fn expose_secret(&self) -> &S; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.