Skip to main content

CtEngine

Struct CtEngine 

Source
pub struct CtEngine<A, const PAD: bool> { /* private fields */ }
Expand description

A zero-sized constant-time-oriented Base64 decoder.

Implementations§

Source§

impl<A, const PAD: bool> CtEngine<A, PAD>
where A: Alphabet,

Source

pub const fn new() -> Self

Creates a new constant-time-oriented decoder engine.

Source

pub const fn is_padded(&self) -> bool

Returns whether this constant-time-oriented decoder expects padded input.

Source

pub fn validate_result(&self, input: &[u8]) -> Result<(), DecodeError>

Validates input without writing decoded bytes.

This uses the same constant-time-oriented symbol mapping and opaque malformed-input error behavior as Self::decode_slice. Input length, padding length, and final success or failure remain public.

§Examples
use base64_ng::ct;

ct::STANDARD.validate_result(b"aGVsbG8=").unwrap();
assert!(ct::STANDARD.validate_result(b"aGVsbG8").is_err());
Source

pub fn validate(&self, input: &[u8]) -> bool

Returns whether input is valid for this constant-time-oriented decoder.

This is a convenience wrapper around Self::validate_result.

§Examples
use base64_ng::ct;

assert!(ct::URL_SAFE_NO_PAD.validate(b"-_8"));
assert!(!ct::URL_SAFE_NO_PAD.validate(b"+/8"));
Source

pub fn decoded_len(&self, input: &[u8]) -> Result<usize, DecodeError>

Returns the exact decoded length for valid input.

This uses the same constant-time-oriented validation policy as Self::decode_slice before returning a length. Input length, padding length, and final success or failure remain public.

Source

pub fn decode_slice( &self, input: &[u8], output: &mut [u8], ) -> Result<usize, DecodeError>

Decodes input into output, returning the number of bytes written.

This path uses a fixed alphabet scan for Base64 symbol mapping and avoids secret-indexed lookup tables. Input length, padding length, output length, and final success or failure remain public. Malformed content errors are intentionally opaque and non-localized; use the normal strict decoder when exact diagnostics are required.

§Examples
use base64_ng::ct;

let mut output = [0u8; 5];
let written = ct::STANDARD
    .decode_slice(b"aGVsbG8=", &mut output)
    .unwrap();

assert_eq!(&output[..written], b"hello");
Source

pub fn decode_slice_clear_tail( &self, input: &[u8], output: &mut [u8], ) -> Result<usize, DecodeError>

Decodes input into output and clears all bytes after the decoded prefix.

If decoding fails, the entire output buffer is cleared before the error is returned. Use this variant for sensitive payloads where partially decoded bytes from rejected input should not remain in the caller-owned output buffer.

§Examples
use base64_ng::ct;

let mut output = [0xff; 8];
let written = ct::STANDARD
    .decode_slice_clear_tail(b"aGk=", &mut output)
    .unwrap();

assert_eq!(&output[..written], b"hi");
assert!(output[written..].iter().all(|byte| *byte == 0));
Source

pub fn decode_buffer<const CAP: usize>( &self, input: &[u8], ) -> Result<DecodedBuffer<CAP>, DecodeError>

Decodes input into a stack-backed buffer.

This uses the same constant-time-oriented scalar decoder as Self::decode_slice_clear_tail and clears the internal backing array before returning an error.

§Examples
use base64_ng::ct;

let decoded = ct::STANDARD.decode_buffer::<5>(b"aGVsbG8=").unwrap();

assert_eq!(decoded.as_bytes(), b"hello");
Source

pub fn decode_in_place<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], DecodeError>

Decodes buffer in place and returns the decoded prefix.

This uses the constant-time-oriented scalar decoder while reading each Base64 quantum into local values before writing decoded bytes back to the front of the same buffer.

§Examples
use base64_ng::ct;

let mut buffer = *b"aGk=";
let decoded = ct::STANDARD.decode_in_place(&mut buffer).unwrap();

assert_eq!(decoded, b"hi");
Source

pub fn decode_in_place_clear_tail<'a>( &self, buffer: &'a mut [u8], ) -> Result<&'a mut [u8], DecodeError>

Decodes buffer in place and clears all bytes after the decoded prefix.

If decoding fails, the entire buffer is cleared before the error is returned.

§Examples
use base64_ng::ct;

let mut buffer = *b"aGk=";
let decoded = ct::STANDARD.decode_in_place_clear_tail(&mut buffer).unwrap();

assert_eq!(decoded, b"hi");

Trait Implementations§

Source§

impl<A: Clone, const PAD: bool> Clone for CtEngine<A, PAD>

Source§

fn clone(&self) -> CtEngine<A, PAD>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug, const PAD: bool> Debug for CtEngine<A, PAD>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Default, const PAD: bool> Default for CtEngine<A, PAD>

Source§

fn default() -> CtEngine<A, PAD>

Returns the “default value” for a type. Read more
Source§

impl<A, const PAD: bool> Display for CtEngine<A, PAD>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: PartialEq, const PAD: bool> PartialEq for CtEngine<A, PAD>

Source§

fn eq(&self, other: &CtEngine<A, PAD>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: Copy, const PAD: bool> Copy for CtEngine<A, PAD>

Source§

impl<A: Eq, const PAD: bool> Eq for CtEngine<A, PAD>

Source§

impl<A, const PAD: bool> StructuralPartialEq for CtEngine<A, PAD>

Auto Trait Implementations§

§

impl<A, const PAD: bool> Freeze for CtEngine<A, PAD>

§

impl<A, const PAD: bool> RefUnwindSafe for CtEngine<A, PAD>
where A: RefUnwindSafe,

§

impl<A, const PAD: bool> Send for CtEngine<A, PAD>
where A: Send,

§

impl<A, const PAD: bool> Sync for CtEngine<A, PAD>
where A: Sync,

§

impl<A, const PAD: bool> Unpin for CtEngine<A, PAD>
where A: Unpin,

§

impl<A, const PAD: bool> UnsafeUnpin for CtEngine<A, PAD>

§

impl<A, const PAD: bool> UnwindSafe for CtEngine<A, PAD>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.