pub struct Envelope {
pub d: String,
pub f: String,
pub m: EnvelopeMode,
pub e: Option<u64>,
pub v: u8,
}Expand description
A sealed envelope that carries data, its SHA-256 fingerprint, and an encoding mode.
§Example
use entrouter_universal::Envelope;
let env = Envelope::wrap("secret payload");
assert_eq!(env.unwrap_verified().unwrap(), "secret payload");Fields§
§d: StringEncoded data - opaque to every layer
f: StringSHA-256 fingerprint of the ORIGINAL raw input (before compression)
m: EnvelopeModeEncoding mode
e: Option<u64>Optional expiry as Unix timestamp (seconds)
v: u8Version
Implementations§
Source§impl Envelope
impl Envelope
Sourcepub fn wrap_url_safe(input: &str) -> Self
pub fn wrap_url_safe(input: &str) -> Self
URL-safe Base64 wrap.
Use when passing through URLs, query params, or HTTP headers.
Uses - and _ instead of + and /. No padding.
Sourcepub fn wrap_compressed(input: &str) -> Result<Self, UniversalError>
pub fn wrap_compressed(input: &str) -> Result<Self, UniversalError>
Compressed wrap - gzip then Base64. Use for large payloads. Transparent to consumer - unwrap_verified() returns the original uncompressed string.
Sourcepub fn wrap_with_ttl(input: &str, ttl_secs: u64) -> Self
pub fn wrap_with_ttl(input: &str, ttl_secs: u64) -> Self
TTL wrap - standard Base64 with an expiry time. unwrap_verified() returns Err if the envelope has expired.
Sourcepub fn unwrap_verified(&self) -> Result<String, UniversalError>
pub fn unwrap_verified(&self) -> Result<String, UniversalError>
Decode and verify integrity at the exit point. Works for all modes. Returns Err on:
- Integrity violation (data mutated in transit)
- Expired TTL
- Decode/decompress failure
Sourcepub fn unwrap_raw(&self) -> Result<String, UniversalError>
pub fn unwrap_raw(&self) -> Result<String, UniversalError>
Decode without verification - use when you trust the source.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns true if this envelope has expired (TTL mode only).
Sourcepub fn ttl_remaining(&self) -> Option<u64>
pub fn ttl_remaining(&self) -> Option<u64>
Seconds remaining until expiry. None if no TTL set.
Sourcepub fn is_intact(&self) -> bool
pub fn is_intact(&self) -> bool
Returns true if the data passes integrity verification.
Convenience wrapper around Envelope::unwrap_verified.
Sourcepub fn fingerprint(&self) -> &str
pub fn fingerprint(&self) -> &str
Returns the SHA-256 fingerprint of the original data.
Sourcepub fn mode(&self) -> EnvelopeMode
pub fn mode(&self) -> EnvelopeMode
Returns the EnvelopeMode used to create this envelope.
Sourcepub fn to_json(&self) -> Result<String, UniversalError>
pub fn to_json(&self) -> Result<String, UniversalError>
Serialize this envelope to a JSON string.
Sourcepub fn from_json(s: &str) -> Result<Self, UniversalError>
pub fn from_json(s: &str) -> Result<Self, UniversalError>
Deserialize an envelope from a JSON string.