pub trait BlockCrypt:
Send
+ Sync
+ Debug {
// Required methods
fn encrypt(&self, dst: &mut [u8], src: &[u8]);
fn decrypt(&self, dst: &mut [u8], src: &[u8]);
// Provided methods
fn header_size(&self) -> usize { ... }
fn overhead(&self) -> usize { ... }
fn nonce_size(&self) -> usize { ... }
fn seal(
&self,
dst: &mut [u8],
nonce: &[u8],
plaintext: &[u8],
) -> Result<usize, String> { ... }
fn open(
&self,
dst: &mut [u8],
nonce: &[u8],
ciphertext: &[u8],
) -> Result<usize, String> { ... }
fn is_aead(&self) -> bool { ... }
}Expand description
BlockCrypt trait 定义加密/解密方法
参考 kcp-go 的 BlockCrypt 接口
Required Methods§
Provided Methods§
Sourcefn header_size(&self) -> usize
fn header_size(&self) -> usize
获取加密头部大小
Sourcefn nonce_size(&self) -> usize
fn nonce_size(&self) -> usize
获取 nonce 大小
CFB 模式使用固定的 16 字节 nonce AEAD 模式(如 AES-GCM)使用 12 字节 nonce