Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -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 | |
Jeff Thompson | 84cfe1d | 2013-10-15 17:59:01 -0700 | [diff] [blame^] | 9 | #if 1 // TODO: Remove this when we don't throw "not implemented". |
| 10 | #include <stdexcept> |
| 11 | #endif |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 12 | #include "simple-visitor.hpp" |
| 13 | #include "../der.hpp" |
| 14 | #include <ndn-cpp/encoding/oid.hpp> |
| 15 | |
| 16 | using namespace std; |
| 17 | |
| 18 | namespace ndn { |
| 19 | |
| 20 | namespace der |
| 21 | { |
| 22 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 23 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 24 | SimpleVisitor::visit(DerBool& derBool) |
| 25 | { |
| 26 | bool result = true; |
| 27 | |
| 28 | if(0 == derBool.getPayload()[0]) |
| 29 | result = false; |
| 30 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 31 | return ndnboost::any(result); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 34 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 35 | SimpleVisitor::visit(DerInteger& derInteger) |
| 36 | { |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 37 | return ndnboost::any(derInteger.getPayload()); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 40 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 41 | SimpleVisitor::visit(DerPrintableString& derPStr) |
| 42 | { |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 43 | return ndnboost::any(string((const char*)&derPStr.getPayload()[0], derPStr.getPayload().size())); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 46 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 47 | SimpleVisitor::visit(DerBitString& derBStr) |
| 48 | { |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 49 | return ndnboost::any(derBStr.getPayload()); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 52 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 53 | SimpleVisitor::visit(DerNull& derNull) |
| 54 | { |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 55 | return ndnboost::any(); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 58 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 59 | SimpleVisitor::visit(DerOctetString& derOStr) |
| 60 | { |
Jeff Thompson | 736a182 | 2013-10-14 18:22:53 -0700 | [diff] [blame] | 61 | vector<uint8_t> result(derOStr.getPayload()); |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 62 | return ndnboost::any(result); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 65 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 66 | SimpleVisitor::visit(DerOid& derOid) |
| 67 | { |
Jeff Thompson | 84cfe1d | 2013-10-15 17:59:01 -0700 | [diff] [blame^] | 68 | #if 0 // Include again when der is defined. |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 69 | vector<int> intList; |
| 70 | int offset = 0; |
| 71 | |
Jeff Thompson | 736a182 | 2013-10-14 18:22:53 -0700 | [diff] [blame] | 72 | vector<uint8_t>& blob = derOid.getPayload(); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 73 | |
| 74 | int first = blob[offset]; |
| 75 | |
| 76 | intList.push_back(first / 40); |
| 77 | intList.push_back(first % 40); |
| 78 | |
| 79 | offset++; |
| 80 | |
| 81 | while(offset < blob.size()){ |
| 82 | intList.push_back(derOid.decode128(offset)); |
| 83 | } |
| 84 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 85 | return ndnboost::any(OID(intList)); |
Jeff Thompson | 84cfe1d | 2013-10-15 17:59:01 -0700 | [diff] [blame^] | 86 | #else |
| 87 | throw std::runtime_error("not implemented"); |
| 88 | #endif |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 91 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 92 | SimpleVisitor::visit(DerSequence& derSeq) |
| 93 | { |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 94 | return ndnboost::any(); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Jeff Thompson | 736a182 | 2013-10-14 18:22:53 -0700 | [diff] [blame] | 97 | #if 0 // TODO: Implmenent alternative to boost::posix_time::from_iso_string. |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 98 | ndnboost::any |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 99 | SimpleVisitor::visit(DerGtime& derGtime) |
| 100 | { |
Jeff Thompson | 736a182 | 2013-10-14 18:22:53 -0700 | [diff] [blame] | 101 | string str((const char*)&derGtime.getPayload()[0], derGtime.getPayload().size()); |
Jeff Thompson | d0a7d6d | 2013-10-15 12:34:26 -0700 | [diff] [blame] | 102 | return ndnboost::any(boost::posix_time::from_iso_string(str.substr(0, 8) + "T" + str.substr(8, 6))); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 103 | } |
| 104 | #endif |
| 105 | |
| 106 | } // der |
| 107 | |
| 108 | } |