Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 5 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
| 6 | * See COPYING for copyright and distribution information. |
| 7 | */ |
| 8 | |
| 9 | #ifndef NDN_DER_HPP |
| 10 | #define NDN_DER_HPP |
| 11 | |
| 12 | #include <vector> |
| 13 | #include <string> |
| 14 | #include <istream> |
| 15 | #include <ostream> |
| 16 | #include <sstream> |
| 17 | |
| 18 | #include <ndn-cpp/common.hpp> |
| 19 | #include <ndn-cpp/encoding/oid.hpp> |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame^] | 20 | #include <ndn-cpp/util/blob.hpp> |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 21 | |
| 22 | #include "visitor/visitor.hpp" |
| 23 | #include "visitor/void-visitor.hpp" |
| 24 | #include "visitor/no-arguments-visitor.hpp" |
| 25 | #include "visitor/void-no-arguments-visitor.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 29 | namespace der { |
| 30 | |
| 31 | enum DerType { |
| 32 | DER_EOC = 0, |
| 33 | DER_BOOLEAN = 1, |
| 34 | DER_INTEGER = 2, |
| 35 | DER_BIT_STRING = 3, |
| 36 | DER_OCTET_STRING = 4, |
| 37 | DER_NULL = 5, |
| 38 | DER_OBJECT_IDENTIFIER = 6, |
| 39 | DER_OBJECT_DESCRIPTOR = 7, |
| 40 | DER_EXTERNAL = 40, |
| 41 | DER_REAL = 9, |
| 42 | DER_ENUMERATED = 10, |
| 43 | DER_EMBEDDED_PDV = 43, |
| 44 | DER_UTF8_STRING = 12, |
| 45 | DER_RELATIVE_OID = 13, |
| 46 | DER_SEQUENCE = 48, |
| 47 | DER_SET = 49, |
| 48 | DER_NUMERIC_STRING = 18, |
| 49 | DER_PRINTABLE_STRING = 19, |
| 50 | DER_T61_STRING = 20, |
| 51 | DER_VIDEOTEX_STRING = 21, |
| 52 | DER_IA5_STRING = 22, |
| 53 | DER_UTC_TIME = 23, |
| 54 | DER_GENERALIZED_TIME = 24, |
| 55 | DER_GRAPHIC_STRING = 25, |
| 56 | DER_VISIBLE_STRING = 26, |
| 57 | DER_GENERAL_STRING = 27, |
| 58 | DER_UNIVERSAL_STRING = 28, |
| 59 | DER_CHARACTER_STRING = 29, |
| 60 | DER_BMP_STRING = 30, |
| 61 | }; |
| 62 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 63 | class InputIterator : public std::istream |
| 64 | { |
| 65 | public: |
| 66 | uint8_t ReadU8() { return static_cast<uint8_t> (get()); } |
| 67 | uint8_t PeekU8() { return static_cast<uint8_t> (peek()); } |
| 68 | bool IsEnd() const { return eof(); } |
| 69 | void Prev() { seekg(-1, std::ios_base::cur); } |
| 70 | }; |
| 71 | |
| 72 | class OutputIterator : public std::ostream |
| 73 | { |
| 74 | public: |
| 75 | void Write(const uint8_t * s, uint32_t n) { write (reinterpret_cast<const char*>(s),n); } |
| 76 | void WriteU8(const uint8_t s) { put (s); } |
| 77 | void WriteU8(const uint8_t s, uint32_t n) { for (uint32_t i = 0; i < n; i++) { put(s); } } |
| 78 | }; |
| 79 | |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 80 | class DerComplex; |
| 81 | |
| 82 | class DerNode |
| 83 | { |
| 84 | public: |
| 85 | DerNode(); |
| 86 | |
| 87 | DerNode(DerType type); |
| 88 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 89 | DerNode(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 90 | |
| 91 | virtual |
| 92 | ~DerNode(); |
| 93 | |
| 94 | virtual int |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 95 | getSize() { return header_.size() + payload_.size(); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 96 | |
| 97 | virtual void |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 98 | encode(OutputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 99 | |
| 100 | void |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 101 | setParent(DerComplex * parent) { parent_ = parent; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 102 | |
| 103 | static ptr_lib::shared_ptr<DerNode> |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 104 | parse(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 105 | |
| 106 | const std::vector<uint8_t>& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 107 | getHeader() const { return header_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 108 | |
| 109 | std::vector<uint8_t>& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 110 | getHeader() { return header_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 111 | |
| 112 | const std::vector<uint8_t>& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 113 | getPayload() const { return payload_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 114 | |
| 115 | std::vector<uint8_t>& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 116 | getPayload() { return payload_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 117 | |
| 118 | const DerType& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 119 | getType() { return type_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 120 | |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame^] | 121 | virtual Blob |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 122 | getRaw() |
| 123 | { |
| 124 | ptr_lib::shared_ptr<std::vector<uint8_t> > blob(new std::vector<uint8_t>()); |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 125 | blob->insert(blob->end(), header_.begin(), header_.end()); |
| 126 | blob->insert(blob->end(), payload_.begin(), payload_.end()); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 127 | |
| 128 | return blob; |
| 129 | } |
| 130 | |
| 131 | virtual void accept(VoidNoArgumentsVisitor& visitor) = 0; |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 132 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) = 0; |
| 133 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) = 0; |
| 134 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) = 0; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 135 | |
| 136 | protected: |
| 137 | void |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 138 | decode(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 139 | |
| 140 | void |
| 141 | encodeHeader(int size); |
| 142 | |
| 143 | int |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 144 | decodeHeader(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 145 | |
| 146 | protected: |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 147 | DerType type_; |
| 148 | std::vector<uint8_t> header_; |
| 149 | std::vector<uint8_t> payload_; |
| 150 | DerComplex * parent_; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | |
| 154 | typedef std::vector<ptr_lib::shared_ptr<DerNode> > DerNodePtrList; |
| 155 | |
| 156 | class DerComplex : public DerNode |
| 157 | { |
| 158 | public: |
| 159 | DerComplex(); |
| 160 | |
| 161 | DerComplex(DerType type); |
| 162 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 163 | DerComplex(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 164 | |
| 165 | virtual |
| 166 | ~DerComplex(); |
| 167 | |
| 168 | virtual int |
| 169 | getSize(); |
| 170 | |
| 171 | void |
| 172 | addChild(ptr_lib::shared_ptr<DerNode> nodePtr, bool notifyParent = true); |
| 173 | |
| 174 | virtual void |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 175 | encode(OutputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 176 | |
| 177 | const DerNodePtrList& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 178 | getChildren() const { return nodeList_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 179 | |
| 180 | DerNodePtrList& |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 181 | getChildren() { return nodeList_; } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 182 | |
Jeff Thompson | 415da1e | 2013-10-17 16:52:59 -0700 | [diff] [blame^] | 183 | virtual Blob |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 184 | getRaw(); |
| 185 | |
| 186 | private: |
| 187 | void |
| 188 | updateSize(); |
| 189 | |
| 190 | void |
| 191 | setChildChanged(); |
| 192 | |
| 193 | private: |
Jeff Thompson | 7ff36fe | 2013-10-16 15:30:13 -0700 | [diff] [blame] | 194 | bool childChanged_; |
| 195 | int size_; |
| 196 | DerNodePtrList nodeList_; |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | |
| 200 | |
| 201 | class DerByteString : public DerNode |
| 202 | { |
| 203 | public: |
| 204 | DerByteString(const std::string& str, DerType type); |
| 205 | |
| 206 | DerByteString(const std::vector<uint8_t>& blob, DerType type); |
| 207 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 208 | DerByteString(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 209 | |
| 210 | virtual |
| 211 | ~DerByteString(); |
| 212 | }; |
| 213 | |
| 214 | |
| 215 | //0x01 |
| 216 | class DerBool : public DerNode |
| 217 | { |
| 218 | public: |
| 219 | DerBool(bool value); |
| 220 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 221 | DerBool(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 222 | |
| 223 | virtual |
| 224 | ~DerBool(); |
| 225 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 226 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 227 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 228 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 229 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | //0x02 |
| 233 | class DerInteger : public DerNode |
| 234 | { |
| 235 | public: |
| 236 | DerInteger(const std::vector<uint8_t>& blob); |
| 237 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 238 | DerInteger(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 239 | |
| 240 | virtual |
| 241 | ~DerInteger(); |
| 242 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 243 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 244 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 245 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 246 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | //0x03 |
| 250 | class DerBitString : public DerNode |
| 251 | { |
| 252 | public: |
| 253 | DerBitString(const std::vector<uint8_t>& blob, uint8_t paddingLen); |
| 254 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 255 | DerBitString(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 256 | |
| 257 | virtual |
| 258 | ~DerBitString(); |
| 259 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 260 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 261 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 262 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 263 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 264 | }; |
| 265 | |
| 266 | //0x04 |
| 267 | class DerOctetString : public DerByteString |
| 268 | { |
| 269 | public: |
| 270 | DerOctetString(const std::string& str); |
| 271 | |
| 272 | DerOctetString(const std::vector<uint8_t>& blob); |
| 273 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 274 | DerOctetString(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 275 | |
| 276 | virtual |
| 277 | ~DerOctetString(); |
| 278 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 279 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 280 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 281 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 282 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | |
| 286 | //0x05 |
| 287 | class DerNull : public DerNode |
| 288 | { |
| 289 | public: |
| 290 | DerNull(); |
| 291 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 292 | DerNull(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 293 | |
| 294 | virtual |
| 295 | ~DerNull(); |
| 296 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 297 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 298 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 299 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 300 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | |
| 304 | //0x06 |
| 305 | class DerOid : public DerNode |
| 306 | { |
| 307 | public: |
| 308 | DerOid(const OID& oid); |
| 309 | |
| 310 | DerOid(const std::string& oidStr); |
| 311 | |
| 312 | DerOid(const std::vector<int>& value); |
| 313 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 314 | DerOid(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 315 | |
| 316 | virtual |
| 317 | ~DerOid(); |
| 318 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 319 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 320 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 321 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 322 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 323 | |
| 324 | int |
| 325 | decode128(int& offset); |
| 326 | |
| 327 | private: |
| 328 | void |
| 329 | prepareEncoding(const std::vector<int>& value); |
| 330 | |
| 331 | void |
| 332 | encode128(int value, std::ostringstream& os); |
| 333 | }; |
| 334 | |
| 335 | |
| 336 | //0x10 |
| 337 | class DerSequence : public DerComplex |
| 338 | { |
| 339 | public: |
| 340 | DerSequence(); |
| 341 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 342 | DerSequence(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 343 | |
| 344 | virtual |
| 345 | ~DerSequence(); |
| 346 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 347 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 348 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 349 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 350 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | //0x13 |
| 354 | class DerPrintableString : public DerByteString |
| 355 | { |
| 356 | public: |
| 357 | DerPrintableString(const std::string& str); |
| 358 | |
| 359 | DerPrintableString(const std::vector<uint8_t>& blob); |
| 360 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 361 | DerPrintableString(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 362 | |
| 363 | virtual |
| 364 | ~DerPrintableString(); |
| 365 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 366 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 367 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 368 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 369 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | //0x1b |
| 373 | class DerGtime : public DerNode |
| 374 | { |
| 375 | public: |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 376 | DerGtime(const MillisecondsSince1970& time); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 377 | |
Jeff Thompson | 2d47db7 | 2013-10-17 15:19:52 -0700 | [diff] [blame] | 378 | DerGtime(InputIterator& start); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 379 | |
| 380 | virtual |
| 381 | ~DerGtime(); |
| 382 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 383 | virtual void accept(VoidNoArgumentsVisitor& visitor) { visitor.visit(*this); } |
| 384 | virtual void accept(VoidVisitor& visitor, ndnboost::any param) { visitor.visit(*this, param); } |
| 385 | virtual ndnboost::any accept(NoArgumentsVisitor& visitor) { return visitor.visit(*this); } |
| 386 | virtual ndnboost::any accept(Visitor& visitor, ndnboost::any param) { return visitor.visit(*this, param); } |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 387 | |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 388 | /** |
| 389 | * Convert to the ISO string representation of the time. |
| 390 | * @param time Milliseconds since 1/1/1970. |
| 391 | * @return The ISO string. |
| 392 | */ |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 393 | static std::string toIsoString(const MillisecondsSince1970& time); |
Jeff Thompson | a92861a | 2013-10-16 14:06:23 -0700 | [diff] [blame] | 394 | |
| 395 | /** |
| 396 | * Convert from the ISO string representation to the internal time format. |
| 397 | * @param isoString The ISO time formatted string. |
| 398 | * @return The time in milliseconds since 1/1/1970. |
| 399 | */ |
Jeff Thompson | 9a8e82f | 2013-10-17 14:13:43 -0700 | [diff] [blame] | 400 | static MillisecondsSince1970 fromIsoString(const std::string& isoString); |
Jeff Thompson | 958bf9b | 2013-10-12 17:20:51 -0700 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | } // der |
| 404 | |
| 405 | } |
| 406 | |
| 407 | #endif |