pub struct EncryptedPathCodec { /* private fields */ }Expand description
Encrypting codec: shadow paths are opaque v1.<base64url> blobs.
Real paths are AES-256-GCM encrypted with a server-held key; the ciphertext carries a random 96-bit nonce and a 128-bit auth tag, so the shadow is unreadable and unforgeable (tampering fails the tag check at decode time). Encrypting the same path twice yields different shadows: a listing leaks nothing, not even equality of paths.
Shadow format: v1. + base64url(no-pad) of nonce(12) ‖ ciphertext+tag.
use libfw_core::pathmap::{EncryptedPathCodec, PathCodec};
let codec = EncryptedPathCodec::from_hex(
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
).unwrap();
let shadow = codec.encode("docs/机密/plan.pdf");
assert_ne!(shadow, "docs/机密/plan.pdf");
assert_eq!(codec.decode(&shadow).unwrap(), "docs/机密/plan.pdf");
// the same path encrypts differently every time
assert_ne!(codec.encode("docs/机密/plan.pdf"), shadow);
// tampered shadows are rejected
let mut bad = shadow.into_bytes();
let n = bad.len();
bad[n - 1] = if bad[n - 1] == b'A' { b'B' } else { b'A' };
assert!(codec.decode(&String::from_utf8(bad).unwrap()).is_err());Implementations§
Source§impl EncryptedPathCodec
impl EncryptedPathCodec
Sourcepub fn new(key: [u8; 32]) -> Self
pub fn new(key: [u8; 32]) -> Self
Build the codec from a 32-byte key.
§Panics
If the host has no usable OS CSPRNG: AES-GCM nonces must be
unpredictable (see random_bytes), so the codec refuses to exist
rather than silently emit predictable nonces. Use
EncryptedPathCodec::from_hex to get this as a recoverable error.
Sourcepub fn from_hex(hex: &str) -> Result<Self, PathCodecError>
pub fn from_hex(hex: &str) -> Result<Self, PathCodecError>
Build the codec from a 64-char hex key (32 bytes).
Trait Implementations§
Source§impl Clone for EncryptedPathCodec
impl Clone for EncryptedPathCodec
Source§impl Debug for EncryptedPathCodec
Available on crate feature path-encrypt only.
impl Debug for EncryptedPathCodec
path-encrypt only.