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 | |
| 20 | Any |
| 21 | SimpleVisitor::visit(DerBool& derBool) |
| 22 | { |
| 23 | bool result = true; |
| 24 | |
| 25 | if(0 == derBool.getPayload()[0]) |
| 26 | result = false; |
| 27 | |
| 28 | return Any(result); |
| 29 | } |
| 30 | |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 31 | Any |
| 32 | SimpleVisitor::visit(DerInteger& derInteger) |
| 33 | { |
| 34 | return Any(derInteger.getPayload()); |
| 35 | } |
| 36 | |
| 37 | Any |
| 38 | SimpleVisitor::visit(DerPrintableString& derPStr) |
| 39 | { |
Jeff Thompson | 736a182 | 2013-10-14 18:22:53 -0700 | [diff] [blame^] | 40 | return Any(string((const char*)&derPStr.getPayload()[0], derPStr.getPayload().size())); |
Jeff Thompson | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | Any |
| 44 | SimpleVisitor::visit(DerBitString& derBStr) |
| 45 | { |
| 46 | return Any(derBStr.getPayload()); |
| 47 | } |
| 48 | |
| 49 | Any |
| 50 | SimpleVisitor::visit(DerNull& derNull) |
| 51 | { |
| 52 | return Any(); |
| 53 | } |
| 54 | |
| 55 | Any |
| 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 | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 59 | return Any(result); |
| 60 | } |
| 61 | |
| 62 | Any |
| 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 | |
| 81 | return Any(OID(intList)); |
| 82 | } |
| 83 | |
| 84 | Any |
| 85 | SimpleVisitor::visit(DerSequence& derSeq) |
| 86 | { |
| 87 | return Any(); |
| 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 | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 91 | Any |
| 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 | cfed832 | 2013-10-14 18:00:15 -0700 | [diff] [blame] | 95 | return Any(boost::posix_time::from_iso_string(str.substr(0, 8) + "T" + str.substr(8, 6))); |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | } // der |
| 100 | |
| 101 | } |