blob: 79cb090089f7886ffbdb454d6f65d84cd439b3e8 [file] [log] [blame]
Yingdi Yub8f8b342015-04-27 11:06:42 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yingdi Yu6ee2d362015-07-16 21:48:05 -07003 * Copyright (c) 2013-2017 Regents of the University of California.
Yingdi Yub8f8b342015-04-27 11:06:42 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
22#include "identity.hpp"
Yingdi Yucbe72b02015-11-25 17:35:37 -080023#include "detail/identity-impl.hpp"
Yingdi Yub8f8b342015-04-27 11:06:42 -070024
25namespace ndn {
26namespace security {
Yingdi Yu6ee2d362015-07-16 21:48:05 -070027namespace pib {
Yingdi Yub8f8b342015-04-27 11:06:42 -070028
Yingdi Yucbe72b02015-11-25 17:35:37 -080029Identity::Identity() = default;
Yingdi Yub8f8b342015-04-27 11:06:42 -070030
Yingdi Yucbe72b02015-11-25 17:35:37 -080031Identity::Identity(weak_ptr<detail::IdentityImpl> impl)
32 : m_impl(impl)
Yingdi Yub8f8b342015-04-27 11:06:42 -070033{
Yingdi Yub8f8b342015-04-27 11:06:42 -070034}
35
36const Name&
37Identity::getName() const
38{
Yingdi Yucbe72b02015-11-25 17:35:37 -080039 return lock()->getName();
Yingdi Yub8f8b342015-04-27 11:06:42 -070040}
41
42Key
Yingdi Yufe4733a2015-10-22 14:24:12 -070043Identity::addKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
Yingdi Yub8f8b342015-04-27 11:06:42 -070044{
Yingdi Yucbe72b02015-11-25 17:35:37 -080045 return lock()->addKey(key, keyLen, keyName);
Yingdi Yub8f8b342015-04-27 11:06:42 -070046}
47
48void
Yingdi Yufe4733a2015-10-22 14:24:12 -070049Identity::removeKey(const Name& keyName) const
Yingdi Yub8f8b342015-04-27 11:06:42 -070050{
Yingdi Yucbe72b02015-11-25 17:35:37 -080051 return lock()->removeKey(keyName);
Yingdi Yub8f8b342015-04-27 11:06:42 -070052}
53
54Key
Yingdi Yu6ee2d362015-07-16 21:48:05 -070055Identity::getKey(const Name& keyName) const
Yingdi Yub8f8b342015-04-27 11:06:42 -070056{
Yingdi Yucbe72b02015-11-25 17:35:37 -080057 return lock()->getKey(keyName);
Yingdi Yub8f8b342015-04-27 11:06:42 -070058}
59
60const KeyContainer&
Yingdi Yuc8209892015-06-19 17:47:56 -070061Identity::getKeys() const
Yingdi Yub8f8b342015-04-27 11:06:42 -070062{
Yingdi Yucbe72b02015-11-25 17:35:37 -080063 return lock()->getKeys();
Yingdi Yub8f8b342015-04-27 11:06:42 -070064}
65
Yingdi Yucbe72b02015-11-25 17:35:37 -080066const Key&
Yingdi Yufe4733a2015-10-22 14:24:12 -070067Identity::setDefaultKey(const Name& keyName) const
Yingdi Yub8f8b342015-04-27 11:06:42 -070068{
Yingdi Yucbe72b02015-11-25 17:35:37 -080069 return lock()->setDefaultKey(keyName);
Yingdi Yub8f8b342015-04-27 11:06:42 -070070}
71
Yingdi Yucbe72b02015-11-25 17:35:37 -080072const Key&
Yingdi Yufe4733a2015-10-22 14:24:12 -070073Identity::setDefaultKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
Yingdi Yub8f8b342015-04-27 11:06:42 -070074{
Yingdi Yucbe72b02015-11-25 17:35:37 -080075 return lock()->setDefaultKey(key, keyLen, keyName);
Yingdi Yub8f8b342015-04-27 11:06:42 -070076}
77
Yingdi Yucbe72b02015-11-25 17:35:37 -080078const Key&
Yingdi Yuc8209892015-06-19 17:47:56 -070079Identity::getDefaultKey() const
Yingdi Yub8f8b342015-04-27 11:06:42 -070080{
Yingdi Yucbe72b02015-11-25 17:35:37 -080081 return lock()->getDefaultKey();
Yingdi Yub8f8b342015-04-27 11:06:42 -070082}
83
84Identity::operator bool() const
85{
86 return !(this->operator!());
87}
88
89bool
90Identity::operator!() const
91{
Yingdi Yucbe72b02015-11-25 17:35:37 -080092 return m_impl.expired();
Yingdi Yub8f8b342015-04-27 11:06:42 -070093}
94
Yingdi Yucbe72b02015-11-25 17:35:37 -080095shared_ptr<detail::IdentityImpl>
96Identity::lock() const
Yingdi Yub8f8b342015-04-27 11:06:42 -070097{
Yingdi Yucbe72b02015-11-25 17:35:37 -080098 auto impl = m_impl.lock();
99
100 if (impl == nullptr)
101 BOOST_THROW_EXCEPTION(std::domain_error("Invalid Identity instance"));
102
103 return impl;
Yingdi Yub8f8b342015-04-27 11:06:42 -0700104}
105
Yingdi Yu6ee2d362015-07-16 21:48:05 -0700106} // namespace pib
Yingdi Yub8f8b342015-04-27 11:06:42 -0700107} // namespace security
108} // namespace ndn