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
impl CoseMessage
Sourcepub fn new_sign() -> CoseMessage
pub fn new_sign() -> CoseMessage
Creates a new empty COSE signature (cose-sign1 and cose-sign) message structure.
Sourcepub fn new_encrypt() -> CoseMessage
pub fn new_encrypt() -> CoseMessage
Creates a new empty COSE encrypt (cose-encrypt0 and cose-encrypt) message structure.
Sourcepub fn new_mac() -> CoseMessage
pub fn new_mac() -> CoseMessage
Creates a new empty COSE MAC (cose-mac0 and cose-mac) message structure.
Sourcepub fn add_header(&mut self, header: CoseHeader)
pub fn add_header(&mut self, header: CoseHeader)
Add an header to the message.
Sourcepub fn add_agent(&mut self, agent: &mut CoseAgent) -> CoseResult
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.
Sourcepub fn get_agent(&self, kid: &Vec<u8>) -> CoseResultWithRet<Vec<usize>>
pub fn get_agent(&self, kid: &Vec<u8>) -> CoseResultWithRet<Vec<usize>>
Returns a signer/recipient (agent) of the message with a given Key ID.
Sourcepub fn key(&mut self, cose_key: &CoseKey) -> CoseResult
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.
Sourcepub fn counter_sig(
&self,
external_aad: Option<Vec<u8>>,
counter: &mut CoseAgent,
) -> CoseResult
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.
Sourcepub fn get_to_sign(
&self,
external_aad: Option<Vec<u8>>,
counter: &mut CoseAgent,
) -> CoseResultWithRet<Vec<u8>>
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.
Sourcepub fn get_to_verify(
&mut self,
external_aad: Option<Vec<u8>>,
counter: &usize,
) -> CoseResultWithRet<Vec<u8>>
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.
Sourcepub fn counters_verify(
&mut self,
external_aad: Option<Vec<u8>>,
counter: usize,
) -> CoseResult
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.
Sourcepub fn add_counter_sig(&mut self, counter: CoseAgent) -> CoseResult
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
Sourcepub fn secure_content(&mut self, external_aad: Option<Vec<u8>>) -> CoseResult
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.
Sourcepub fn encode(&mut self, data: bool) -> CoseResult
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.
Sourcepub fn init_decoder(&mut self, data: Option<Vec<u8>>) -> CoseResult
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.
Sourcepub fn decode(
&mut self,
external_aad: Option<Vec<u8>>,
agent: Option<usize>,
) -> CoseResultWithRet<Vec<u8>>
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.