Skip to main content

Alphabet

Trait Alphabet 

Source
pub trait Alphabet {
    const ENCODE: [u8; 64];

    // Required method
    fn decode(byte: u8) -> Option<u8>;

    // Provided method
    fn encode(value: u8) -> u8 { ... }
}
Expand description

A Base64 alphabet.

§Security

The default Alphabet::encode implementation is constant-time-oriented: it scans all 64 alphabet entries instead of using ENCODE[value as usize]. Direct callers that override encode with a table lookup make those direct calls timing-sensitive with respect to the selected 6-bit value. Public Engine encoding does not call this overridable method: Alphabet::ENCODE is its sole output definition for const, scalar, SIMD, wrapped, and in-place surfaces.

Public Engine decoding also treats Alphabet::ENCODE as authoritative and does not call Alphabet::decode. This prevents mutable or otherwise stateful method overrides from changing results across scalar and SIMD backends. The ct module independently scans the same table with its fixed-work mapper. Direct calls to an overridden decode method retain that implementation’s behavior and timing.

Required Associated Constants§

Source

const ENCODE: [u8; 64]

Encoding table indexed by 6-bit values.

Required Methods§

Source

fn decode(byte: u8) -> Option<u8>

Decode one byte into a 6-bit value.

Implementations that want conservative custom-alphabet timing posture should delegate to decode_alphabet_byte, which scans all 64 entries before returning. This method is retained as a public low-level mapping helper for API compatibility; Engine and the ct module ignore it and derive mappings from Self::ENCODE directly.

Provided Methods§

Source

fn encode(value: u8) -> u8

Encode one 6-bit value into an alphabet byte.

The default implementation scans the alphabet table instead of using a secret-indexed table lookup. Built-in alphabets override this with the branch-minimized ASCII arithmetic mapper. Custom alphabets that keep the default method prioritize timing posture over throughput for direct calls. This method is retained as a public low-level mapping helper for API compatibility; Engine uses Self::ENCODE directly and is unaffected by overrides.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§