Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::COSEMessage Class Reference

Implementation of COSE_Sign1 message format as specified in RFC 8152. More...

#include <COSEMessage.h>

Public Member Functions

 COSEMessage (COSEMessage const &)=delete
 Copy constructor disabled.
 
void operator= (COSEMessage const &)=delete
 Assignment operator disabled.
 
 COSEMessage ()
 Default constructor.
 
 COSEMessage (Bytes buf)
 Constructs a message from existing CBOR data.
 
virtual ~COSEMessage ()
 Destructor.
 
bool read (const Bytes &buf)
 Reads a CBOR-encoded COSE_Sign1 message.
 
bool wasReadSuccessful () const
 Checks if the message was read successfully.
 
Bytes getProtectedHeader ()
 Gets the protected header as a byte string.
 
CBORObject getUnprotectedHeader ()
 Gets the unprotected header as a CBORObject.
 
Bytes getUnprotectedKid ()
 Gets the key identifier from the unprotected header.
 
Bytes getPayload ()
 Gets the payload of the message.
 
Bytes getSignature ()
 Gets the signature of the message.
 
bool isSigned ()
 Checks if the message has a valid signature structure.
 
void setUnprotectedKid (const Bytes &kid)
 Sets the key identifier in the unprotected header.
 
bool setPayload (const Bytes &payload)
 Sets the payload of the message.
 
void sign (const ICOSESigner &signer, const Bytes &external=Bytes())
 Signs the message using the provided signer.
 
bool verify (const Bytes &publicKey)
 Verifies the signature of the message using the provided public key.
 
Bytes build () const
 Builds the CBOR representation of the message.
 
void clean ()
 Resets the message to its initial empty state.
 

Detailed Description

Implementation of COSE_Sign1 message format as specified in RFC 8152.

This class provides functionality to create, read, sign, and verify COSE_Sign1 messages. It implements the message structure defined in section 4.2 of RFC 8152. The class supports EdDSA signatures (algorithm -8).

Constructor & Destructor Documentation

◆ COSEMessage() [1/3]

uniot::COSEMessage::COSEMessage ( COSEMessage const & )
delete

Copy constructor disabled.

◆ COSEMessage() [2/3]

uniot::COSEMessage::COSEMessage ( )
inline

Default constructor.

Creates an empty COSE_Sign1 message with default structure

◆ COSEMessage() [3/3]

uniot::COSEMessage::COSEMessage ( Bytes buf)
inline

Constructs a message from existing CBOR data.

Parameters
bufCBOR-encoded COSE_Sign1 message

◆ ~COSEMessage()

virtual uniot::COSEMessage::~COSEMessage ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ build()

Bytes uniot::COSEMessage::build ( ) const
inline

Builds the CBOR representation of the message.

Return values
BytesContains the CBOR-encoded message

◆ clean()

void uniot::COSEMessage::clean ( )
inline

Resets the message to its initial empty state.

◆ getPayload()

Bytes uniot::COSEMessage::getPayload ( )
inline

Gets the payload of the message.

Return values
BytesContains the payload data

◆ getProtectedHeader()

Bytes uniot::COSEMessage::getProtectedHeader ( )
inline

Gets the protected header as a byte string.

Return values
BytesContains the CBOR-encoded protected header

◆ getSignature()

Bytes uniot::COSEMessage::getSignature ( )
inline

Gets the signature of the message.

Return values
BytesContains the signature

◆ getUnprotectedHeader()

CBORObject uniot::COSEMessage::getUnprotectedHeader ( )
inline

Gets the unprotected header as a CBORObject.

Return values
CBORObjectRepresents the unprotected header

◆ getUnprotectedKid()

Bytes uniot::COSEMessage::getUnprotectedKid ( )
inline

Gets the key identifier from the unprotected header.

Return values
BytesContains the key identifier (kid)
BytesEmpty if the key identifier is not present

◆ isSigned()

bool uniot::COSEMessage::isSigned ( )
inline

Checks if the message has a valid signature structure.

Return values
trueThe message is signed (has an algorithm and non-empty signature)
falseThe message is not signed

◆ operator=()

void uniot::COSEMessage::operator= ( COSEMessage const & )
delete

Assignment operator disabled.

◆ read()

bool uniot::COSEMessage::read ( const Bytes & buf)
inline

Reads a CBOR-encoded COSE_Sign1 message.

Parameters
bufCBOR data to parse
Return values
trueThe message was read successfully
falseThe message was not read successfully

◆ setPayload()

bool uniot::COSEMessage::setPayload ( const Bytes & payload)
inline

Sets the payload of the message.

Parameters
payloadData to set as the payload
Return values
trueThe payload was set successfully
falseThe payload was not set successfully

◆ setUnprotectedKid()

void uniot::COSEMessage::setUnprotectedKid ( const Bytes & kid)
inline

Sets the key identifier in the unprotected header.

Parameters
kidKey identifier to set

◆ sign()

void uniot::COSEMessage::sign ( const ICOSESigner & signer,
const Bytes & external = Bytes() )
inline

Signs the message using the provided signer.

Parameters
signerObject implementing the ICOSESigner interface that performs the signature
externalOptional external data to include in the signature calculation (AAD)

◆ verify()

bool uniot::COSEMessage::verify ( const Bytes & publicKey)
inline

Verifies the signature of the message using the provided public key.

Parameters
publicKeyPublic key to use for verification
Return values
trueThe signature is valid
falseThe signature is invalid

◆ wasReadSuccessful()

bool uniot::COSEMessage::wasReadSuccessful ( ) const
inline

Checks if the message was read successfully.

Return values
trueThe read operation was successful
falseThe read operation failed

The documentation for this class was generated from the following file: