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"
58 static ptr_lib::shared_ptr<DerNode>
59 parse(
const uint8_t* inputBuf,
size_t inputBufLength,
size_t startIdx = 0);
61 static ptr_lib::shared_ptr<DerNode>
62 parse(
const Blob& input,
size_t startIdx = 0)
67 static ptr_lib::shared_ptr<DerNode>
68 parse(
const std::vector<uint8_t>& input,
size_t startIdx = 0)
70 return parse(&input[0], input.size(), startIdx);
95 virtual const std::vector<ptr_lib::shared_ptr<DerNode> >&
109 class DerOctetString;
113 class DerPrintableString;
128 (
const std::vector<ptr_lib::shared_ptr<DerNode> >&children,
size_t index);
137 : nodeType_(nodeType),
158 decodeHeader(
const uint8_t* inputBuf,
size_t inputBufLength,
size_t startIdx);
166 decode(
const uint8_t* inputBuf,
size_t inputBufLength,
size_t startIdx);
177 payloadPosition_ = payload_.
copy(value, valueLength, payloadPosition_);
180 DerStructure* parent_;
182 std::vector<uint8_t> header_;
184 size_t payloadPosition_;
203 virtual const std::vector<ptr_lib::shared_ptr<DerNode> >&
207 addChild(
const ptr_lib::shared_ptr<DerNode>& node,
bool notifyParent =
false)
209 node->parent_ =
this;
210 nodeList_.push_back(node);
214 parent_->setChildChanged();
217 childChanged_ =
true;
236 childChanged_(false),
248 decode(
const uint8_t* inputBuf,
size_t inputBufLength,
size_t startIdx);
261 parent_->setChildChanged();
262 childChanged_ =
true;
266 std::vector<ptr_lib::shared_ptr<DerNode> > nodeList_;
292 (
const uint8_t* inputData,
size_t inputDataLength,
DerNodeType nodeType)
316 uint8_t val = value ? 0xff : 0x00;
361 DerBitString(
const uint8_t* inputBuf,
size_t inputBufLength,
int paddingLength)
362 :
DerNode(DerNodeType_BitString)
364 uint8_t pad = paddingLength & 0xff;
371 :
DerNode(DerNodeType_BitString)
384 :
DerByteString(inputData, inputDataLength, DerNodeType_OctetString)
420 :
DerNode(DerNodeType_ObjectIdentifier)
424 prepareEncoding(tempOid.getIntegerList());
433 :
DerNode(DerNodeType_ObjectIdentifier)
435 prepareEncoding(oid.getIntegerList());
439 :
DerNode(DerNodeType_ObjectIdentifier)
456 prepareEncoding(
const std::vector<int>& value);
464 static std::vector<uint8_t>
465 encode128(
int value);
474 decode128(
size_t offset,
size_t& skip);
497 :
DerByteString(inputData, inputDataLength, DerNodeType_PrintableString)
518 :
DerNode(DerNodeType_GeneralizedTime)
520 std::string derTime = toDerTimeString(msSince1970);
526 :
DerNode(DerNodeType_GeneralizedTime)
Blob getPayload()
Get a copy of the payload bytes.
Definition: der-node.hpp:86
DerOid(const OID &oid)
Create a DerOid with the given object identifier.
Definition: der-node.hpp:432
DerOctetString extends DerByteString to encode a string of bytes.
Definition: der-node.hpp:381
size_t decodeHeader(const uint8_t *inputBuf, size_t inputBufLength, size_t startIdx)
Extract the header from an input buffer and return the size.
Definition: der-node.cpp:149
static ptr_lib::shared_ptr< DerNode > parse(const uint8_t *inputBuf, size_t inputBufLength, 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
DerSequence()
Create a DerSequence.
Definition: der-node.hpp:482
A DerBitString extends DerNode to handle a bit string.
Definition: der-node.hpp:352
virtual Blob encode()
Get the raw data encoding for this node.
Definition: der-node.cpp:40
virtual size_t getSize()
Override to get the total length of the encoding, including children.
Definition: der-node.cpp:201
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:100
int toIntegerVal() const
Parse the payload as an integer and return the value.
Definition: der-node.cpp:316
void encodeHeader(size_t size)
Encode the given size and update the header.
Definition: der-node.cpp:114
DerNull()
Create a DerNull.
Definition: der-node.hpp:402
virtual Blob toVal()
Convert the encoded data to a standard representation.
Definition: der-node.cpp:87
DerNodeType
The DerNodeType enum defines the known DER node types.
Definition: der-node-type.hpp:32
Definition: der-node.hpp:477
DerInteger extends DerNode to encode an integer value.
Definition: der-node.hpp:330
MillisecondsSince1970 toMillisecondsSince1970()
Interpret the result of toVal() as a time string and return the milliseconds since 1970...
Definition: der-node.cpp:432
static MillisecondsSince1970 fromIsoString(const std::string &isoString)
Convert from the ISO string representation to the internal time format.
Definition: der-node.cpp:462
virtual Blob encode()
Override the base encode to return raw data encoding for this node and its children.
Definition: der-node.cpp:219
A DerPrintableString extends DerByteString to handle a a printable string.
Definition: der-node.hpp:494
DerByteString(const uint8_t *inputData, size_t inputDataLength, DerNodeType nodeType)
Create a DerByteString with the given inputData and nodeType.
Definition: der-node.hpp:292
DerOid(const std::string &oidStr)
Create a DerOid with the given object identifier.
Definition: der-node.hpp:419
virtual Blob toVal()
Override to return the string representation of the OID.
Definition: der-node.cpp:332
A DerStructure extends DerNode to hold other DerNodes.
Definition: der-node.hpp:190
A Blob holds a pointer to an immutable byte array implemented as const std::vector<uint8_t>.
Definition: blob.hpp:42
A DerOid extends DerNode to represent an object identifier.
Definition: der-node.hpp:412
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:159
DerBoolean extends DerNode to encode a boolean value.
Definition: der-node.hpp:307
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:147
virtual Blob toVal()
Override to return just the byte string.
Definition: der-node.cpp:272
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:119
A DerNull extends DerNode to encode a null value.
Definition: der-node.hpp:397
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:234
DerNode(DerNodeType nodeType)
Create a generic DER node with the given nodeType.
Definition: der-node.hpp:136
virtual void decode(const uint8_t *inputBuf, size_t inputBufLength, size_t startIdx)
Override the base decode to decode and store the data from an input buffer.
Definition: der-node.cpp:240
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:451
DerBoolean(bool value)
Create a new DerBoolean for the value.
Definition: der-node.hpp:313
virtual const std::vector< ptr_lib::shared_ptr< DerNode > > & getChildren()
Get the children of this node.
Definition: der-node.cpp:213
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:93
A DerGeneralizedTime extends DerNode to represent a date and time, with millisecond accuracy...
Definition: der-node.hpp:511
virtual void decode(const uint8_t *inputBuf, size_t inputBufLength, size_t startIdx)
Decode and store the data from an input buffer.
Definition: der-node.cpp:189
A DynamicUInt8Vector extends ndn_DynamicUInt8Array to hold a shared_ptr<vector<uint8_t> > for use wit...
Definition: dynamic-uint8-vector.hpp:37
DerBitString(const uint8_t *inputBuf, size_t inputBufLength, int paddingLength)
Create a DerBitString with the given padding and inputBuf.
Definition: der-node.hpp:361
DerGeneralizedTime(MillisecondsSince1970 msSince1970)
Create a DerGeneralizedTime with the given milliseconds since 1970.
Definition: der-node.hpp:517
void payloadAppend(const uint8_t *value, size_t valueLength)
Call payload_.copy to copy value into payload_ at payloadPosition_.
Definition: der-node.hpp:175
A DerByteString extends DerNode to handle byte strings.
Definition: der-node.hpp:273