blob: f71ad56f806fa462b0e9851ac17710102e1ceda6 [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
31#if 0
32Any
33SimpleVisitor::visit(DerInteger& derInteger)
34{
35 return Any(derInteger.getPayload());
36}
37
38Any
39SimpleVisitor::visit(DerPrintableString& derPStr)
40{
41 return Any(string(derPStr.getPayload().buf(), derPStr.getPayload().size()));
42}
43
44Any
45SimpleVisitor::visit(DerBitString& derBStr)
46{
47 return Any(derBStr.getPayload());
48}
49
50Any
51SimpleVisitor::visit(DerNull& derNull)
52{
53 return Any();
54}
55
56Any
57SimpleVisitor::visit(DerOctetString& derOStr)
58{
59 Ptr<Blob> result = Ptr<Blob>(new Blob(derOStr.getPayload().buf(), derOStr.getPayload().size()));
60 return Any(result);
61}
62
63Any
64SimpleVisitor::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
85Any
86SimpleVisitor::visit(DerSequence& derSeq)
87{
88 return Any();
89}
90
91Any
92SimpleVisitor::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}