libcdoc 0.5.1
libcdoc::Recipient Struct Reference

A descriptor of encryption method and key to be used in container. More...

#include <Recipient.h>

Public Types

enum  Type : uint8_t { NONE , SYMMETRIC_KEY , PUBLIC_KEY }
 The recipient type. More...
 

Public Member Functions

 Recipient ()=default
 
bool isEmpty () const
 test whether the Recipient structure is initialized
 
bool isSymmetric () const
 check whether Recipient is based on symmetric key
 
bool isPKI () const
 check whether Recipient is based on public key
 
bool isCertificate () const
 check whether Recipient is based on certificate
 
bool isKeyServer () const
 check whether Recipient is keyserver
 
bool isTheSameRecipient (const Recipient &other) const
 A convenience method to check whether two recipients are both public key based and have the same keys.
 
bool isTheSameRecipient (const std::vector< uint8_t > &public_key) const
 A convenience method to check whether a recipient is public key based and has the given key.
 
std::string getLabel (std::map< std::string_view, std::string_view > extra) const
 Get the label for this recipient.
 
void setLabelValue (std::string_view key, std::string_view value)
 Set a property for automatic label generation.
 
bool validate () const
 Validate recipient record.
 
bool operator== (const Recipient &other) const =default
 

Static Public Member Functions

static Recipient makeSymmetric (std::string label, int32_t kdf_iter)
 Create a new symmetric key based Recipient.
 
static Recipient makePublicKey (std::string label, std::vector< uint8_t > public_key, std::string server_id={})
 Create a new public key based Recipient.
 
static Recipient makePublicKey (const Lock &lock, std::string server_id={})
 Create a new public key based Recipient.
 
static Recipient makeCertificate (std::string label, std::vector< uint8_t > cert, std::string server_id={})
 Create a new certificate based Recipient.
 

Public Attributes

Type type = Type::NONE
 The recipient type.
 
Algorithm pk_type = Algorithm::ECC
 The public key type.
 
Curve ec_type = Curve::SECP_384_R1
 
int32_t kdf_iter = 0
 The number of iterations for PBKDF. Value 0 means directly provided symmetric key.
 
std::string label
 The recipient's label (if empty the lock label will be autogenerated)
 
std::vector< uint8_t > rcpt_key
 Recipient's public key (for all PKI types)
 
std::vector< uint8_t > cert
 The recipient's certificate (if present)
 
std::string server_id
 The keyserver or share server list id (if present)
 
uint64_t expiry_ts = 0
 The requested capsule expiry timestamp (0 - use server default)
 

Protected Member Functions

 Recipient (Type _type)
 

Detailed Description

A descriptor of encryption method and key to be used in container.

Recipient determines all the relevant properties to encrypt the FMK for a certain target.

Member Enumeration Documentation

◆ Type

enum libcdoc::Recipient::Type : uint8_t

The recipient type.

Enumerator
NONE 

Uninitialized recipient

SYMMETRIC_KEY 

Symmetric key (or password)

PUBLIC_KEY 

Public key.

Constructor & Destructor Documentation

◆ Recipient() [1/2]

libcdoc::Recipient::Recipient ( )
default

◆ Recipient() [2/2]

libcdoc::Recipient::Recipient ( Type  _type)
inlineprotected

Member Function Documentation

◆ getLabel()

std::string libcdoc::Recipient::getLabel ( std::map< std::string_view, std::string_view >  extra) const

Get the label for this recipient.

Either returns user-specified label or generate machine-readable if empty

Parameters
extraadditional parameter values to use
Returns
a label value

◆ isCertificate()

bool libcdoc::Recipient::isCertificate ( ) const
inline

check whether Recipient is based on certificate

Returns
true if type is CERTIFICATE

◆ isEmpty()

bool libcdoc::Recipient::isEmpty ( ) const
inline

test whether the Recipient structure is initialized

Returns
true if not initialized

◆ isKeyServer()

bool libcdoc::Recipient::isKeyServer ( ) const
inline

check whether Recipient is keyserver

Returns
true if type is SERVER

◆ isPKI()

bool libcdoc::Recipient::isPKI ( ) const
inline

check whether Recipient is based on public key

Returns
true if type is CERTIFICATE, PUBLIC_KEY or SERVER

◆ isSymmetric()

bool libcdoc::Recipient::isSymmetric ( ) const
inline

check whether Recipient is based on symmetric key

Returns
true if type is SYMMETRIC_KEY

◆ isTheSameRecipient() [1/2]

bool libcdoc::Recipient::isTheSameRecipient ( const Recipient other) const

A convenience method to check whether two recipients are both public key based and have the same keys.

Parameters
otheranother Recipient
Returns
true if the public keys are identical

◆ isTheSameRecipient() [2/2]

bool libcdoc::Recipient::isTheSameRecipient ( const std::vector< uint8_t > &  public_key) const

A convenience method to check whether a recipient is public key based and has the given key.

Parameters
public_keya public key to test
Returns
true if the public keys are identical

◆ makeCertificate()

static Recipient libcdoc::Recipient::makeCertificate ( std::string  label,
std::vector< uint8_t >  cert,
std::string  server_id = {} 
)
static

Create a new certificate based Recipient.

If the label is empty, a machine-readable label will be created according to CDoc2 specification

Parameters
labelthe label text
certthe certificate value (der-encoded)
server_idthe keyserver id or empty string for offline capsule
Returns
a new Recipient structure

◆ makePublicKey() [1/2]

static Recipient libcdoc::Recipient::makePublicKey ( const Lock lock,
std::string  server_id = {} 
)
static

Create a new public key based Recipient.

Parameters
lockLock to derive parameters from
server_idthe keyserver id or empty string for offline capsule
Returns
a new Recipient structure

◆ makePublicKey() [2/2]

static Recipient libcdoc::Recipient::makePublicKey ( std::string  label,
std::vector< uint8_t >  public_key,
std::string  server_id = {} 
)
static

Create a new public key based Recipient.

If the label is empty, a machine-readable label will be created according to CDoc2 specification

Parameters
labelthe label text
public_keythe public key value
server_idthe keyserver id or empty string for offline capsule
Returns
a new Recipient structure

◆ makeSymmetric()

static Recipient libcdoc::Recipient::makeSymmetric ( std::string  label,
int32_t  kdf_iter 
)
static

Create a new symmetric key based Recipient.

If the label is empty, a machine-readable label will be created according to CDoc2 specification

Parameters
labelthe label text
kdf_iterthe number of PBKDF iterations (0 if full key is provided)
Returns
a new Recipient structure

◆ operator==()

bool libcdoc::Recipient::operator== ( const Recipient other) const
default

◆ setLabelValue()

void libcdoc::Recipient::setLabelValue ( std::string_view  key,
std::string_view  value 
)
inline

Set a property for automatic label generation.

Parameters
keythe property name
valuethe property value

◆ validate()

bool libcdoc::Recipient::validate ( ) const

Validate recipient record.

Returns
true if Recipient is valid

Member Data Documentation

◆ cert

std::vector<uint8_t> libcdoc::Recipient::cert

The recipient's certificate (if present)

◆ ec_type

Curve libcdoc::Recipient::ec_type = Curve::SECP_384_R1

◆ expiry_ts

uint64_t libcdoc::Recipient::expiry_ts = 0

The requested capsule expiry timestamp (0 - use server default)

◆ kdf_iter

int32_t libcdoc::Recipient::kdf_iter = 0

The number of iterations for PBKDF. Value 0 means directly provided symmetric key.

◆ label

std::string libcdoc::Recipient::label

The recipient's label (if empty the lock label will be autogenerated)

◆ pk_type

Algorithm libcdoc::Recipient::pk_type = Algorithm::ECC

The public key type.

◆ rcpt_key

std::vector<uint8_t> libcdoc::Recipient::rcpt_key

Recipient's public key (for all PKI types)

◆ server_id

std::string libcdoc::Recipient::server_id

The keyserver or share server list id (if present)

◆ type

Type libcdoc::Recipient::type = Type::NONE

The recipient type.


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