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  getSignature() const { return BlobLite::downCast(signature); }
60 
66  const BlobLite&
68 
77  int
78  getGenericTypeCode() const { return genericTypeCode; }
79 
80  const KeyLocatorLite&
81  getKeyLocator() const { return KeyLocatorLite::downCast(keyLocator); }
82 
83  KeyLocatorLite&
84  getKeyLocator() { return KeyLocatorLite::downCast(keyLocator); }
85 
86  void
87  setType(ndn_SignatureType type) { this->type = type; }
88 
94  void
95  setSignature(const BlobLite& signature)
96  {
97  BlobLite::downCast(this->signature) = signature;
98  }
99 
109  void
112  {
113  BlobLite::downCast(this->signatureInfoEncoding) = signatureInfoEncoding;
114  this->genericTypeCode = genericTypeCode;
115  }
116 
123  ndn_Error
124  set(const SignatureLite& other);
125 
131  static SignatureLite&
132  downCast(ndn_Signature& signature) { return *(SignatureLite*)&signature; }
133 
134  static const SignatureLite&
135  downCast(const ndn_Signature& signature) { return *(SignatureLite*)&signature; }
136 
137 private:
138  // Declare friends who can downcast to the private base.
139  friend class Tlv0_1_1WireFormatLite;
140 
146  SignatureLite(const SignatureLite& other);
147 
153  SignatureLite& operator=(const SignatureLite& other);
154 };
155 
156 }
157 
158 #endif
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
int genericTypeCode
used with Generic.
Definition: data-types.h:63
const BlobLite & getSignatureInfoEncoding() const
Get the bytes of the entire signature info encoding (including the type code).
Definition: signature-lite.hpp:67
static KeyLocatorLite & downCast(ndn_KeyLocator &keyLocator)
Downcast the reference to the ndn_KeyLocator struct to a KeyLocatorLite.
Definition: key-locator-lite.hpp:100
A SignatureLite holds a signature type, a KeyLocatorLite, the signature bytes and other fields to rep...
Definition: signature-lite.hpp:36
static BlobLite & downCast(ndn_Blob &blob)
Downcast the reference to the ndn_Blob struct to a BlobLite.
Definition: blob-lite.hpp:76
ndn_Error set(const SignatureLite &other)
Set this signature to have the values from the other signature.
Definition: signature-lite.cpp:37
ndn_SignatureType type
-1 for unspecified
Definition: data-types.h:60
A KeyLocatorLite holds a type and other info to represent the key which signs a Data packet...
Definition: key-locator-lite.hpp:34
struct ndn_KeyLocator keyLocator
used with Sha256WithRsaSignature, Sha256WithEcdsaSignature, HmacWithSha256Signature ...
Definition: data-types.h:64
Copyright (C) 2015-2016 Regents of the University of California.
Definition: name-types.h:33
void setSignatureInfoEncoding(const BlobLite &signatureInfoEncoding, int genericTypeCode)
Set the bytes of the entire signature info encoding (including the type code).
Definition: signature-lite.hpp:111
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.
Definition: signature-lite.cpp:28
void setSignature(const BlobLite &signature)
Set the signature bytes.
Definition: signature-lite.hpp:95
void clear()
Set the fields the values for none as in the constructor.
Definition: signature-lite.cpp:34
static SignatureLite & downCast(ndn_Signature &signature)
Downcast the reference to the ndn_Signature struct to a SignatureLite.
Definition: signature-lite.hpp:132
An ndn_Signature struct holds the signature bits and other info representing the signature in a data ...
Definition: data-types.h:59
struct ndn_Blob signatureInfoEncoding
used with Generic
Definition: data-types.h:62
int getGenericTypeCode() const
Get the type code of the generic signature.
Definition: signature-lite.hpp:78