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