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