identity.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "identity.hpp"
23 #include "detail/identity-impl.hpp"
24 
25 namespace ndn {
26 namespace security {
27 namespace pib {
28 
29 Identity::Identity() = default;
30 
31 Identity::Identity(weak_ptr<detail::IdentityImpl> impl)
32  : m_impl(impl)
33 {
34 }
35 
36 const Name&
38 {
39  return lock()->getName();
40 }
41 
42 Key
43 Identity::addKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
44 {
45  return lock()->addKey(key, keyLen, keyName);
46 }
47 
48 void
49 Identity::removeKey(const Name& keyName) const
50 {
51  return lock()->removeKey(keyName);
52 }
53 
54 Key
55 Identity::getKey(const Name& keyName) const
56 {
57  return lock()->getKey(keyName);
58 }
59 
60 const KeyContainer&
62 {
63  return lock()->getKeys();
64 }
65 
66 const Key&
67 Identity::setDefaultKey(const Name& keyName) const
68 {
69  return lock()->setDefaultKey(keyName);
70 }
71 
72 const Key&
73 Identity::setDefaultKey(const uint8_t* key, size_t keyLen, const Name& keyName) const
74 {
75  return lock()->setDefaultKey(key, keyLen, keyName);
76 }
77 
78 const Key&
80 {
81  return lock()->getDefaultKey();
82 }
83 
84 Identity::operator bool() const
85 {
86  return !(this->operator!());
87 }
88 
89 bool
91 {
92  return m_impl.expired();
93 }
94 
95 shared_ptr<detail::IdentityImpl>
96 Identity::lock() const
97 {
98  auto impl = m_impl.lock();
99 
100  if (impl == nullptr)
101  BOOST_THROW_EXCEPTION(std::domain_error("Invalid Identity instance"));
102 
103  return impl;
104 }
105 
106 } // namespace pib
107 } // namespace security
108 } // namespace ndn
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
const Key & getDefaultKey() const
Get the default key for this Identity.
Definition: identity.cpp:79
Identity()
Default Constructor.
Container of keys of an identity.
const KeyContainer & getKeys() const
Get all keys for this identity.
Definition: identity.cpp:61
A frontend handle of a key instance.
Definition: key.hpp:49
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Key getKey(const Name &keyName) const
Get a key with id keyName.
Definition: identity.cpp:55
const Name & getName() const
Get the name of the identity.
Definition: identity.cpp:37