signature-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_SIGNATURE_LITE_HPP
23 #define NDN_SIGNATURE_LITE_HPP
24 
25 #include "key-locator-lite.hpp"
26 #include "../c/data-types.h"
27 
28 namespace ndn {
29 
36 class SignatureLite : private ndn_Signature {
37 public:
47  SignatureLite(ndn_NameComponent* keyNameComponents, size_t maxKeyNameComponents);
48 
52  void
53  clear();
54 
55  ndn_SignatureType
56  getType() const { return type; }
57 
58  const BlobLite&
59  getDigestAlgorithm() const { return BlobLite::upCast(digestAlgorithm); }
60 
61  const BlobLite&
62  getWitness() const { return BlobLite::upCast(witness); }
63 
64  const BlobLite&
65  getSignature() const { return BlobLite::upCast(signature); }
66 
67  const KeyLocatorLite&
68  getKeyLocator() const { return KeyLocatorLite::upCast(keyLocator); }
69 
71  getKeyLocator() { return KeyLocatorLite::upCast(keyLocator); }
72 
73  void
74  setType(ndn_SignatureType type) { this->type = type; }
75 
81  void
83  {
84  BlobLite::upCast(this->digestAlgorithm) = digestAlgorithm;
85  }
86 
92  void
94  {
95  BlobLite::upCast(this->witness) = witness;
96  }
97 
103  void
104  setSignature(const BlobLite& signature)
105  {
106  BlobLite::upCast(this->signature) = signature;
107  }
108 
115  ndn_Error
116  set(const SignatureLite& other);
117 
123  static SignatureLite&
124  upCast(ndn_Signature& signature) { return *(SignatureLite*)&signature; }
125 
126  static const SignatureLite&
127  upCast(const ndn_Signature& signature) { return *(SignatureLite*)&signature; }
128 
129 private:
136  SignatureLite(const SignatureLite& other);
137 
143  SignatureLite& operator=(const SignatureLite& other);
144 };
145 
146 }
147 
148 #endif
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
static SignatureLite & upCast(ndn_Signature &signature)
Upcast the reference to the ndn_Signature struct to a SignatureLite.
Definition: signature-lite.hpp:124
static KeyLocatorLite & upCast(ndn_KeyLocator &keyLocator)
Upcast the reference to the ndn_KeyLocator struct to a KeyLocatorLite.
Definition: key-locator-lite.hpp:106
A SignatureLite holds a signature type, a KeyLocatorLite, the signature bytes and other fields to rep...
Definition: signature-lite.hpp:36
void setDigestAlgorithm(const BlobLite &digestAlgorithm)
Set the bytes of the digest algorithm.
Definition: signature-lite.hpp:82
ndn_Error set(const SignatureLite &other)
Set this signature to have the values from the other signature.
Definition: signature-lite.cpp:37
struct ndn_Blob witness
A Blob whose value is a pointer to pre-allocated buffer.
Definition: data-types.h:68
static BlobLite & upCast(ndn_Blob &blob)
Upcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:69
ndn_SignatureType type
-1 for none
Definition: data-types.h:65
A KeyLocatorLite holds a type and other info to represent the key which signs a Data packet...
Definition: key-locator-lite.hpp:34
Copyright (C) 2015 Regents of the University of California.
Definition: name-types.h:33
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
SignatureLite(ndn_NameComponent *keyNameComponents, size_t maxKeyNameComponents)
Create a SignatureLite with values for none and the default digestAlgorithm.
Definition: signature-lite.cpp:28
void setSignature(const BlobLite &signature)
Set the signature bytes.
Definition: signature-lite.hpp:104
void clear()
Set the fields the values for none as in the constructor.
Definition: signature-lite.cpp:34
void setWitness(const BlobLite &witness)
Set the witness.
Definition: signature-lite.hpp:93
An ndn_Signature struct holds the signature bits and other info representing the signature in a data ...
Definition: data-types.h:64
struct ndn_Blob digestAlgorithm
A Blob whose value is a pointer to a pre-allocated buffer.
Definition: data-types.h:66