Struct CoseMessage

Source
pub struct CoseMessage {
    pub header: CoseHeader,
    pub payload: Vec<u8>,
    pub bytes: Vec<u8>,
    pub agents: Vec<CoseAgent>,
    /* private fields */
}
Expand description

Structure to encode/decode cose-sign and cose-sign1 messages

Fields§

§header: CoseHeader

The header parameters of the message.

§payload: Vec<u8>

The payload of the message.

§bytes: Vec<u8>

The COSE encoded message.

§agents: Vec<CoseAgent>

The signers/recipients of the message, empty if cose-sign1, cose-encrypt0 and cose-mac0 message type.

Implementations§

Source§

impl CoseMessage

Source

pub fn new_sign() -> CoseMessage

Creates a new empty COSE signature (cose-sign1 and cose-sign) message structure.

Source

pub fn new_encrypt() -> CoseMessage

Creates a new empty COSE encrypt (cose-encrypt0 and cose-encrypt) message structure.

Source

pub fn new_mac() -> CoseMessage

Creates a new empty COSE MAC (cose-mac0 and cose-mac) message structure.

Source

pub fn add_header(&mut self, header: CoseHeader)

Add an header to the message.

Source

pub fn payload(&mut self, payload: Vec<u8>)

Add the payload to the message.

Source

pub fn add_agent(&mut self, agent: &mut CoseAgent) -> CoseResult

Adds a signer/recipient (agent) to the message.

Used for cose-sign, cose-mac and cose-encrypt messages.

Source

pub fn get_agent(&self, kid: &Vec<u8>) -> CoseResultWithRet<Vec<usize>>

Returns a signer/recipient (agent) of the message with a given Key ID.

Source

pub fn key(&mut self, cose_key: &CoseKey) -> CoseResult

Adds a cose-key to the message.

This option is only available for the cose-sign1, cose-encrypt0 and cose-mac0 message types, since when using this message types, the keys are respective to each signer/recipient.

Source

pub fn counter_sig( &self, external_aad: Option<Vec<u8>>, counter: &mut CoseAgent, ) -> CoseResult

Adds a counter signature to the message.

The counter signature structure is the same type as the signers/recipients structure and it should be used the function new_counter_sig to initiate the structure.

Source

pub fn get_to_sign( &self, external_aad: Option<Vec<u8>>, counter: &mut CoseAgent, ) -> CoseResultWithRet<Vec<u8>>

Function to get the content to sign by the counter signature.

This function is meant to be called if the counter signature process needs to be external to this crate, like a timestamp authority.

Source

pub fn get_to_verify( &mut self, external_aad: Option<Vec<u8>>, counter: &usize, ) -> CoseResultWithRet<Vec<u8>>

Function to get the content to verify with the counter signature.

This function is meant to be called if the counter signature process needs to be external to this crate, like a timestamp authority.

Source

pub fn counters_verify( &mut self, external_aad: Option<Vec<u8>>, counter: usize, ) -> CoseResult

Function that verifies a given counter signature on the COSE message.

Source

pub fn add_counter_sig(&mut self, counter: CoseAgent) -> CoseResult

Function that adds a counter signature which was signed externally with the use of get_to_sign

Source

pub fn secure_content(&mut self, external_aad: Option<Vec<u8>>) -> CoseResult

Function to secure the content, sign, encrypt or mac depending on the COSE message type.

external_aad parameter is used when it is desired to have an additional authentication data to reinforce security of the signature.

Source

pub fn encode(&mut self, data: bool) -> CoseResult

Function to encode the COSE message after the content is secured by gen_signature.

The data parameter is used to specified if the payload/ciphertext shall be present or not in the message.

Source

pub fn init_decoder(&mut self, data: Option<Vec<u8>>) -> CoseResult

Function to decode the initial parts of the COSE message, in order to access the required parameters to fully decode the message with decode

This function requires that the attribute bytes is set in the structure with the COSE encoded message beforehand.

if the payload/ciphertext is not included in the COSE message, it needs to be provided in the data parameter.

Source

pub fn decode( &mut self, external_aad: Option<Vec<u8>>, agent: Option<usize>, ) -> CoseResultWithRet<Vec<u8>>

Function to verify/decrypt the secured content of the COSE message.

external_add is used in case of an AAD is included.

agent parameter must be None if the type of the message is cose-sign1, cose-encrypt0 or cose-mac0 and in case of being a cose-sign, cose-mac or cose-encrypt message type, the index of the signer/recipient of the message must be given with the respective key already added to the same signer/recipient.

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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V