pub struct CoseSigned<T> { /* private fields */ }Expand description
Generic COSE_Sign1 signed envelope.
Wraps any serializable payload T with a COSE_Sign1 signature.
Implementations§
Source§impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn algorithm(&self) -> Option<SigningAlgorithm>
pub fn algorithm(&self) -> Option<SigningAlgorithm>
Returns the signing algorithm from the protected header.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, CoseError>
pub fn to_bytes(&self) -> Result<Vec<u8>, CoseError>
Serializes the signed envelope to CBOR bytes.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<CoseSigned<T>, CoseError>
pub fn from_bytes(bytes: &[u8]) -> Result<CoseSigned<T>, CoseError>
Deserializes a signed envelope from CBOR bytes.
Sourcepub fn payload_unverified(&self) -> Result<T, CoseError>
pub fn payload_unverified(&self) -> Result<T, CoseError>
Extracts the payload without verifying the signature.
Use with caution: this bypasses signature verification.
Sourcepub fn sign_with<F>(
payload: &T,
issuer: &str,
alg: SigningAlgorithm,
sign_fn: F,
) -> Result<CoseSigned<T>, CoseError>
pub fn sign_with<F>( payload: &T, issuer: &str, alg: SigningAlgorithm, sign_fn: F, ) -> Result<CoseSigned<T>, CoseError>
Signs a payload using a custom signing function (crypto-agnostic).
The closure receives the to-be-signed bytes and returns the signature.
Source§impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn sign_ed25519(
payload: &T,
issuer: &str,
signing_key: &SigningKey,
) -> Result<CoseSigned<T>, CoseError>
pub fn sign_ed25519( payload: &T, issuer: &str, signing_key: &SigningKey, ) -> Result<CoseSigned<T>, CoseError>
Signs payload with Ed25519. Algorithm is set to EdDSA automatically.
Sourcepub fn verify_ed25519(
&self,
verifying_key: &VerifyingKey,
) -> Result<T, CoseError>
pub fn verify_ed25519( &self, verifying_key: &VerifyingKey, ) -> Result<T, CoseError>
Verifies payload with Ed25519. Returns error if algorithm is not EdDSA.
Trait Implementations§
Source§impl<T> Clone for CoseSigned<T>where
T: Clone,
impl<T> Clone for CoseSigned<T>where
T: Clone,
Source§fn clone(&self) -> CoseSigned<T>
fn clone(&self) -> CoseSigned<T>
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 moreAuto Trait Implementations§
impl<T> Freeze for CoseSigned<T>
impl<T> RefUnwindSafe for CoseSigned<T>where
T: RefUnwindSafe,
impl<T> Send for CoseSigned<T>where
T: Send,
impl<T> Sync for CoseSigned<T>where
T: Sync,
impl<T> Unpin for CoseSigned<T>where
T: Unpin,
impl<T> UnwindSafe for CoseSigned<T>where
T: UnwindSafe,
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