24 #ifndef NDN_DER_NODE_HPP
25 #define NDN_DER_NODE_HPP
27 #include <ndn-cpp/util/blob.hpp>
28 #include <ndn-cpp/encoding/oid.hpp>
29 #include "../../util/dynamic-uint8-vector.hpp"
30 #include "der-node-type.hpp"
57 static ptr_lib::shared_ptr<DerNode>
58 parse(
const uint8_t* inputBuf,
size_t startIdx = 0);
82 virtual const std::vector<ptr_lib::shared_ptr<DerNode> >&
100 class DerPrintableString;
115 (
const std::vector<ptr_lib::shared_ptr<DerNode> >&children,
size_t index);
124 : nodeType_(nodeType),
153 decode(
const uint8_t* inputBuf,
size_t startIdx);
164 payloadPosition_ = payload_.
copy(value, valueLength, payloadPosition_);
167 DerStructure* parent_;
169 std::vector<uint8_t> header_;
171 size_t payloadPosition_;
190 virtual const std::vector<ptr_lib::shared_ptr<DerNode> >&
194 addChild(
const ptr_lib::shared_ptr<DerNode>& node,
bool notifyParent =
false)
196 node->parent_ =
this;
197 nodeList_.push_back(node);
201 parent_->setChildChanged();
204 childChanged_ =
true;
223 childChanged_(false),
235 decode(
const uint8_t* inputBuf,
size_t startIdx);
248 parent_->setChildChanged();
249 childChanged_ =
true;
253 std::vector<ptr_lib::shared_ptr<DerNode> > nodeList_;
279 (
const uint8_t* inputData,
size_t inputDataLength,
DerNodeType nodeType)
303 uint8_t val = value ? 0xff : 0x00;
348 DerBitString(
const uint8_t* inputBuf,
size_t inputBufLength,
int paddingLen)
349 :
DerNode(DerNodeType_BitString)
351 uint8_t pad = paddingLen & 0xff;
358 :
DerNode(DerNodeType_BitString)
371 :
DerByteString(inputData, inputDataLength, DerNodeType_OctetString)
407 :
DerNode(DerNodeType_ObjectIdentifier)
411 prepareEncoding(tempOid.getIntegerList());
420 :
DerNode(DerNodeType_ObjectIdentifier)
422 prepareEncoding(oid.getIntegerList());
426 :
DerNode(DerNodeType_ObjectIdentifier)
443 prepareEncoding(
const std::vector<int>& value);
451 static std::vector<uint8_t>
452 encode128(
int value);
461 decode128(
size_t offset,
size_t& skip);
484 :
DerByteString(inputData, inputDataLength, DerNodeType_PrintableString)
505 :
DerNode(DerNodeType_GeneralizedTime)
507 std::string derTime = toDerTimeString(msSince1970);
513 :
DerNode(DerNodeType_GeneralizedTime)
Blob getPayload()
Get a copy of the payload bytes.
Definition: der-node.hpp:73
DerOid(const OID &oid)
Create a DerOid with the given object identifier.
Definition: der-node.hpp:419
DerOctetString extends DerByteString to encode a string of bytes.
Definition: der-node.hpp:368
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
DerSequence()
Create a DerSequence.
Definition: der-node.hpp:469
A DerBitString extends DerNode to handle a bit string.
Definition: der-node.hpp:339
virtual Blob encode()
Get the raw data encoding for this node.
Definition: der-node.cpp:40
DerBitString(const uint8_t *inputBuf, size_t inputBufLength, int paddingLen)
Create a DerBitString with the given padding and inputBuf.
Definition: der-node.hpp:348
virtual size_t getSize()
Override to get the total length of the encoding, including children.
Definition: der-node.cpp:192
static DerNode::DerSequence & getSequence(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 i...
Definition: der-node.cpp:98
int toIntegerVal() const
Parse the payload as an integer and return the value.
Definition: der-node.cpp:304
void encodeHeader(size_t size)
Encode the given size and update the header.
Definition: der-node.cpp:112
DerNull()
Create a DerNull.
Definition: der-node.hpp:389
virtual Blob toVal()
Convert the encoded data to a standard representation.
Definition: der-node.cpp:85
DerNodeType
The DerNodeType enum defines the known DER node types.
Definition: der-node-type.hpp:32
virtual void decode(const uint8_t *inputBuf, size_t startIdx)
Override the base decode to decode and store the data from an input buffer.
Definition: der-node.cpp:230
Definition: der-node.hpp:464
DerInteger extends DerNode to encode an integer value.
Definition: der-node.hpp:317
MillisecondsSince1970 toMillisecondsSince1970()
Interpret the result of toVal() as a time string and return the milliseconds since 1970...
Definition: der-node.cpp:420
static MillisecondsSince1970 fromIsoString(const std::string &isoString)
Convert from the ISO string representation to the internal time format.
Definition: der-node.cpp:450
virtual Blob encode()
Override the base encode to return raw data encoding for this node and its children.
Definition: der-node.cpp:210
A DerPrintableString extends DerByteString to handle a a printable string.
Definition: der-node.hpp:481
DerByteString(const uint8_t *inputData, size_t inputDataLength, DerNodeType nodeType)
Create a DerByteString with the given inputData and nodeType.
Definition: der-node.hpp:279
DerOid(const std::string &oidStr)
Create a DerOid with the given object identifier.
Definition: der-node.hpp:406
virtual Blob toVal()
Override to return the string representation of the OID.
Definition: der-node.cpp:320
A DerStructure extends DerNode to hold other DerNodes.
Definition: der-node.hpp:177
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
A DerOid extends DerNode to represent an object identifier.
Definition: der-node.hpp:399
DerBoolean extends DerNode to encode a boolean value.
Definition: der-node.hpp:294
virtual Blob toVal()
Override to return just the byte string.
Definition: der-node.cpp:260
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:116
A DerNull extends DerNode to encode a null value.
Definition: der-node.hpp:384
DerNode implements the DER node types used in encoding/decoding DER-formatted data.
Definition: der-node.hpp:38
DerStructure(DerNodeType nodeType)
Create a DerStructure with the given nodeType.
Definition: der-node.hpp:221
size_t decodeHeader(const uint8_t *inputBuf, size_t startIdx)
Extract the header from an input buffer and return the size.
Definition: der-node.cpp:146
virtual void decode(const uint8_t *inputBuf, size_t startIdx)
Decode and store the data from an input buffer.
Definition: der-node.cpp:180
DerNode(DerNodeType nodeType)
Create a generic DER node with the given nodeType.
Definition: der-node.hpp:123
size_t copy(const uint8_t *value, size_t valueLength, size_t offset)
Copy value into the vector at offset, using ensureLength to make sure the vector has enough size...
Definition: dynamic-uint8-vector.hpp:68
static std::string toIsoString(const MillisecondsSince1970 &time)
Convert to the ISO string representation of the time.
Definition: der-node.cpp:439
DerBoolean(bool value)
Create a new DerBoolean for the value.
Definition: der-node.hpp:300
virtual const std::vector< ptr_lib::shared_ptr< DerNode > > & getChildren()
Get the children of this node.
Definition: der-node.cpp:204
virtual const std::vector< ptr_lib::shared_ptr< DerNode > > & getChildren()
If this object is a DerSequence, get the children of this node.
Definition: der-node.cpp:91
A DerGeneralizedTime extends DerNode to represent a date and time, with millisecond accuracy...
Definition: der-node.hpp:498
A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr > for use wit...
Definition: dynamic-uint8-vector.hpp:37
DerGeneralizedTime(MillisecondsSince1970 msSince1970)
Create a DerGeneralizedTime with the given milliseconds since 1970.
Definition: der-node.hpp:504
void payloadAppend(const uint8_t *value, size_t valueLength)
Call payload_.copy to copy value into payload_ at payloadPosition_.
Definition: der-node.hpp:162
static ptr_lib::shared_ptr< DerNode > parse(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 De...
Definition: der-node.cpp:53
A DerByteString extends DerNode to handle byte strings.
Definition: der-node.hpp:260