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 | |
| 8 | #include <stdexcept> |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 9 | #include "../security-exception.hpp" |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 10 | #include "memory-identity-storage.hpp" |
| 11 | |
| 12 | using namespace std; |
| 13 | using namespace ndn::ptr_lib; |
| 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | MemoryIdentityStorage::~MemoryIdentityStorage() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | bool |
| 22 | MemoryIdentityStorage::doesIdentityExist(const Name& identityName) |
| 23 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 24 | string identityUri = identityName.toUri(); |
| 25 | return find(identityStore_.begin(), identityStore_.end(), identityUri) != identityStore_.end(); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void |
| 29 | MemoryIdentityStorage::addIdentity(const Name& identityName) |
| 30 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 31 | 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 Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | bool |
| 39 | MemoryIdentityStorage::revokeIdentity() |
| 40 | { |
| 41 | #if 1 |
| 42 | throw std::runtime_error("MemoryIdentityStorage::revokeIdentity not implemented"); |
| 43 | #endif |
| 44 | } |
| 45 | |
| 46 | Name |
| 47 | MemoryIdentityStorage::getNewKeyName(const Name& identityName, bool useKsk) |
| 48 | { |
| 49 | #if 1 |
| 50 | throw std::runtime_error("MemoryIdentityStorage::getNewKeyName not implemented"); |
| 51 | #endif |
| 52 | } |
| 53 | |
| 54 | bool |
| 55 | MemoryIdentityStorage::doesKeyExist(const Name& keyName) |
| 56 | { |
| 57 | #if 1 |
| 58 | throw std::runtime_error("MemoryIdentityStorage::doesKeyExist not implemented"); |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | Name |
| 63 | MemoryIdentityStorage::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 | |
| 75 | void |
Jeff Thompson | bd04b07 | 2013-09-27 15:14:09 -0700 | [diff] [blame] | 76 | MemoryIdentityStorage::addKey(const Name& keyName, KeyType keyType, const Blob& publicKeyDer) |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 77 | { |
| 78 | #if 1 |
| 79 | throw std::runtime_error("MemoryIdentityStorage::addKey not implemented"); |
| 80 | #endif |
| 81 | } |
| 82 | |
| 83 | Blob |
| 84 | MemoryIdentityStorage::getKey(const Name& keyName) |
| 85 | { |
| 86 | #if 1 |
| 87 | throw std::runtime_error("MemoryIdentityStorage::getKey not implemented"); |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | MemoryIdentityStorage::activateKey(const Name& keyName) |
| 93 | { |
| 94 | #if 1 |
| 95 | throw std::runtime_error("MemoryIdentityStorage::activateKey not implemented"); |
| 96 | #endif |
| 97 | } |
| 98 | |
| 99 | void |
| 100 | MemoryIdentityStorage::deactivateKey(const Name& keyName) |
| 101 | { |
| 102 | #if 1 |
| 103 | throw std::runtime_error("MemoryIdentityStorage::deactivateKey not implemented"); |
| 104 | #endif |
| 105 | } |
| 106 | |
| 107 | bool |
| 108 | MemoryIdentityStorage::doesCertificateExist(const Name& certificateName) |
| 109 | { |
| 110 | #if 1 |
| 111 | throw std::runtime_error("MemoryIdentityStorage::doesCertificateExist not implemented"); |
| 112 | #endif |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | MemoryIdentityStorage::addCertificate(const Certificate& certificate) |
| 117 | { |
| 118 | #if 1 |
| 119 | throw std::runtime_error("MemoryIdentityStorage::addCertificate not implemented"); |
| 120 | #endif |
| 121 | } |
| 122 | |
Jeff Thompson | a6fd638 | 2013-09-24 15:23:37 -0700 | [diff] [blame] | 123 | ptr_lib::shared_ptr<Certificate> |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 124 | MemoryIdentityStorage::getCertificate(const Name &certificateName, bool allowAny) |
| 125 | { |
| 126 | #if 1 |
| 127 | throw std::runtime_error("MemoryIdentityStorage::getCertificate not implemented"); |
| 128 | #endif |
| 129 | } |
| 130 | |
| 131 | Name |
| 132 | MemoryIdentityStorage::getDefaultIdentity() |
| 133 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 134 | return Name(defaultIdentity_); |
Jeff Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | Name |
| 138 | MemoryIdentityStorage::getDefaultKeyNameForIdentity(const Name& identityName) |
| 139 | { |
| 140 | #if 1 |
| 141 | throw std::runtime_error("MemoryIdentityStorage::getDefaultKeyNameForIdentity not implemented"); |
| 142 | #endif |
| 143 | } |
| 144 | |
| 145 | Name |
| 146 | MemoryIdentityStorage::getDefaultCertificateNameForKey(const Name& keyName) |
| 147 | { |
| 148 | #if 1 |
| 149 | throw std::runtime_error("MemoryIdentityStorage::getDefaultCertificateNameForKey not implemented"); |
| 150 | #endif |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | MemoryIdentityStorage::setDefaultIdentity(const Name& identityName) |
| 155 | { |
Jeff Thompson | 8184227 | 2013-09-25 16:12:33 -0700 | [diff] [blame] | 156 | 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 Thompson | 6c314bc | 2013-09-23 18:09:38 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | void |
| 165 | MemoryIdentityStorage::setDefaultKeyNameForIdentity(const Name& keyName, const Name& identityName) |
| 166 | { |
| 167 | #if 1 |
| 168 | throw std::runtime_error("MemoryIdentityStorage::setDefaultKeyNameForIdentity not implemented"); |
| 169 | #endif |
| 170 | } |
| 171 | |
| 172 | void |
| 173 | MemoryIdentityStorage::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 | } |