blob: 1e4f0fcba2ebf3edbc5870ee391e869c15156012 [file] [log] [blame]
Jeff Thompson6c314bc2013-09-23 18:09:38 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
5 * See COPYING for copyright and distribution information.
6 */
7
8#include <stdexcept>
Jeff Thompson81842272013-09-25 16:12:33 -07009#include "../security-exception.hpp"
Jeff Thompson6c314bc2013-09-23 18:09:38 -070010#include "memory-identity-storage.hpp"
11
12using namespace std;
13using namespace ndn::ptr_lib;
14
15namespace ndn {
16
17MemoryIdentityStorage::~MemoryIdentityStorage()
18{
19}
20
21bool
22MemoryIdentityStorage::doesIdentityExist(const Name& identityName)
23{
Jeff Thompson81842272013-09-25 16:12:33 -070024 string identityUri = identityName.toUri();
25 return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end();
Jeff Thompson6c314bc2013-09-23 18:09:38 -070026}
27
28void
29MemoryIdentityStorage::addIdentity(const Name& identityName)
30{
Jeff Thompson81842272013-09-25 16:12:33 -070031 string identityUri = identityName.toUri();
32 if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
33 throw SecurityException("Identity already exists: " + identityUri);
34
35 identityStore_.push_back(identityUri);
Jeff Thompson6c314bc2013-09-23 18:09:38 -070036}
37
38bool
39MemoryIdentityStorage::revokeIdentity()
40{
41#if 1
42 throw std::runtime_error("MemoryIdentityStorage::revokeIdentity not implemented");
43#endif
44}
45
46Name
47MemoryIdentityStorage::getNewKeyName(const Name& identityName, bool useKsk)
48{
49#if 1
50 throw std::runtime_error("MemoryIdentityStorage::getNewKeyName not implemented");
51#endif
52}
53
54bool
55MemoryIdentityStorage::doesKeyExist(const Name& keyName)
56{
57#if 1
58 throw std::runtime_error("MemoryIdentityStorage::doesKeyExist not implemented");
59#endif
60}
61
62Name
63MemoryIdentityStorage::getKeyNameForCertificate(const Name& certificateName)
64{
65 int i = certificateName.getComponentCount() - 1;
66
67 for (; i >= 0; --i) {
68 if(certificateName.getComponent(i).toEscapedString() == string("ID-CERT"))
69 break;
70 }
71
72 return certificateName.getSubName(0, i);
73}
74
75void
76MemoryIdentityStorage::addKey(const Name& keyName, KeyType keyType, Blob& publicKeyDer)
77{
78#if 1
79 throw std::runtime_error("MemoryIdentityStorage::addKey not implemented");
80#endif
81}
82
83Blob
84MemoryIdentityStorage::getKey(const Name& keyName)
85{
86#if 1
87 throw std::runtime_error("MemoryIdentityStorage::getKey not implemented");
88#endif
89}
90
91void
92MemoryIdentityStorage::activateKey(const Name& keyName)
93{
94#if 1
95 throw std::runtime_error("MemoryIdentityStorage::activateKey not implemented");
96#endif
97}
98
99void
100MemoryIdentityStorage::deactivateKey(const Name& keyName)
101{
102#if 1
103 throw std::runtime_error("MemoryIdentityStorage::deactivateKey not implemented");
104#endif
105}
106
107bool
108MemoryIdentityStorage::doesCertificateExist(const Name& certificateName)
109{
110#if 1
111 throw std::runtime_error("MemoryIdentityStorage::doesCertificateExist not implemented");
112#endif
113}
114
115void
116MemoryIdentityStorage::addCertificate(const Certificate& certificate)
117{
118#if 1
119 throw std::runtime_error("MemoryIdentityStorage::addCertificate not implemented");
120#endif
121}
122
Jeff Thompsona6fd6382013-09-24 15:23:37 -0700123ptr_lib::shared_ptr<Certificate>
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700124MemoryIdentityStorage::getCertificate(const Name &certificateName, bool allowAny)
125{
126#if 1
127 throw std::runtime_error("MemoryIdentityStorage::getCertificate not implemented");
128#endif
129}
130
131Name
132MemoryIdentityStorage::getDefaultIdentity()
133{
Jeff Thompson81842272013-09-25 16:12:33 -0700134 return Name(defaultIdentity_);
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700135}
136
137Name
138MemoryIdentityStorage::getDefaultKeyNameForIdentity(const Name& identityName)
139{
140#if 1
141 throw std::runtime_error("MemoryIdentityStorage::getDefaultKeyNameForIdentity not implemented");
142#endif
143}
144
145Name
146MemoryIdentityStorage::getDefaultCertificateNameForKey(const Name& keyName)
147{
148#if 1
149 throw std::runtime_error("MemoryIdentityStorage::getDefaultCertificateNameForKey not implemented");
150#endif
151}
152
153void
154MemoryIdentityStorage::setDefaultIdentity(const Name& identityName)
155{
Jeff Thompson81842272013-09-25 16:12:33 -0700156 string identityUri = identityName.toUri();
157 if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
158 defaultIdentity_ = identityUri;
159 else
160 // The identity doesn't exist, so clear the default.
161 defaultIdentity_.clear();
Jeff Thompson6c314bc2013-09-23 18:09:38 -0700162}
163
164void
165MemoryIdentityStorage::setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName)
166{
167#if 1
168 throw std::runtime_error("MemoryIdentityStorage::setDefaultKeyNameForIdentity not implemented");
169#endif
170}
171
172void
173MemoryIdentityStorage::setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName)
174{
175#if 1
176 throw std::runtime_error("MemoryIdentityStorage::setDefaultCertificateNameForKey not implemented");
177#endif
178}
179
180}