libcdoc 0.1.8
libcdoc::Recipient Struct Reference

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

#include <Recipient.h>

Public Types

enum  Type : unsigned char {
  NONE , SYMMETRIC_KEY , PUBLIC_KEY , CERTIFICATE ,
  SERVER , KEYSHARE
}
 The recipient type. More...
 
enum  PKType : unsigned char { ECC , RSA }
 The public key type. More...
 
enum  EIDType { Unknown , IDCard , DigiID , DigiID_EResident }
 The EID 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 isKeyShare () const
 check whether Recipient is keyshare
 
void clear ()
 Clear all values and set type to NONE.
 
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 keys.
 
bool operator== (const Recipient &other) const =default
 

Static Public Member Functions

static Recipient makeSymmetric (const std::string &label, int32_t kdf_iter)
 Create a new symmetric key based Recipient.
 
static Recipient makePublicKey (const std::string &label, const std::vector< uint8_t > &public_key, PKType pk_type)
 Create a new public key based Recipient.
 
static Recipient makeCertificate (std::string label, std::vector< uint8_t > cert)
 Create a new certificate based Recipient.
 
static Recipient makeEID (std::vector< uint8_t > cert)
 Create a new certificate based Recipient filling label from certificate.
 
static Recipient makeServer (std::string label, std::vector< uint8_t > public_key, PKType pk_type, std::string server_id)
 Create new server based Recipient.
 
static Recipient makeEIDServer (std::vector< uint8_t > cert, std::string server_id)
 Create new server based Recipient filling label from certificate.
 
static Recipient makeShare (const std::string &label, const std::string &server_id, const std::string &recipient_id)
 Create new keyshare recipient.
 
static std::string buildLabel (std::vector< std::pair< std::string_view, std::string_view > > components)
 build machine-readable CDoc2 label
 
static std::string BuildLabelEID (int version, EIDType type, std::string_view cn, std::string_view serial_number, std::string_view last_name, std::string_view first_name)
 build machine-readable CDoc2 label for EID recipient
 
static std::string BuildLabelEID (const std::vector< uint8_t > &cert)
 build machine-readable CDoc2 label for EID recipient filling info from certificate
 
static std::string BuildLabelCertificate (int version, std::string_view file, std::string_view cn, const std::vector< uint8_t > &cert_sha1)
 build machine-readable CDoc2 label for certificate-based recipient
 
static std::string BuildLabelCertificate (std::string_view file, const std::vector< uint8_t > &cert)
 build machine-readable CDoc2 label for certificate-based recipient filling info from certificate
 
static std::string BuildLabelPublicKey (int version, const std::string file)
 build machine-readable CDoc2 label for public key based recipient
 
static std::string BuildLabelSymmetricKey (int version, const std::string &label, const std::string file)
 build machine-readable CDoc2 label for symmetric key based recipient
 
static std::string BuildLabelPassword (int version, const std::string &label)
 build machine-readable CDoc2 label for password key based recipient
 
static EIDType getEIDType (const std::vector< std::string > &policies)
 get EID type from policies list
 
static std::map< std::string, std::string > parseLabel (const std::string &label)
 parse machine-readable CDoc2 label
 

Public Attributes

Type type = Type::NONE
 The recipient type.
 
PKType pk_type = PKType::ECC
 The public key type.
 
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.
 
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 id
 The recipient id for share server (PNOEE-XXXXXXXXXXX)
 
std::string server_id
 The keyserver or share server list id (if present)
 

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

◆ EIDType

The EID type.

Enumerator
Unknown 
IDCard 
DigiID 
DigiID_EResident 

◆ PKType

enum libcdoc::Recipient::PKType : unsigned char

The public key type.

Enumerator
ECC 

Elliptic curve

RSA 

RSA

◆ Type

enum libcdoc::Recipient::Type : unsigned char

The recipient type.

Enumerator
NONE 

Uninitialized recipient

SYMMETRIC_KEY 

Symmetric key (or password)

PUBLIC_KEY 

Public key.

CERTIFICATE 

Full certificate.

SERVER 

public key on keyserver

KEYSHARE 

n of n shared symmetric key

Constructor & Destructor Documentation

◆ Recipient() [1/2]

libcdoc::Recipient::Recipient ( )
default

◆ Recipient() [2/2]

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

Member Function Documentation

◆ buildLabel()

static std::string libcdoc::Recipient::buildLabel ( std::vector< std::pair< std::string_view, std::string_view > >  components)
static

build machine-readable CDoc2 label

Parameters
componentsa list of string pairs
Returns
a composed label

◆ BuildLabelCertificate() [1/2]

static std::string libcdoc::Recipient::BuildLabelCertificate ( int  version,
std::string_view  file,
std::string_view  cn,
const std::vector< uint8_t > &  cert_sha1 
)
static

build machine-readable CDoc2 label for certificate-based recipient

Parameters
versionthe label version
filethe name of certificate file
cnthe common name
cert_sha1the certificate SHA1 hash
Returns
a composed label

◆ BuildLabelCertificate() [2/2]

static std::string libcdoc::Recipient::BuildLabelCertificate ( std::string_view  file,
const std::vector< uint8_t > &  cert 
)
static

build machine-readable CDoc2 label for certificate-based recipient filling info from certificate

See also
BuildLabelCertificate
Parameters
filethe name of certificate file
certthe certificate value (der-encoded)
Returns
a composed label

◆ BuildLabelEID() [1/2]

static std::string libcdoc::Recipient::BuildLabelEID ( const std::vector< uint8_t > &  cert)
static

build machine-readable CDoc2 label for EID recipient filling info from certificate

See also
BuildLabelEID
Parameters
certthe certificate value (der-encoded)
Returns
a composed label

◆ BuildLabelEID() [2/2]

static std::string libcdoc::Recipient::BuildLabelEID ( int  version,
EIDType  type,
std::string_view  cn,
std::string_view  serial_number,
std::string_view  last_name,
std::string_view  first_name 
)
static

build machine-readable CDoc2 label for EID recipient

Parameters
versionthe label version
typeEID type
cnthe common name
serial_numberthe serial number
last_namethe last name
first_namethe first name
Returns
a composed label

◆ BuildLabelPassword()

static std::string libcdoc::Recipient::BuildLabelPassword ( int  version,
const std::string &  label 
)
static

build machine-readable CDoc2 label for password key based recipient

Parameters
versionthe label version
labelthe password label
Returns
a composed label

◆ BuildLabelPublicKey()

static std::string libcdoc::Recipient::BuildLabelPublicKey ( int  version,
const std::string  file 
)
static

build machine-readable CDoc2 label for public key based recipient

Parameters
versionthe label version
filethe name of public key file
Returns
a composed label

◆ BuildLabelSymmetricKey()

static std::string libcdoc::Recipient::BuildLabelSymmetricKey ( int  version,
const std::string &  label,
const std::string  file 
)
static

build machine-readable CDoc2 label for symmetric key based recipient

Parameters
versionthe label version
labelthe key label
filethe name of key file
Returns
a composed label

◆ clear()

void libcdoc::Recipient::clear ( )
inline

Clear all values and set type to NONE.

◆ getEIDType()

static EIDType libcdoc::Recipient::getEIDType ( const std::vector< std::string > &  policies)
static

get EID type from policies list

Parameters
policiesthe list of policies
Returns
EID type

◆ 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

◆ isKeyShare()

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

check whether Recipient is keyshare

Returns
true if type is KEYSHARE

◆ 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 keys.

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 
)
static

Create a new certificate based Recipient.

Parameters
labelthe label text
certthe certificate value (der-encoded)
Returns
a new Recipient structure

◆ makeEID()

static Recipient libcdoc::Recipient::makeEID ( std::vector< uint8_t >  cert)
static

Create a new certificate based Recipient filling label from certificate.

See also
makeCertificate, BuildLabelEID
Parameters
certthe certificate value (der-encoded)
Returns
a new Recipient structure

◆ makeEIDServer()

static Recipient libcdoc::Recipient::makeEIDServer ( std::vector< uint8_t >  cert,
std::string  server_id 
)
static

Create new server based Recipient filling label from certificate.

See also
makeServer, BuildLabelEID
Parameters
certthe certificate value (der-encoded)
server_idthe keyserver id
Returns
a new Recipient structure

◆ makePublicKey()

static Recipient libcdoc::Recipient::makePublicKey ( const std::string &  label,
const std::vector< uint8_t > &  public_key,
PKType  pk_type 
)
static

Create a new public key based Recipient.

Parameters
labelthe label text
public_keythe public key value
pk_typethe algorithm type (either ECC or RSA)
Returns
a new Recipient structure

◆ makeServer()

static Recipient libcdoc::Recipient::makeServer ( std::string  label,
std::vector< uint8_t >  public_key,
PKType  pk_type,
std::string  server_id 
)
static

Create new server based Recipient.

Parameters
labelthe label text
public_keythe public key value
pk_typethe algorithm type (either ECC or RSA)
server_idthe keyserver id
Returns
a new Recipient structure

◆ makeShare()

static Recipient libcdoc::Recipient::makeShare ( const std::string &  label,
const std::string &  server_id,
const std::string &  recipient_id 
)
static

Create new keyshare recipient.

Parameters
labelthe label text
server_idthe id of share server group
recipient_idthe recipient id (PNOEE-01234567890)
Returns
Recipient a new Recipient structure

◆ makeSymmetric()

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

Create a new symmetric key based Recipient.

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

◆ parseLabel()

static std::map< std::string, std::string > libcdoc::Recipient::parseLabel ( const std::string &  label)
static

parse machine-readable CDoc2 label

Parameters
labelthe label
Returns
a map of key-value pairs

Member Data Documentation

◆ cert

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

The recipient's certificate (if present)

◆ id

std::string libcdoc::Recipient::id

The recipient id for share server (PNOEE-XXXXXXXXXXX)

◆ 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.

◆ pk_type

PKType libcdoc::Recipient::pk_type = PKType::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: