blob: 82affaa24bce9f79ac2f8332b8b5e7dab53e9bdc [file] [log] [blame]
Yingdi Yu87581582014-01-14 14:28:39 -08001/* -*- 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
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -08008#include "common.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -08009
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080010#include "sec-public-info-memory.hpp"
11#include "identity-certificate.hpp"
Yingdi Yu87581582014-01-14 14:28:39 -080012
13using namespace std;
14
15namespace ndn {
16
17SecPublicInfoMemory::~SecPublicInfoMemory()
18{
19}
20
21bool
22SecPublicInfoMemory::doesIdentityExist(const Name& identityName)
23{
24 string identityUri = identityName.toUri();
25 return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end();
26}
27
28void
29SecPublicInfoMemory::addIdentity(const Name& identityName)
30{
31 string identityUri = identityName.toUri();
32 if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080033 return;
Yingdi Yu87581582014-01-14 14:28:39 -080034
35 identityStore_.push_back(identityUri);
36}
37
38bool
39SecPublicInfoMemory::revokeIdentity()
40{
41#if 1
Yingdi Yu2e57a582014-02-20 23:34:43 -080042 throw Error("SecPublicInfoMemory::revokeIdentity not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -080043#endif
44}
45
46bool
47SecPublicInfoMemory::doesPublicKeyExist(const Name& keyName)
48{
49 return keyStore_.find(keyName.toUri()) != keyStore_.end();
50}
51
52void
53SecPublicInfoMemory::addPublicKey(const Name& keyName, KeyType keyType, const PublicKey& publicKey)
54{
55 Name identityName = keyName.getSubName(0, keyName.size() - 1);
56
Yingdi Yu2e57a582014-02-20 23:34:43 -080057 addIdentity(identityName);
Yingdi Yu87581582014-01-14 14:28:39 -080058
Yingdi Yu2e57a582014-02-20 23:34:43 -080059 keyStore_[keyName.toUri()] = make_shared<KeyRecord>(keyType, publicKey);
Yingdi Yu87581582014-01-14 14:28:39 -080060}
61
Yingdi Yu2e57a582014-02-20 23:34:43 -080062shared_ptr<PublicKey>
Yingdi Yu87581582014-01-14 14:28:39 -080063SecPublicInfoMemory::getPublicKey(const Name& keyName)
64{
65 KeyStore::iterator record = keyStore_.find(keyName.toUri());
66 if (record == keyStore_.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080067 throw Error("SecPublicInfoMemory::getPublicKey " + keyName.toUri());
Yingdi Yu87581582014-01-14 14:28:39 -080068
Yingdi Yu2e57a582014-02-20 23:34:43 -080069 return make_shared<PublicKey> (record->second->getKey());
Yingdi Yu87581582014-01-14 14:28:39 -080070}
71
72bool
73SecPublicInfoMemory::doesCertificateExist(const Name& certificateName)
74{
75 return certificateStore_.find(certificateName.toUri()) != certificateStore_.end();
76}
77
78void
79SecPublicInfoMemory::addCertificate(const IdentityCertificate& certificate)
80{
81 const Name& certificateName = certificate.getName();
82 const Name& keyName = certificate.getPublicKeyName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080083 const Name& identity = keyName.getPrefix(-1);
Yingdi Yu87581582014-01-14 14:28:39 -080084
Yingdi Yu2e57a582014-02-20 23:34:43 -080085 addIdentity(identity);
86 addPublicKey(keyName, KEY_TYPE_RSA, certificate.getPublicKeyInfo());
87 certificateStore_[certificateName.toUri()] = make_shared<IdentityCertificate> (certificate);
Yingdi Yu87581582014-01-14 14:28:39 -080088}
89
Yingdi Yu2e57a582014-02-20 23:34:43 -080090shared_ptr<IdentityCertificate>
Yingdi Yu88663af2014-01-15 15:21:38 -080091SecPublicInfoMemory::getCertificate(const Name& certificateName)
Yingdi Yu87581582014-01-14 14:28:39 -080092{
93 CertificateStore::iterator record = certificateStore_.find(certificateName.toUri());
94 if (record == certificateStore_.end())
Yingdi Yu2e57a582014-02-20 23:34:43 -080095 throw Error("SecPublicInfoMemory::getCertificate " + certificateName.toUri());
Yingdi Yu87581582014-01-14 14:28:39 -080096
97 return record->second;
98}
99
100Name
101SecPublicInfoMemory::getDefaultIdentity()
102{
103 return Name(defaultIdentity_);
104}
105
106void
107SecPublicInfoMemory::setDefaultIdentityInternal(const Name& identityName)
108{
109 string identityUri = identityName.toUri();
110 if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end())
111 defaultIdentity_ = identityUri;
112 else
113 // The identity doesn't exist, so clear the default.
114 defaultIdentity_.clear();
115}
116
117Name
118SecPublicInfoMemory::getDefaultKeyNameForIdentity(const Name& identityName)
119{
120 return defaultKeyName_;
121}
122
123void
124SecPublicInfoMemory::setDefaultKeyNameForIdentityInternal(const Name& keyName)
125{
126 defaultKeyName_ = keyName;
127}
128
129Name
130SecPublicInfoMemory::getDefaultCertificateNameForKey(const Name& keyName)
131{
132 return defaultCert_;
133}
134
135void
136SecPublicInfoMemory::setDefaultCertificateNameForKeyInternal(const Name& certificateName)
137{
138 defaultCert_ = certificateName;
139}
140
141
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800142void
143SecPublicInfoMemory::getAllIdentities(std::vector<Name> &nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800144{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800145 throw Error("SecPublicInfoMemory::getAllIdentities not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800146}
147
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800148void
149SecPublicInfoMemory::getAllKeyNames(std::vector<Name> &nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800150{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800151 throw Error("SecPublicInfoMemory::getAllKeyNames not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800152}
153
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800154void
155SecPublicInfoMemory::getAllKeyNamesOfIdentity(const Name& identity, std::vector<Name> &nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800156{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800157 throw Error("SecPublicInfoMemory::getAllKeyNamesOfIdentity not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800158}
159
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800160void
161SecPublicInfoMemory::getAllCertificateNames(std::vector<Name> &nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800162{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800163 throw Error("SecPublicInfoMemory::getAllCertificateNames not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800164}
165
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800166void
167SecPublicInfoMemory::getAllCertificateNamesOfKey(const Name& keyName, std::vector<Name> &nameList, bool isDefault)
Yingdi Yu87581582014-01-14 14:28:39 -0800168{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800169 throw Error("SecPublicInfoMemory::getAllCertificateNamesOfKey not implemented");
Yingdi Yu87581582014-01-14 14:28:39 -0800170}
171
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800172void
173SecPublicInfoMemory::deleteCertificateInfo(const Name &certName)
174{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800175 throw Error("SecPublicInfoMemory::deleteCertificateInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800176}
177
178void
179SecPublicInfoMemory::deletePublicKeyInfo(const Name &keyName)
180{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800181 throw Error("SecPublicInfoMemory::deletePublicKeyInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800182}
183
184void
185SecPublicInfoMemory::deleteIdentityInfo(const Name &identityName)
186{
Yingdi Yu2e57a582014-02-20 23:34:43 -0800187 throw Error("SecPublicInfoMemory::deleteIdentityInfo not implemented");
Yingdi Yu28fd32f2014-01-28 19:03:03 -0800188}
189
Yingdi Yufc40d872014-02-18 12:56:04 -0800190} // namespace ndn