key-locator.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_KEY_LOCATOR_HPP
23 #define NDN_KEY_LOCATOR_HPP
24 
25 #include <vector>
26 #include "c/key-types.h"
27 #include "name.hpp"
28 #include "util/change-counter.hpp"
29 #include "lite/key-locator-lite.hpp"
30 
31 namespace ndn {
32 
33 class Signature;
34 
35 class KeyLocator {
36 public:
37  KeyLocator()
38  : type_((ndn_KeyLocatorType)-1), changeCount_(0)
39  {
40  }
41 
45  void
47  {
48  type_ = (ndn_KeyLocatorType)-1;
49  keyData_.reset();
50  setKeyName(Name());
51  ++changeCount_;
52  }
53 
62  void
63  get(KeyLocatorLite& keyLocatorLite) const;
64 
69  void
70  set(const KeyLocatorLite& keyLocatorLite);
71 
72  ndn_KeyLocatorType
73  getType() const { return type_; }
74 
75  const Blob&
76  getKeyData() const { return keyData_; }
77 
78  const Name&
79  getKeyName() const { return keyName_.get(); }
80 
81  Name&
82  getKeyName() { return keyName_.get(); }
83 
84  void
85  setType(ndn_KeyLocatorType type)
86  {
87  type_ = type;
88  ++changeCount_;
89  }
90 
91  void
92  setKeyData(const Blob& keyData)
93  {
94  keyData_ = keyData;
95  ++changeCount_;
96  }
97 
98  void
99  setKeyName(const Name &keyName)
100  {
101  keyName_.set(keyName);
102  ++changeCount_;
103  }
104 
116  static bool
117  canGetFromSignature(const Signature* signature);
118 
126  static const KeyLocator&
127  getFromSignature(const Signature* signature);
128 
133  uint64_t
135  {
136  if (keyName_.checkChanged())
137  // A child object has changed, so update the change count.
138  // This method can be called on a const object, but we want to be able to update the changeCount_.
139  ++const_cast<KeyLocator*>(this)->changeCount_;
140 
141  return changeCount_;
142  }
143 
144 private:
145  ndn_KeyLocatorType type_;
146  Blob keyData_;
149  ChangeCounter<Name> keyName_;
150  uint64_t changeCount_;
151 };
152 
153 }
154 
155 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
static bool canGetFromSignature(const Signature *signature)
If the signature is a type that has a KeyLocator (so that getFromSignature will succeed), return true.
Definition: key-locator.cpp:53
static const KeyLocator & getFromSignature(const Signature *signature)
If the signature is a type that has a KeyLocator, then return it.
Definition: key-locator.cpp:61
A ChangeCounter keeps a target object whose change count is tracked by a local change count...
Definition: change-counter.hpp:37
A KeyLocatorLite holds a type and other info to represent the key which signs a Data packet...
Definition: key-locator-lite.hpp:34
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
void clear()
Clear the keyData and set the type to none.
Definition: key-locator.hpp:46
Definition: key-locator.hpp:35
uint64_t getChangeCount() const
Get the change count, which is incremented each time this object (or a child object) is changed...
Definition: key-locator.hpp:134
void set(const KeyLocatorLite &keyLocatorLite)
Clear this key locator, and set the values by copying from keyLocatorLite.
Definition: key-locator.cpp:42