blob: c56f999f689d128691117b840af39c220a432f4a [file] [log] [blame]
Jeff Thompsoncfed8322013-10-14 18:00:15 -07001/* -*- 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
13using namespace std;
14
15namespace ndn {
16
17namespace der
18{
19
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070020ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070021SimpleVisitor::visit(DerBool& derBool)
22{
23 bool result = true;
24
25 if(0 == derBool.getPayload()[0])
26 result = false;
27
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070028 return ndnboost::any(result);
Jeff Thompsoncfed8322013-10-14 18:00:15 -070029}
30
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070031ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070032SimpleVisitor::visit(DerInteger& derInteger)
33{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070034 return ndnboost::any(derInteger.getPayload());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070035}
36
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070037ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070038SimpleVisitor::visit(DerPrintableString& derPStr)
39{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070040 return ndnboost::any(string((const char*)&derPStr.getPayload()[0], derPStr.getPayload().size()));
Jeff Thompsoncfed8322013-10-14 18:00:15 -070041}
42
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070043ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070044SimpleVisitor::visit(DerBitString& derBStr)
45{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070046 return ndnboost::any(derBStr.getPayload());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070047}
48
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070049ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070050SimpleVisitor::visit(DerNull& derNull)
51{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070052 return ndnboost::any();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070053}
54
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070055ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070056SimpleVisitor::visit(DerOctetString& derOStr)
57{
Jeff Thompson736a1822013-10-14 18:22:53 -070058 vector<uint8_t> result(derOStr.getPayload());
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070059 return ndnboost::any(result);
Jeff Thompsoncfed8322013-10-14 18:00:15 -070060}
61
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070062ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070063SimpleVisitor::visit(DerOid& derOid)
64{
65 vector<int> intList;
66 int offset = 0;
67
Jeff Thompson736a1822013-10-14 18:22:53 -070068 vector<uint8_t>& blob = derOid.getPayload();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070069
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 Thompsond0a7d6d2013-10-15 12:34:26 -070081 return ndnboost::any(OID(intList));
Jeff Thompsoncfed8322013-10-14 18:00:15 -070082}
83
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070084ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070085SimpleVisitor::visit(DerSequence& derSeq)
86{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070087 return ndnboost::any();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070088}
89
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070090ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070091SimpleVisitor::visit(DerGtime& derGtime)
92{
Jeff Thompson736a1822013-10-14 18:22:53 -070093 string str((const char*)&derGtime.getPayload()[0], derGtime.getPayload().size());
Jeff Thompsona92861a2013-10-16 14:06:23 -070094 return ndnboost::any(DerGtime::fromIsoString(str.substr(0, 8) + "T" + str.substr(8, 6)));
Jeff Thompsoncfed8322013-10-14 18:00:15 -070095}
Jeff Thompsoncfed8322013-10-14 18:00:15 -070096
97} // der
98
99}