pub struct Base64String<S: Codec> { /* private fields */ }Expand description
An owned ordinary Base64 string validated by one exact codec policy.
The value retains the Base64<S> used to encode or validate its text, so
its decode methods cannot accidentally select a different
alphabet, padding, or trailing-bit policy. Construction either encodes
bytes through that codec or validates complete encoded text before
ownership is returned. There is deliberately no mutable string access.
This is an ordinary, visibly printable, cloneable value. It performs no
cleanup and is not suitable for keys, tokens, passwords, or other secret
material. Use the secret module for secret-bearing data.
Implementations§
Source§impl<S: Codec> Base64String<S>
impl<S: Codec> Base64String<S>
Sourcepub fn encode(codec: Base64<S>, input: &[u8]) -> Result<Self, OneShotError>
pub fn encode(codec: Base64<S>, input: &[u8]) -> Result<Self, OneShotError>
Encodes bytes and retains the exact codec policy with the result.
Allocation and length errors use the same contract as
Base64::encode_to_string.
Sourcepub fn from_string(
codec: Base64<S>,
encoded: String,
) -> Result<Self, OneShotError>
pub fn from_string( codec: Base64<S>, encoded: String, ) -> Result<Self, OneShotError>
Validates and adopts an existing owned string without copying it.
The complete string must satisfy the supplied codec’s decode policy. On error, this function consumes and drops the supplied ordinary string.
Sourcepub fn parse(codec: Base64<S>, encoded: &str) -> Result<Self, OneShotError>
pub fn parse(codec: Base64<S>, encoded: &str) -> Result<Self, OneShotError>
Validates and copies an encoded string slice into owned storage.
Validation completes before allocation. The copy uses
try_reserve_exact, returning OneShotError::AllocationFailed if the
reservation cannot be made.
Sourcepub fn settings(&self) -> CodecSettings
pub fn settings(&self) -> CodecSettings
Returns the retained codec settings.
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the validated encoded text.
Passing this ordinary view to another codec can deliberately discard
the retained policy. Use Self::decode to preserve it.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the validated encoded bytes.
Passing this ordinary view to another codec can deliberately discard
the retained policy. Use Self::decode to preserve it.
Sourcepub fn decode(&self) -> Result<Vec<u8>, OneShotError>
pub fn decode(&self) -> Result<Vec<u8>, OneShotError>
Decodes the validated text with its retained codec.
Sourcepub fn decode_with_limit(
&self,
max_output_len: usize,
) -> Result<Vec<u8>, OneShotError>
pub fn decode_with_limit( &self, max_output_len: usize, ) -> Result<Vec<u8>, OneShotError>
Decodes with an exact maximum output length.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Consumes the wrapper and returns the validated ordinary string.
The returned String no longer carries the codec policy.
Trait Implementations§
Source§impl<S: Clone + Codec> Clone for Base64String<S>
impl<S: Clone + Codec> Clone for Base64String<S>
Source§fn clone(&self) -> Base64String<S>
fn clone(&self) -> Base64String<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more