Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
Jeff Thompson | 1130afc | 2013-10-01 14:45:50 -0700 | [diff] [blame] | 8 | #if 1 |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 9 | #include <stdexcept> |
Jeff Thompson | 1130afc | 2013-10-01 14:45:50 -0700 | [diff] [blame] | 10 | #endif |
| 11 | #include <algorithm> |
Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 12 | #include <ndn-cpp/security/security-exception.hpp> |
| 13 | #include <ndn-cpp/security/identity/memory-identity-storage.hpp> |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 14 | |
| 15 | using namespace std; |
| 16 | using namespace ndn::ptr_lib; |
| 17 | |
| 18 | namespace ndn { |
| 19 | |
| 20 | MemoryIdentityStorage::~MemoryIdentityStorage() |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | bool |
| 25 | MemoryIdentityStorage::doesIdentityExist(const Name& identityName) |
| 26 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 27 | string identityUri = identityName.toUri(); |
| 28 | return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end(); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | void |
| 32 | MemoryIdentityStorage::addIdentity(const Name& identityName) |
| 33 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 34 | string identityUri = identityName.toUri(); |
| 35 | if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) |
| 36 | throw SecurityException("Identity already exists: " + identityUri); |
| 37 | |
| 38 | identityStore_.push_back(identityUri); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | bool |
| 42 | MemoryIdentityStorage::revokeIdentity() |
| 43 | { |
| 44 | #if 1 |
| 45 | throw std::runtime_error("MemoryIdentityStorage::revokeIdentity not implemented"); |
| 46 | #endif |
| 47 | } |
| 48 | |
| 49 | Name |
| 50 | MemoryIdentityStorage::getNewKeyName(const Name& identityName, bool useKsk) |
| 51 | { |
| 52 | #if 1 |
| 53 | throw std::runtime_error("MemoryIdentityStorage::getNewKeyName not implemented"); |
| 54 | #endif |
| 55 | } |
| 56 | |
| 57 | bool |
| 58 | MemoryIdentityStorage::doesKeyExist(const Name& keyName) |
| 59 | { |
| 60 | #if 1 |
| 61 | throw std::runtime_error("MemoryIdentityStorage::doesKeyExist not implemented"); |
| 62 | #endif |
| 63 | } |
| 64 | |
| 65 | Name |
| 66 | MemoryIdentityStorage::getKeyNameForCertificate(const Name& certificateName) |
| 67 | { |
| 68 | int i = certificateName.getComponentCount() - 1; |
| 69 | |
| 70 | for (; i >= 0; --i) { |
| 71 | if(certificateName.getComponent(i).toEscapedString() == string("ID-CERT")) |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | return certificateName.getSubName(0, i); |
| 76 | } |
| 77 | |
| 78 | void |
Jeff Thompson | bd04b07 | 2013-09-27 15:14:09 -0700 | [diff] [blame] | 79 | MemoryIdentityStorage::addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 80 | { |
| 81 | #if 1 |
| 82 | throw std::runtime_error("MemoryIdentityStorage::addKey not implemented"); |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | Blob |
| 87 | MemoryIdentityStorage::getKey(const Name& keyName) |
| 88 | { |
| 89 | #if 1 |
| 90 | throw std::runtime_error("MemoryIdentityStorage::getKey not implemented"); |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | MemoryIdentityStorage::activateKey(const Name& keyName) |
| 96 | { |
| 97 | #if 1 |
| 98 | throw std::runtime_error("MemoryIdentityStorage::activateKey not implemented"); |
| 99 | #endif |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | MemoryIdentityStorage::deactivateKey(const Name& keyName) |
| 104 | { |
| 105 | #if 1 |
| 106 | throw std::runtime_error("MemoryIdentityStorage::deactivateKey not implemented"); |
| 107 | #endif |
| 108 | } |
| 109 | |
| 110 | bool |
| 111 | MemoryIdentityStorage::doesCertificateExist(const Name& certificateName) |
| 112 | { |
| 113 | #if 1 |
| 114 | throw std::runtime_error("MemoryIdentityStorage::doesCertificateExist not implemented"); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | void |
Jeff Thompson | c69163b | 2013-10-12 13:49:50 -0700 | [diff] [blame] | 119 | MemoryIdentityStorage::addCertificate(const IdentityCertificate& certificate) |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 120 | { |
| 121 | #if 1 |
| 122 | throw std::runtime_error("MemoryIdentityStorage::addCertificate not implemented"); |
| 123 | #endif |
| 124 | } |
| 125 | |
Jeff Thompson | a6fd638 | 2013-09-24 15:23:37 -0700 | [diff] [blame] | 126 | ptr_lib::shared_ptr<Certificate> |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 127 | MemoryIdentityStorage::getCertificate(const Name &certificateName, bool allowAny) |
| 128 | { |
| 129 | #if 1 |
| 130 | throw std::runtime_error("MemoryIdentityStorage::getCertificate not implemented"); |
| 131 | #endif |
| 132 | } |
| 133 | |
| 134 | Name |
| 135 | MemoryIdentityStorage::getDefaultIdentity() |
| 136 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 137 | return Name(defaultIdentity_); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | Name |
| 141 | MemoryIdentityStorage::getDefaultKeyNameForIdentity(const Name& identityName) |
| 142 | { |
| 143 | #if 1 |
| 144 | throw std::runtime_error("MemoryIdentityStorage::getDefaultKeyNameForIdentity not implemented"); |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | Name |
| 149 | MemoryIdentityStorage::getDefaultCertificateNameForKey(const Name& keyName) |
| 150 | { |
| 151 | #if 1 |
| 152 | throw std::runtime_error("MemoryIdentityStorage::getDefaultCertificateNameForKey not implemented"); |
| 153 | #endif |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | MemoryIdentityStorage::setDefaultIdentity(const Name& identityName) |
| 158 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 159 | string identityUri = identityName.toUri(); |
| 160 | if (find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end()) |
| 161 | defaultIdentity_ = identityUri; |
| 162 | else |
| 163 | // The identity doesn't exist, so clear the default. |
| 164 | defaultIdentity_.clear(); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void |
Jeff Thompson | abcea7d | 2013-10-02 15:03:21 -0700 | [diff] [blame] | 168 | MemoryIdentityStorage::setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityNameCheck) |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 169 | { |
| 170 | #if 1 |
| 171 | throw std::runtime_error("MemoryIdentityStorage::setDefaultKeyNameForIdentity not implemented"); |
| 172 | #endif |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | MemoryIdentityStorage::setDefaultCertificateNameForKey(const Name& keyName, const Name& certificateName) |
| 177 | { |
| 178 | #if 1 |
| 179 | throw std::runtime_error("MemoryIdentityStorage::setDefaultCertificateNameForKey not implemented"); |
| 180 | #endif |
| 181 | } |
| 182 | |
| 183 | } |