pub struct SignedEnvelope {
pub d: String,
pub f: String,
pub sig: String,
pub m: SignedEnvelopeMode,
pub e: Option<u64>,
pub v: u8,
}Expand description
A sealed, HMAC-authenticated envelope.
Carries data, its SHA-256 fingerprint, and an HMAC-SHA256 signature over the fingerprint. Unwrapping requires the same key used to sign.
§Example
use entrouter_universal::SignedEnvelope;
let env = SignedEnvelope::wrap("secret", "my-key");
assert_eq!(env.unwrap_verified("my-key").unwrap(), "secret");
assert!(env.unwrap_verified("wrong-key").is_err());Fields§
§d: StringEncoded data
f: StringSHA-256 fingerprint of the original raw input
sig: StringHMAC-SHA256 signature (hex) over the fingerprint
m: SignedEnvelopeModeEncoding mode
e: Option<u64>Optional expiry as Unix timestamp (seconds)
v: u8Version
Implementations§
Source§impl SignedEnvelope
impl SignedEnvelope
Sourcepub fn wrap_url_safe(input: &str, key: &str) -> Self
pub fn wrap_url_safe(input: &str, key: &str) -> Self
URL-safe Base64 wrap with HMAC signature.
Sourcepub fn wrap_compressed(input: &str, key: &str) -> Result<Self, UniversalError>
pub fn wrap_compressed(input: &str, key: &str) -> Result<Self, UniversalError>
Compressed wrap with HMAC signature.
Sourcepub fn wrap_with_ttl(input: &str, key: &str, ttl_secs: u64) -> Self
pub fn wrap_with_ttl(input: &str, key: &str, ttl_secs: u64) -> Self
TTL wrap with HMAC signature.
Sourcepub fn unwrap_verified(&self, key: &str) -> Result<String, UniversalError>
pub fn unwrap_verified(&self, key: &str) -> Result<String, UniversalError>
Verify HMAC signature, then decode and verify integrity.
Sourcepub fn to_json(&self) -> Result<String, UniversalError>
pub fn to_json(&self) -> Result<String, UniversalError>
Serialize to JSON.
Sourcepub fn from_json(s: &str) -> Result<Self, UniversalError>
pub fn from_json(s: &str) -> Result<Self, UniversalError>
Deserialize from JSON.
Trait Implementations§
Source§impl Clone for SignedEnvelope
impl Clone for SignedEnvelope
Source§fn clone(&self) -> SignedEnvelope
fn clone(&self) -> SignedEnvelope
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SignedEnvelope
impl Debug for SignedEnvelope
Source§impl<'de> Deserialize<'de> for SignedEnvelope
impl<'de> Deserialize<'de> for SignedEnvelope
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SignedEnvelope
impl RefUnwindSafe for SignedEnvelope
impl Send for SignedEnvelope
impl Sync for SignedEnvelope
impl Unpin for SignedEnvelope
impl UnsafeUnpin for SignedEnvelope
impl UnwindSafe for SignedEnvelope
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