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 | |
| 31 | #if 0 |
| 32 | Any |
| 33 | SimpleVisitor::visit(DerInteger& derInteger) |
| 34 | { |
| 35 | return Any(derInteger.getPayload()); |
| 36 | } |
| 37 | |
| 38 | Any |
| 39 | SimpleVisitor::visit(DerPrintableString& derPStr) |
| 40 | { |
| 41 | return Any(string(derPStr.getPayload().buf(), derPStr.getPayload().size())); |
| 42 | } |
| 43 | |
| 44 | Any |
| 45 | SimpleVisitor::visit(DerBitString& derBStr) |
| 46 | { |
| 47 | return Any(derBStr.getPayload()); |
| 48 | } |
| 49 | |
| 50 | Any |
| 51 | SimpleVisitor::visit(DerNull& derNull) |
| 52 | { |
| 53 | return Any(); |
| 54 | } |
| 55 | |
| 56 | Any |
| 57 | SimpleVisitor::visit(DerOctetString& derOStr) |
| 58 | { |
| 59 | Ptr<Blob> result = Ptr<Blob>(new Blob(derOStr.getPayload().buf(), derOStr.getPayload().size())); |
| 60 | return Any(result); |
| 61 | } |
| 62 | |
| 63 | Any |
| 64 | SimpleVisitor::visit(DerOid& derOid) |
| 65 | { |
| 66 | vector<int> intList; |
| 67 | int offset = 0; |
| 68 | |
| 69 | Blob & blob = derOid.getPayload(); |
| 70 | |
| 71 | int first = blob[offset]; |
| 72 | |
| 73 | intList.push_back(first / 40); |
| 74 | intList.push_back(first % 40); |
| 75 | |
| 76 | offset++; |
| 77 | |
| 78 | while(offset < blob.size()){ |
| 79 | intList.push_back(derOid.decode128(offset)); |
| 80 | } |
| 81 | |
| 82 | return Any(OID(intList)); |
| 83 | } |
| 84 | |
| 85 | Any |
| 86 | SimpleVisitor::visit(DerSequence& derSeq) |
| 87 | { |
| 88 | return Any(); |
| 89 | } |
| 90 | |
| 91 | Any |
| 92 | SimpleVisitor::visit(DerGtime& derGtime) |
| 93 | { |
| 94 | string str(derGtime.getPayload().buf() , derGtime.getPayload().size()); |
| 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 | } |