pub struct AesGcmCipher { /* private fields */ }Available on crate feature
encryption only.Expand description
AES-256-GCM cipher with a random 12-byte nonce prepended to each ciphertext.
The on-disk payload format is: [12-byte nonce][ciphertext + 16-byte GCM tag].
This is byte-compatible with monitor365’s EncryptionKey segment format,
so existing encrypted segments can be read without migration. (The segment
file envelope, if present, is stripped before the cipher sees the bytes.)
Implementations§
Source§impl AesGcmCipher
impl AesGcmCipher
Sourcepub fn from_slice(key_bytes: &[u8]) -> Result<Self, CipherError>
pub fn from_slice(key_bytes: &[u8]) -> Result<Self, CipherError>
Create a new cipher from a 32-byte AES-256 key.
§Example
use segment_buffer::AesGcmCipher;
let key = [0u8; 32];
let _cipher = AesGcmCipher::from_slice(&key).unwrap();§Errors
Returns CipherError if the key length is not 32 bytes.
Sourcepub fn new(key_bytes: &[u8; 32]) -> Self
pub fn new(key_bytes: &[u8; 32]) -> Self
Create a new cipher from a 32-byte AES-256 key (const-sized input).
Because the key length is fixed at compile time, construction is
infallible — unlike from_slice, which must
validate runtime slice length.
§Example
use segment_buffer::AesGcmCipher;
use segment_buffer::SegmentCipher;
let cipher = AesGcmCipher::new(&[0u8; 32]);
let ciphertext = cipher.encrypt(b"hello").unwrap();
let plaintext = cipher.decrypt(&ciphertext).unwrap();
assert_eq!(plaintext, b"hello");Trait Implementations§
Source§impl SegmentCipher for AesGcmCipher
impl SegmentCipher for AesGcmCipher
Auto Trait Implementations§
impl Freeze for AesGcmCipher
impl RefUnwindSafe for AesGcmCipher
impl Send for AesGcmCipher
impl Sync for AesGcmCipher
impl Unpin for AesGcmCipher
impl UnsafeUnpin for AesGcmCipher
impl UnwindSafe for AesGcmCipher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more