pub struct EncryptedData(/* private fields */);Expand description
A newtype over Vec<u8> representing binary (non‑armored) age
encrypted data.
§Overview
This is the raw, binary output of age encryption when no armor is
requested. It is the complement of [ArmoredData]. The inner bytes are
the direct result of the age::Encryptor writer — a compact, but not
human‑readable, ciphertext.
§Why wrap a Vec<u8>?
Exactly the same reasons as ArmoredData:
- Type distinctness – prevents mixing up plaintext, encrypted data, and other byte buffers at the type level.
- Controlled construction –
newispub(crate), so only the encryption functions can create anEncryptedData. This guarantees that anyEncryptedDatayou hold came from a successful encryption operation. - Ergonomics – implements [
AsRef<[u8]>],Fromconversions, and provides accessor methods. The [Display] implementation shows only the byte length to avoid dumping binary data to the screen.
§Examples
use age_crypto::encrypt;
let encrypted: EncryptedData = encrypt(b"secret", &["age1..."]).unwrap();
println!("{}", encrypted); // [EncryptedData: 512 bytes]
let raw: &[u8] = encrypted.as_bytes();
let owned: Vec<u8> = encrypted.to_vec();Implementations§
Source§impl EncryptedData
impl EncryptedData
Trait Implementations§
Source§impl AsRef<[u8]> for EncryptedData
Allows &EncryptedData to be used wherever &[u8] is expected.
impl AsRef<[u8]> for EncryptedData
Allows &EncryptedData to be used wherever &[u8] is expected.
This means you can pass an EncryptedData directly to functions that
take a byte slice, such as write_all or copy_to.
Source§impl Clone for EncryptedData
impl Clone for EncryptedData
Source§fn clone(&self) -> EncryptedData
fn clone(&self) -> EncryptedData
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncryptedData
impl Debug for EncryptedData
Source§impl Display for EncryptedData
Displays a description showing the byte length only.
impl Display for EncryptedData
Displays a description showing the byte length only.
Printing raw binary data is seldom useful and could clutter output
or accidentally expose ciphertext. The Display implementation
limits itself to a short, human‑readable summary.
Source§impl From<EncryptedData> for Vec<u8>
Extracts the raw byte vector from the wrapper.
impl From<EncryptedData> for Vec<u8>
Extracts the raw byte vector from the wrapper.
This consumes the EncryptedData, giving you full ownership of the
underlying Vec<u8> without cloning.
Source§fn from(data: EncryptedData) -> Self
fn from(data: EncryptedData) -> Self
Source§impl From<Vec<u8>> for EncryptedData
Converts an owned Vec<u8> into an EncryptedData.
impl From<Vec<u8>> for EncryptedData
Converts an owned Vec<u8> into an EncryptedData.
Caution: No validation is performed. The caller must guarantee that the bytes constitute a valid age binary ciphertext. In normal use, only the encryption functions should use this conversion.