Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ndn::DerNode Class Reference

DerNode implements the DER node types used in encoding/decoding DER-formatted data. More...

#include <der-node.hpp>

Inheritance diagram for ndn::DerNode:
ndn::DerNode::DerBitString ndn::DerNode::DerBoolean ndn::DerNode::DerByteString ndn::DerNode::DerGeneralizedTime ndn::DerNode::DerInteger ndn::DerNode::DerNull ndn::DerNode::DerOid ndn::DerNode::DerStructure

Classes

class  DerBitString
 A DerBitString extends DerNode to handle a bit string. More...
 
class  DerBoolean
 DerBoolean extends DerNode to encode a boolean value. More...
 
class  DerByteString
 A DerByteString extends DerNode to handle byte strings. More...
 
class  DerGeneralizedTime
 A DerGeneralizedTime extends DerNode to represent a date and time, with millisecond accuracy. More...
 
class  DerInteger
 DerInteger extends DerNode to encode an integer value. More...
 
class  DerNull
 A DerNull extends DerNode to encode a null value. More...
 
class  DerOctetString
 DerOctetString extends DerByteString to encode a string of bytes. More...
 
class  DerOid
 A DerOid extends DerNode to represent an object identifier. More...
 
class  DerPrintableString
 A DerPrintableString extends DerByteString to handle a a printable string. More...
 
class  DerSequence
 
class  DerStructure
 A DerStructure extends DerNode to hold other DerNodes. More...
 

Public Member Functions

virtual size_t getSize ()
 
virtual Blob encode ()
 Get the raw data encoding for this node. More...
 
virtual Blob toVal ()
 Convert the encoded data to a standard representation. More...
 
Blob getPayload ()
 Get a copy of the payload bytes. More...
 
virtual const std::vector< ptr_lib::shared_ptr< DerNode > > & getChildren ()
 If this object is a DerSequence, get the children of this node. More...
 

Static Public Member Functions

static ptr_lib::shared_ptr< DerNodeparse (const uint8_t *inputBuf, size_t startIdx=0)
 Parse the data from the input buffer recursively and return the root as an object of a subclass of DerNode. More...
 
static DerNode::DerSequencegetSequence (const std::vector< ptr_lib::shared_ptr< DerNode > > &children, size_t index)
 Check that index is in bounds for the children list, cast children[index] to DerSequence and return it. More...
 

Protected Member Functions

 DerNode (DerNodeType nodeType)
 Create a generic DER node with the given nodeType. More...
 
void encodeHeader (size_t size)
 Encode the given size and update the header. More...
 
size_t decodeHeader (const uint8_t *inputBuf, size_t startIdx)
 Extract the header from an input buffer and return the size. More...
 
virtual void decode (const uint8_t *inputBuf, size_t startIdx)
 Decode and store the data from an input buffer. More...
 
void payloadAppend (const uint8_t *value, size_t valueLength)
 Call payload_.copy to copy value into payload_ at payloadPosition_. More...
 

Protected Attributes

DerStructureparent_
 
DerNodeType nodeType_
 
std::vector< uint8_t > header_
 
DynamicUInt8Vector payload_
 
size_t payloadPosition_
 

Detailed Description

DerNode implements the DER node types used in encoding/decoding DER-formatted data.

Constructor & Destructor Documentation

ndn::DerNode::DerNode ( DerNodeType  nodeType)
inlineprotected

Create a generic DER node with the given nodeType.

This is a private constructor used by one of the public DerNode subclasses defined below.

Parameters
nodeTypeThe DER node type.

Member Function Documentation

void ndn::DerNode::decode ( const uint8_t *  inputBuf,
size_t  startIdx 
)
protectedvirtual

Decode and store the data from an input buffer.

Parameters
inputBufThe input buffer to read from. This reads from startIdx.
startIdxThe offset into the buffer.

Reimplemented in ndn::DerNode::DerStructure.

size_t ndn::DerNode::decodeHeader ( const uint8_t *  inputBuf,
size_t  startIdx 
)
protected

Extract the header from an input buffer and return the size.

Parameters
inputBufThe input buffer to read from.
startIdxThe offset into the buffer.
Returns
The parsed size in the header.
Blob ndn::DerNode::encode ( )
virtual

Get the raw data encoding for this node.

Returns
The raw data encoding.

Reimplemented in ndn::DerNode::DerStructure.

void ndn::DerNode::encodeHeader ( size_t  size)
protected

Encode the given size and update the header.

Parameters
sizeThe size to encode in the header.
const std::vector< ptr_lib::shared_ptr< DerNode > > & ndn::DerNode::getChildren ( )
virtual

If this object is a DerSequence, get the children of this node.

Otherwise, throw an exception. (DerSequence overrides to implement this method.)

Returns
The children as an array of shared_ptr<DerNode>.
Exceptions
DerDecodingExceptionif this object is not a DerSequence.

Reimplemented in ndn::DerNode::DerStructure.

Blob ndn::DerNode::getPayload ( )
inline

Get a copy of the payload bytes.

Returns
A copy of the payload.
DerNode::DerSequence & ndn::DerNode::getSequence ( const std::vector< ptr_lib::shared_ptr< DerNode > > &  children,
size_t  index 
)
static

Check that index is in bounds for the children list, cast children[index] to DerSequence and return it.

Parameters
childrenThe list of DerNode, usually returned by another call to getChildren.
indexThe index of the children.
Returns
children[index] cast to DerSequence.
Exceptions
DerDecodingExceptionif index is out of bounds or if children[index] is not a DerSequence.
ptr_lib::shared_ptr< DerNode > ndn::DerNode::parse ( const uint8_t *  inputBuf,
size_t  startIdx = 0 
)
static

Parse the data from the input buffer recursively and return the root as an object of a subclass of DerNode.

Parameters
inputBufThe input buffer to read from. This reads from startIdx.
startIdx(optional) The offset into the buffer. If omitted, use 0.
Returns
A shared_ptr for an object of a subclass of DerNode.
void ndn::DerNode::payloadAppend ( const uint8_t *  value,
size_t  valueLength 
)
inlineprotected

Call payload_.copy to copy value into payload_ at payloadPosition_.

Update payloadPosition_.

Parameters
valueThe buffer to copy from.
valueLengthThe length of the value buffer.
Blob ndn::DerNode::toVal ( )
virtual

Convert the encoded data to a standard representation.

Overridden by some subclasses (e.g. DerBoolean).

Returns
The encoded data as a Blob.

Reimplemented in ndn::DerNode::DerOid, and ndn::DerNode::DerByteString.


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