Skip to main content

const_secret/
align.rs

1//! Alignment wrapper types for forcing specific memory alignment.
2//!
3//! This module provides newtype wrappers that force specific alignment
4//! for the inner type. This is useful when you need to ensure that
5//! encrypted data has a particular memory alignment.
6//!
7//! # Types
8//!
9//! - [`Aligned8`]: Forces 8-byte alignment
10//! - [`Aligned16`]: Forces 16-byte alignment
11//!
12//! # Example
13//!
14//! ```rust
15//! use const_secret::{
16//!     align::Aligned16,
17//!     Encrypted, ByteArray,
18//!     drop_strategy::Zeroize,
19//!     xor::Xor,
20//! };
21//!
22//! // Ensure the encrypted data is 16-byte aligned
23//! const SECRET: Aligned16<Encrypted<Xor<0xAA, Zeroize>, ByteArray, 16>> =
24//!     Aligned16(Encrypted::<Xor<0xAA, Zeroize>, ByteArray, 16>::new([0u8; 16]));
25//!
26//! fn main() {
27//!     // Access the inner encrypted data
28//!     let _inner: &Encrypted<Xor<0xAA, Zeroize>, ByteArray, 16> = &SECRET.0;
29//! }
30//! ```
31
32#[repr(align(8))]
33#[derive(Debug)]
34pub struct Aligned8<E>(pub E);
35
36#[repr(align(16))]
37#[derive(Debug)]
38pub struct Aligned16<E>(pub E);