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,
impl<A, const PAD: bool> CtEngine<A, PAD>where
A: Alphabet,
Sourcepub fn decode_slice(
&self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, DecodeError>
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 branch-minimized arithmetic for Base64 symbol mapping and avoids secret-indexed lookup tables. Input length, padding length, output length, and final success or failure remain public. Malformed input errors are intentionally non-localized; use the normal strict decoder when exact error indexes 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");Sourcepub fn decode_slice_clear_tail(
&self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, DecodeError>
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));Sourcepub fn decode_in_place<'a>(
&self,
buffer: &'a mut [u8],
) -> Result<&'a mut [u8], DecodeError>
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");Sourcepub fn decode_in_place_clear_tail<'a>(
&self,
buffer: &'a mut [u8],
) -> Result<&'a mut [u8], DecodeError>
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");