blob: 5845e222ec01acd3cbbfcb61a3d5b400a2326389 [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
20Any
21SimpleVisitor::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 Thompsoncfed8322013-10-14 18:00:15 -070031Any
32SimpleVisitor::visit(DerInteger& derInteger)
33{
34 return Any(derInteger.getPayload());
35}
36
37Any
38SimpleVisitor::visit(DerPrintableString& derPStr)
39{
Jeff Thompson736a1822013-10-14 18:22:53 -070040 return Any(string((const char*)&derPStr.getPayload()[0], derPStr.getPayload().size()));
Jeff Thompsoncfed8322013-10-14 18:00:15 -070041}
42
43Any
44SimpleVisitor::visit(DerBitString& derBStr)
45{
46 return Any(derBStr.getPayload());
47}
48
49Any
50SimpleVisitor::visit(DerNull& derNull)
51{
52 return Any();
53}
54
55Any
56SimpleVisitor::visit(DerOctetString& derOStr)
57{
Jeff Thompson736a1822013-10-14 18:22:53 -070058 vector<uint8_t> result(derOStr.getPayload());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070059 return Any(result);
60}
61
62Any
63SimpleVisitor::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
81 return Any(OID(intList));
82}
83
84Any
85SimpleVisitor::visit(DerSequence& derSeq)
86{
87 return Any();
88}
89
Jeff Thompson736a1822013-10-14 18:22:53 -070090#if 0 // TODO: Implmenent alternative to boost::posix_time::from_iso_string.
Jeff Thompsoncfed8322013-10-14 18:00:15 -070091Any
92SimpleVisitor::visit(DerGtime& derGtime)
93{
Jeff Thompson736a1822013-10-14 18:22:53 -070094 string str((const char*)&derGtime.getPayload()[0], derGtime.getPayload().size());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070095 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}