scclib
Stable Cloud Computing C++ Library
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
scc::crypto::DerBase Class Reference

ASN.1 base. More...

#include <der.h>

Inheritance diagram for scc::crypto::DerBase:
Inheritance graph
[legend]

Public Types

enum  Tag {
  id_mask = 0x1f , construct_mask = 0x20 , class_mask = 0xc0 , class_application = 0x40 ,
  class_context = 0x80 , class_private = 0xc0 , length_multi_mask = 0x80 , length_bytes_mask = 0x7f ,
  type_boolean = 1 , type_integer = 2 , type_bit_string = 3 , type_octet_string = 4 ,
  type_null = 5 , type_object_identifier = 6 , type_utf8_string = 12 , type_sequence = 16 ,
  type_set = 17 , type_printable_string = 19 , type_teletex_string = 20 , type_ia5_string = 22 ,
  type_utc_time = 23 , type_generalized_time = 24 , type_visible_string = 26 , type_universal_string = 28 ,
  type_bmp_string = 30
}
 

Public Member Functions

 DerBase (uint8_t tag=0)
 Construct a base object. More...
 
size_t eloff () const
 Offset of the element into the binary vector.
 
void eloff (size_t v)
 
size_t elsz () const
 Binary vector element length, not including the header.
 
void elsz (size_t v)
 
size_t hdrsz () const
 Header size of the element (tag, id, and length bytes).
 
void hdrsz (size_t v)
 
size_t pre_len () const
 The length of prefix bytes (tag/id, and length).
 
virtual size_t len () const
 Length of the data.
 
virtual void parse (const std::vector< uint8_t > &v)
 Parse raw data into the object.
 
virtual void dump_pre (std::vector< char > &) const
 Dump prefix data. More...
 
virtual void dump_data (std::vector< char > &) const
 Dump data. More...
 
virtual std::string str (uint32_t=100) const
 Print summary line to maximum width.
 
virtual std::string data_str () const
 Print vizualized data.
 
virtual std::string name () const
 
std::vector< uint8_t > & data ()
 Underlying data.
 
void get_base (std::vector< uint8_t > &v) const
 Get raw data.
 
void set_base (const std::vector< uint8_t > &v)
 Set raw data.
 
void set_base (const std::vector< char > &v)
 
uint32_t id () const
 Tag id of the type. More...
 
void id (uint32_t v)
 
std::string id_str () const
 String version of the id.
 
uint8_t type_class () const
 Classification of the type (bits 7-8)
 
void type_class (uint8_t f)
 Set type class.
 
bool uni_class () const
 Universal class.
 
bool app_class () const
 Application class.
 
bool context_class () const
 Context class.
 
bool priv_class () const
 Private class.
 
std::string class_str () const
 String version of the classification.
 
bool constructed () const
 Constructed flag (bit 6).
 
void constructed (bool cons)
 Set constructed flag.
 
std::string construct_str () const
 String version of the construct flag.
 
bool is_seq () const
 Is this a sequence type?
 
bool is_set () const
 Is this a set type?
 
bool is_contain () const
 Is this a container type?
 
std::vector< BasePtr > & contain ()
 Return container, or throw an error if this is not a container.
 
bool is_integer () const
 Is this a DerInteger?
 
scc::crypto::Bignuminteger ()
 Return reference to a scc::crypto::Bignum. More...
 
bool is_bit_string () const
 Is this a DerBitString?
 
BitStringbit_string ()
 Return reference to bit string.
 
bool is_octet_string () const
 Is this an octet string (8 bit chars)?
 
bool is_printable_string () const
 Is this a printable string?
 
bool is_utf8_string () const
 Is this a utf8 (ascii) string?
 
bool is_ia5_string () const
 Is this an ia5 (ascii) string?
 
bool is_bmp_string () const
 Is this a bmp (ascii) string?
 
bool is_universal_string () const
 Is this a univeral (ascii) string?
 
bool is_teletex_string () const
 Is this a teletex (ascii) string?
 
bool is_visible_string () const
 Is this a visible (ascii) string?
 
bool is_string () const
 Is this a generic ascii string?
 
std::string string ()
 Return string.
 
void string (const std::string &)
 Set the string.
 
void string_get (std::vector< char > &)
 Get string vector.
 
void string_get (std::vector< uint8_t > &)
 
void string_set (const std::vector< char > &)
 Set string vector.
 
void string_set (const std::vector< uint8_t > &)
 
bool is_null () const
 Is this a null type?
 
bool is_boolean () const
 Is this a boolean type?
 
bool boolean ()
 Return boolean value.
 
void boolean (bool)
 Set boolean value.
 
bool is_utc_time () const
 Is this a utc time type?
 
bool is_generalized_time () const
 Is this as generalized time type?
 
bool is_time () const
 Is this a time type?
 
time_t time_epoch ()
 Epoch time. More...
 
std::chrono::system_clock::time_point time_point ()
 Time point.
 
bool is_object_id () const
 Is this an object identifier?
 
oid_value object_id ()
 Return the object identifier value.
 
void object_id (const oid_value &)
 Set the object identifier.
 

Static Public Member Functions

static BasePtr create (int)
 Create a base pointer, using only the tag byte.
 
static BasePtr create (const std::vector< uint8_t > &, size_t)
 Create a base pointer, with extended header bytes.
 
static BasePtr context_to_explicit (const BasePtr &)
 Change a context element to explicit. More...
 
static BasePtr explicit_to_context (const BasePtr &BasePtr, uint32_t)
 Convert explicit to context. More...
 
static BasePtr context_to_implicit (const BasePtr &, uint32_t)
 Change a context element to implicit. More...
 
static BasePtr implicit_to_context (const BasePtr &BasePtr, uint32_t)
 Convert implicit to context. More...
 

Protected Attributes

uint8_t m_tag
 
uint32_t m_id
 

Friends

class DerDocument
 
class X509Cert
 

Detailed Description

ASN.1 base.

All objects can be manipulated using unique_ptr to Base object.

Examples
scclib/crypto/unittest/der.cc.

Definition at line 174 of file der.h.

Constructor & Destructor Documentation

◆ DerBase()

scc::crypto::DerBase::DerBase ( uint8_t  tag = 0)
inline

Construct a base object.

NOTE: An Id less than 0x1f can be embedded in the tag. If an id > 30 is required, must call the id() function to set.

Definition at line 220 of file der.h.

Member Function Documentation

◆ context_to_explicit()

BasePtr DerBase::context_to_explicit ( const BasePtr &  ctx)
static

Change a context element to explicit.

Parameters
ctxOriginal context element. Data from this element is parsed to create a new element.

The ASN.1 spec says that explicit elements must be context-class and constructed. This api throws an exception otherwise.

The data is used to construct a new element, which is returned.

Definition at line 1048 of file der.cc.

◆ context_to_implicit()

BasePtr DerBase::context_to_implicit ( const BasePtr &  ctx,
uint32_t  id 
)
static

Change a context element to implicit.

Parameters
ctxOriginal element.
idThe type id (type_* from DerBase::Tag)

The ASN.1 spec says that implicit elements must be context-class. This api throws an exception otherwise.

A universal element is created with the same construct flag as the original element.

A new element is constructed by changing the tag to the input tag provided. If the input tag is constructed, the input element must be as well.

Definition at line 1072 of file der.cc.

◆ dump_data()

void DerBase::dump_data ( std::vector< char > &  v) const
virtual

◆ dump_pre()

void DerBase::dump_pre ( std::vector< char > &  v) const
virtual

Dump prefix data.

Throws exception if buffer is too small.

Definition at line 143 of file der.cc.

◆ explicit_to_context()

BasePtr DerBase::explicit_to_context ( const BasePtr &  BasePtr,
uint32_t  id 
)
static

Convert explicit to context.

Parameters
origThe element to be converted to context.
idId to be applied to the returned context element.

Output will be a constructed context-class element with the input id, and data DER-encoded input element.

Definition at line 1057 of file der.cc.

◆ id()

uint32_t scc::crypto::DerBase::id ( ) const
inline

Tag id of the type.

The id can be encoded in the tag (low-tag), or separately using a multibyte method (high-tag).

Definition at line 325 of file der.h.

◆ implicit_to_context()

BasePtr DerBase::implicit_to_context ( const BasePtr &  BasePtr,
uint32_t  id 
)
static

Convert implicit to context.

Parameters
origThe element to be converted to context.
idId to be applied to the returned context element.

Output will be a context-class element with the input id, and data the same as the input element. If the input element is constructed, the output element will also be set constructed.

Definition at line 1090 of file der.cc.

◆ integer()

Bignum & DerBase::integer ( )

Return reference to a scc::crypto::Bignum.

Throw error if this is not an integer.

Definition at line 232 of file der.cc.

◆ time_epoch()

time_t DerBase::time_epoch ( )

Epoch time.

Seconds since Jan 1, 1970 in the local time zone.

Definition at line 367 of file der.cc.


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