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 
30 struct ndn_KeyLocator;
31 
32 namespace ndn {
33 
34 class Signature;
35 
36 class KeyLocator {
37 public:
38  KeyLocator()
39  : type_((ndn_KeyLocatorType)-1), keyNameType_((ndn_KeyNameType)-1), changeCount_(0)
40  {
41  }
42 
46  void
48  {
49  type_ = (ndn_KeyLocatorType)-1;
50  keyNameType_ = (ndn_KeyNameType)-1;
51  keyData_.reset();
52  setKeyName(Name());
53  ++changeCount_;
54  }
55 
61  void
62  get(struct ndn_KeyLocator& keyLocatorStruct) const;
63 
68  void
69  set(const struct ndn_KeyLocator& keyLocatorStruct);
70 
71  ndn_KeyLocatorType
72  getType() const { return type_; }
73 
74  const Blob&
75  getKeyData() const { return keyData_; }
76 
77  const Name&
78  getKeyName() const { return keyName_.get(); }
79 
80  Name&
81  getKeyName() { return keyName_.get(); }
82 
87  ndn_KeyNameType
88  DEPRECATED_IN_NDN_CPP getKeyNameType() const { return keyNameType_; }
89 
90  void
91  setType(ndn_KeyLocatorType type)
92  {
93  type_ = type;
94  ++changeCount_;
95  }
96 
97  void
98  setKeyData(const Blob& keyData)
99  {
100  keyData_ = keyData;
101  ++changeCount_;
102  }
103 
104  void
105  setKeyName(const Name &keyName)
106  {
107  keyName_.set(keyName);
108  ++changeCount_;
109  }
110 
116  void
117  DEPRECATED_IN_NDN_CPP setKeyNameType(ndn_KeyNameType keyNameType)
118  {
119  keyNameType_ = keyNameType;
120  ++changeCount_;
121  }
122 
134  static bool
135  canGetFromSignature(const Signature* signature);
136 
144  static const KeyLocator&
145  getFromSignature(const Signature* signature);
146 
151  uint64_t
153  {
154  if (keyName_.checkChanged())
155  // A child object has changed, so update the change count.
156  // This method can be called on a const object, but we want to be able to update the changeCount_.
157  ++const_cast<KeyLocator*>(this)->changeCount_;
158 
159  return changeCount_;
160  }
161 
162 private:
163  ndn_KeyLocatorType type_;
164  Blob keyData_;
173  ChangeCounter<Name> keyName_;
175  ndn_KeyNameType keyNameType_;
176  uint64_t changeCount_;
177 };
178 
179 }
180 
181 #endif
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
struct ndn_Blob keyData
A Blob whose value is a pointer to a pre-allocated buffer for the key data as follows: If type is ndn...
Definition: key-types.h:53
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:58
static const KeyLocator & getFromSignature(const Signature *signature)
If the signature is a type that has a KeyLocator, then return it.
Definition: key-locator.cpp:65
ndn_KeyLocatorType type
-1 for none
Definition: key-types.h:52
A ChangeCounter keeps a target object whose change count is tracked by a local change count...
Definition: change-counter.hpp:37
ndn_KeyNameType keyNameType
The type of data for keyName, -1 for none.
Definition: key-types.h:64
An ndn_KeyLocator holds the type of key locator and related data.
Definition: key-types.h:51
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
A Signature is an abstract base class providing methods to work with the signature information in a D...
Definition: signature.hpp:36
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:47
struct ndn_Name keyName
The key name (only used if type is ndn_KeyLocatorType_KEYNAME.)
Definition: key-types.h:62
void set(const struct ndn_KeyLocator &keyLocatorStruct)
Clear this key locator, and set the values by copying from the ndn_KeyLocator struct.
Definition: key-locator.cpp:43
Definition: key-locator.hpp:36
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:152
void DEPRECATED_IN_NDN_CPP setKeyNameType(ndn_KeyNameType keyNameType)
Definition: key-locator.hpp:117
ndn_KeyNameType DEPRECATED_IN_NDN_CPP getKeyNameType() const
Definition: key-locator.hpp:88