DER encoding: Define InputIterator and OutputIterator in der.hpp and use as in the original.
diff --git a/ndn-cpp/encoding/der/der.hpp b/ndn-cpp/encoding/der/der.hpp
index ff92c78..a02a2e9 100644
--- a/ndn-cpp/encoding/der/der.hpp
+++ b/ndn-cpp/encoding/der/der.hpp
@@ -59,6 +59,23 @@
DER_BMP_STRING = 30,
};
+class InputIterator : public std::istream
+{
+public:
+ uint8_t ReadU8() { return static_cast<uint8_t> (get()); }
+ uint8_t PeekU8() { return static_cast<uint8_t> (peek()); }
+ bool IsEnd() const { return eof(); }
+ void Prev() { seekg(-1, std::ios_base::cur); }
+};
+
+class OutputIterator : public std::ostream
+{
+public:
+ void Write(const uint8_t * s, uint32_t n) { write (reinterpret_cast<const char*>(s),n); }
+ void WriteU8(const uint8_t s) { put (s); }
+ void WriteU8(const uint8_t s, uint32_t n) { for (uint32_t i = 0; i < n; i++) { put(s); } }
+};
+
class DerComplex;
class DerNode
@@ -68,7 +85,7 @@
DerNode(DerType type);
- DerNode(std::istream& start);
+ DerNode(InputIterator& start);
virtual
~DerNode();
@@ -77,13 +94,13 @@
getSize() { return header_.size() + payload_.size(); }
virtual void
- encode(std::ostream& start);
+ encode(OutputIterator& start);
void
setParent(DerComplex * parent) { parent_ = parent; }
static ptr_lib::shared_ptr<DerNode>
- parse(std::istream& start);
+ parse(InputIterator& start);
const std::vector<uint8_t>&
getHeader() const { return header_; }
@@ -117,13 +134,13 @@
protected:
void
- decode(std::istream& start);
+ decode(InputIterator& start);
void
encodeHeader(int size);
int
- decodeHeader(std::istream& start);
+ decodeHeader(InputIterator& start);
protected:
DerType type_;
@@ -142,7 +159,7 @@
DerComplex(DerType type);
- DerComplex(std::istream& start);
+ DerComplex(InputIterator& start);
virtual
~DerComplex();
@@ -154,7 +171,7 @@
addChild(ptr_lib::shared_ptr<DerNode> nodePtr, bool notifyParent = true);
virtual void
- encode(std::ostream& start);
+ encode(OutputIterator& start);
const DerNodePtrList&
getChildren() const { return nodeList_; }
@@ -187,7 +204,7 @@
DerByteString(const std::vector<uint8_t>& blob, DerType type);
- DerByteString(std::istream& start);
+ DerByteString(InputIterator& start);
virtual
~DerByteString();
@@ -200,7 +217,7 @@
public:
DerBool(bool value);
- DerBool(std::istream& start);
+ DerBool(InputIterator& start);
virtual
~DerBool();
@@ -217,7 +234,7 @@
public:
DerInteger(const std::vector<uint8_t>& blob);
- DerInteger(std::istream& start);
+ DerInteger(InputIterator& start);
virtual
~DerInteger();
@@ -234,7 +251,7 @@
public:
DerBitString(const std::vector<uint8_t>& blob, uint8_t paddingLen);
- DerBitString(std::istream& start);
+ DerBitString(InputIterator& start);
virtual
~DerBitString();
@@ -253,7 +270,7 @@
DerOctetString(const std::vector<uint8_t>& blob);
- DerOctetString(std::istream& start);
+ DerOctetString(InputIterator& start);
virtual
~DerOctetString();
@@ -271,7 +288,7 @@
public:
DerNull();
- DerNull(std::istream& start);
+ DerNull(InputIterator& start);
virtual
~DerNull();
@@ -293,7 +310,7 @@
DerOid(const std::vector<int>& value);
- DerOid(std::istream& start);
+ DerOid(InputIterator& start);
virtual
~DerOid();
@@ -321,7 +338,7 @@
public:
DerSequence();
- DerSequence(std::istream& start);
+ DerSequence(InputIterator& start);
virtual
~DerSequence();
@@ -340,7 +357,7 @@
DerPrintableString(const std::vector<uint8_t>& blob);
- DerPrintableString(std::istream& start);
+ DerPrintableString(InputIterator& start);
virtual
~DerPrintableString();
@@ -357,7 +374,7 @@
public:
DerGtime(const MillisecondsSince1970& time);
- DerGtime(std::istream& start);
+ DerGtime(InputIterator& start);
virtual
~DerGtime();