blob: e2ea049abe9825e0c01a295a77aefde7e58b8d09 [file] [log] [blame]
Jeff Thompson415da1e2013-10-17 16:52:59 -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 "public-key-visitor.hpp"
11#include "../der.hpp"
12
13#include <ndn-cpp/security/certificate/certificate.hpp>
14#include <ndn-cpp/security/certificate/certificate-subject-description.hpp>
15#include <ndn-cpp/security/certificate/certificate-extension.hpp>
16
17#include "../../../util/logging.hpp"
18#include "certificate-data-visitor.hpp"
19
20using namespace std;
21using namespace ndn::ptr_lib;
22
23INIT_LOGGER("ndn.der.CertificateDataVisitor");
24
25namespace ndn {
26
27namespace der {
28
29/*
30 * CertificateDataVisitor
31 */
32void
33CertificateDataVisitor::visit(DerSequence& derSeq, ndnboost::any param)
34{
35 // _LOG_DEBUG("CertificateDataVisitor::visit");
36
37 const DerNodePtrList& children = derSeq.getChildren();
38 CertValidityVisitor validityVisitor;
39 children[0]->accept(validityVisitor, param);
40 CertSubjectVisitor subjectVisitor;
41 children[1]->accept(subjectVisitor, param);
42 PublicKeyVisitor pubkeyVisitor;
43 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
44 certData->setPublicKeyInfo(*ndnboost::any_cast<shared_ptr<PublicKey> >(children[2]->accept(pubkeyVisitor)));
45
46 if(children.size() > 3)
47 {
48 CertExtensionVisitor extnVisitor;
49 children[3]->accept(extnVisitor, param);
50 }
51}
52
53/*
54 * CertValidityVisitor
55 */
56void
57CertValidityVisitor::visit(DerSequence& derSeq, ndnboost::any param)
58{
59 // _LOG_DEBUG("CertValidityVisitor::visit");
60
61 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
62
63 const DerNodePtrList& children = derSeq.getChildren();
64
65 SimpleVisitor simpleVisitor;
66
67 MillisecondsSince1970 notBefore = ndnboost::any_cast<MillisecondsSince1970>(children[0]->accept(simpleVisitor));
68 MillisecondsSince1970 notAfter = ndnboost::any_cast<MillisecondsSince1970>(children[1]->accept(simpleVisitor));
69
70 // _LOG_DEBUG("parsed notBefore: " << notBefore);
71 // _LOG_DEBUG("parsed notAfter: " << notAfter);
72
73 certData->setNotBefore(notBefore);
74 certData->setNotAfter(notAfter);
75}
76
77/*
78 * CertSubDescryptVisitor
79 */
80void
81CertSubDescryptVisitor::visit(DerSequence& derSeq, ndnboost::any param)
82{
83 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
84
85 const DerNodePtrList& children = derSeq.getChildren();
86
87 SimpleVisitor simpleVisitor;
88
89 OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
90 string value = ndnboost::any_cast<string>(children[1]->accept(simpleVisitor));
91
92 CertificateSubjectDescription subDescrypt(oid, value);
93
94 certData->addSubjectDescription(subDescrypt);
95}
96
97/*
98 * CertSubjectVisitor
99 */
100void
101CertSubjectVisitor::visit(DerSequence& derSeq, ndnboost::any param)
102{
103 // _LOG_DEBUG("CertSubjectVisitor::visit");
104
105 const DerNodePtrList& children = derSeq.getChildren();
106
107 CertSubDescryptVisitor descryptVisitor;
108
109 DerNodePtrList::const_iterator it = children.begin();
110
111 while(it != children.end()) {
112 (*it)->accept(descryptVisitor, param);
113 it++;
114 }
115}
116
117/*
118 * CertExtnEntryVisitor
119 */
120void
121CertExtnEntryVisitor::visit(DerSequence& derSeq, ndnboost::any param)
122{
123 Certificate* certData = ndnboost::any_cast<Certificate*>(param);
124
125 const DerNodePtrList& children = derSeq.getChildren();
126
127 SimpleVisitor simpleVisitor;
128
129 OID oid = ndnboost::any_cast<OID>(children[0]->accept(simpleVisitor));
130 bool critical = ndnboost::any_cast<bool>(children[1]->accept(simpleVisitor));
131 const Blob& value = ndnboost::any_cast<const Blob&>(children[2]->accept(simpleVisitor));
132
133 CertificateExtension extension(oid, critical, value);
134
135 certData->addExtension(extension);
136}
137
138/*
139 * CertExtensionVisitor
140 */
141void
142CertExtensionVisitor::visit(DerSequence& derSeq, ndnboost::any param)
143{
144 const DerNodePtrList& children = derSeq.getChildren();
145
146 CertExtnEntryVisitor extnEntryVisitor;
147
148 DerNodePtrList::const_iterator it = children.begin();
149
150 while(it != children.end()) {
151 (*it)->accept(extnEntryVisitor, param);
152 it++;
153 }
154}
155
156} // der
157
158}