pub struct CoseSigned<T> { /* private fields */ }Expand description
Generic COSE_Sign1 signed envelope wrapping a payload T.
Implementations§
Source§impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn sign_ed25519(
payload: &T,
kid: &str,
signing_key: &SigningKey,
) -> Result<Self, CoseError>
pub fn sign_ed25519( payload: &T, kid: &str, signing_key: &SigningKey, ) -> Result<Self, 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 Ed25519 signature and returns the payload.
Source§impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
impl<T> CoseSigned<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn kid(&self) -> Option<String>
pub fn kid(&self) -> Option<String>
Returns the key identifier (kid) from the protected header.
The kid can be a SPIFFE ID, DID, URL, or any resolvable identifier that can be used to obtain the public key for verification.
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.
These are the exact signed artifact bytes: every Profile 0.2 hash
(root.pca_hash, predecessor.hash) is computed over them.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, CoseError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, 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 only where the specification treats the artifact as untrusted input to be parsed before validation.
Sourcepub fn sign_with<F>(
payload: &T,
kid: &str,
alg: SigningAlgorithm,
sign_fn: F,
) -> Result<Self, CoseError>
pub fn sign_with<F>( payload: &T, kid: &str, alg: SigningAlgorithm, sign_fn: F, ) -> Result<Self, CoseError>
Signs a payload using a custom signing function (crypto-agnostic).
The closure receives the to-be-signed bytes and returns the signature.
Sourcepub fn verify_with<F>(&self, verify_fn: F) -> Result<T, CoseError>
pub fn verify_with<F>(&self, verify_fn: F) -> Result<T, CoseError>
Verifies the signature using a custom verification function.
The closure receives (data, signature) and returns Ok(()) if valid.
Sourcepub fn check_algorithm(
&self,
expected: SigningAlgorithm,
) -> Result<(), CoseError>
pub fn check_algorithm( &self, expected: SigningAlgorithm, ) -> Result<(), CoseError>
Validates that the envelope’s algorithm matches the expected one.
Trait Implementations§
Source§impl<T: Clone> Clone for CoseSigned<T>
impl<T: Clone> Clone for CoseSigned<T>
Source§fn clone(&self) -> CoseSigned<T>
fn clone(&self) -> CoseSigned<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more