pub trait Padded: ElGamalEncryptable {
// Provided methods
fn from_bytes_padded(data: &[u8]) -> Result<Self, Error>
where Self: Sized { ... }
fn from_string_padded(text: &str) -> Result<Self, Error>
where Self: Sized { ... }
fn to_string_padded(&self) -> Result<String, Error> { ... }
fn to_bytes_padded(&self) -> Result<Vec<u8>, Error> { ... }
}Expand description
A trait for encryptable types that support PKCS#7 padding for single-block (16 byte) encoding.
This trait provides methods to encode data up to 15 bytes using PKCS#7 padding, which fills the remaining bytes of a 16-byte block with padding bytes.
§Padding Format
- For
nbytes of data (0 ≤ n ≤ 15), add16 - npadding bytes - Each padding byte has the value
16 - n - This allows unambiguous removal of padding during decoding
§Examples
ⓘ
use libpep::data::padding::Padded;
use libpep::data::simple::Attribute;
// Encode a string
let attr = Attribute::from_string_padded("hello")?;
let decoded = attr.to_string_padded()?;
assert_eq!(decoded, "hello");
// Encode bytes
let attr = Attribute::from_bytes_padded(b"data")?;
let decoded = attr.to_bytes_padded()?;
assert_eq!(decoded, b"data");Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".