Skip to main content

Envelope

Struct Envelope 

Source
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: String

Encoded data - opaque to every layer

§f: String

SHA-256 fingerprint of the ORIGINAL raw input (before compression)

§m: EnvelopeMode

Encoding mode

§e: Option<u64>

Optional expiry as Unix timestamp (seconds)

§v: u8

Version

Implementations§

Source§

impl Envelope

Source

pub fn wrap(input: &str) -> Self

Standard Base64 wrap.

Source

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.

Source

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.

Source

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.

Source

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
Source

pub fn unwrap_raw(&self) -> Result<String, UniversalError>

Decode without verification - use when you trust the source.

Source

pub fn is_expired(&self) -> bool

Returns true if this envelope has expired (TTL mode only).

Source

pub fn ttl_remaining(&self) -> Option<u64>

Seconds remaining until expiry. None if no TTL set.

Source

pub fn is_intact(&self) -> bool

Returns true if the data passes integrity verification.

Convenience wrapper around Envelope::unwrap_verified.

Source

pub fn fingerprint(&self) -> &str

Returns the SHA-256 fingerprint of the original data.

Source

pub fn mode(&self) -> EnvelopeMode

Returns the EnvelopeMode used to create this envelope.

Source

pub fn to_json(&self) -> Result<String, UniversalError>

Serialize this envelope to a JSON string.

Source

pub fn from_json(s: &str) -> Result<Self, UniversalError>

Deserialize an envelope from a JSON string.

Trait Implementations§

Source§

impl Clone for Envelope

Source§

fn clone(&self) -> Envelope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Envelope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Envelope

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Envelope

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,