blob: 8539950366e6e0051abd68a1feca39f30bc94d96 [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
Jeff Thompson84cfe1d2013-10-15 17:59:01 -07009#if 1 // TODO: Remove this when we don't throw "not implemented".
10#include <stdexcept>
11#endif
Jeff Thompsoncfed8322013-10-14 18:00:15 -070012#include "simple-visitor.hpp"
13#include "../der.hpp"
14#include <ndn-cpp/encoding/oid.hpp>
15
16using namespace std;
17
18namespace ndn {
19
20namespace der
21{
22
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070023ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070024SimpleVisitor::visit(DerBool& derBool)
25{
26 bool result = true;
27
28 if(0 == derBool.getPayload()[0])
29 result = false;
30
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070031 return ndnboost::any(result);
Jeff Thompsoncfed8322013-10-14 18:00:15 -070032}
33
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070034ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070035SimpleVisitor::visit(DerInteger& derInteger)
36{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070037 return ndnboost::any(derInteger.getPayload());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070038}
39
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070040ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070041SimpleVisitor::visit(DerPrintableString& derPStr)
42{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070043 return ndnboost::any(string((const char*)&derPStr.getPayload()[0], derPStr.getPayload().size()));
Jeff Thompsoncfed8322013-10-14 18:00:15 -070044}
45
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070046ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070047SimpleVisitor::visit(DerBitString& derBStr)
48{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070049 return ndnboost::any(derBStr.getPayload());
Jeff Thompsoncfed8322013-10-14 18:00:15 -070050}
51
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070052ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070053SimpleVisitor::visit(DerNull& derNull)
54{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070055 return ndnboost::any();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070056}
57
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070058ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070059SimpleVisitor::visit(DerOctetString& derOStr)
60{
Jeff Thompson736a1822013-10-14 18:22:53 -070061 vector<uint8_t> result(derOStr.getPayload());
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070062 return ndnboost::any(result);
Jeff Thompsoncfed8322013-10-14 18:00:15 -070063}
64
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070065ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070066SimpleVisitor::visit(DerOid& derOid)
67{
Jeff Thompson84cfe1d2013-10-15 17:59:01 -070068#if 0 // Include again when der is defined.
Jeff Thompsoncfed8322013-10-14 18:00:15 -070069 vector<int> intList;
70 int offset = 0;
71
Jeff Thompson736a1822013-10-14 18:22:53 -070072 vector<uint8_t>& blob = derOid.getPayload();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070073
74 int first = blob[offset];
75
76 intList.push_back(first / 40);
77 intList.push_back(first % 40);
78
79 offset++;
80
81 while(offset < blob.size()){
82 intList.push_back(derOid.decode128(offset));
83 }
84
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070085 return ndnboost::any(OID(intList));
Jeff Thompson84cfe1d2013-10-15 17:59:01 -070086#else
87 throw std::runtime_error("not implemented");
88#endif
Jeff Thompsoncfed8322013-10-14 18:00:15 -070089}
90
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070091ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070092SimpleVisitor::visit(DerSequence& derSeq)
93{
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070094 return ndnboost::any();
Jeff Thompsoncfed8322013-10-14 18:00:15 -070095}
96
Jeff Thompson736a1822013-10-14 18:22:53 -070097#if 0 // TODO: Implmenent alternative to boost::posix_time::from_iso_string.
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -070098ndnboost::any
Jeff Thompsoncfed8322013-10-14 18:00:15 -070099SimpleVisitor::visit(DerGtime& derGtime)
100{
Jeff Thompson736a1822013-10-14 18:22:53 -0700101 string str((const char*)&derGtime.getPayload()[0], derGtime.getPayload().size());
Jeff Thompsond0a7d6d2013-10-15 12:34:26 -0700102 return ndnboost::any(boost::posix_time::from_iso_string(str.substr(0, 8) + "T" + str.substr(8, 6)));
Jeff Thompsoncfed8322013-10-14 18:00:15 -0700103}
104#endif
105
106} // der
107
108}