All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
ec-private-key-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_EC_PRIVATE_KEY_LITE_HPP
23 #define NDN_EC_PRIVATE_KEY_LITE_HPP
24 
25 #include "../util/blob-lite.hpp"
26 #include "../../c/errors.h"
27 #include "../../c/security/ec-private-key-types.h"
28 
29 namespace ndn {
30 
36 public:
41 
46 
55  ndn_Error
56  decode(const uint8_t* privateKeyDer, size_t privateKeyDerLength);
57 
65  ndn_Error
66  decode(const BlobLite& privateKeyDer)
67  {
68  return decode(privateKeyDer.buf(), privateKeyDer.size());
69  }
70 
80  ndn_Error
81  setByCurve(int curveId, const uint8_t* value, size_t valueLength);
82 
91  ndn_Error
92  setByCurve(int curveId, const BlobLite& value)
93  {
94  return setByCurve(curveId, value.buf(), value.size());
95  }
96 
105  ndn_Error
106  generate(uint32_t keySize);
107 
121  ndn_Error
123  (bool includeParameters, uint8_t* encoding, size_t& encodingLength) const;
124 
138  ndn_Error
140  (bool includeParameters, uint8_t* encoding, size_t& encodingLength) const;
141 
153  ndn_Error
155  (const uint8_t* data, size_t dataLength, uint8_t* signature,
156  size_t& signatureLength) const;
157 
168  ndn_Error
170  (const BlobLite& data, uint8_t* signature, size_t& signatureLength) const
171  {
172  return signWithSha256(data.buf(), data.size(), signature, signatureLength);
173  }
174 
181  ndn_Error
182  getCurveId(int& curveId) const;
183 
189  static EcPrivateKeyLite&
190  downCast(ndn_EcPrivateKey& blob) { return *(EcPrivateKeyLite*)&blob; }
191 
192  static const EcPrivateKeyLite&
193  downCast(const ndn_EcPrivateKey& blob) { return *(EcPrivateKeyLite*)&blob; }
194 
195 private:
196  // Don't allow copying since we don't reference count the allocated value.
197  EcPrivateKeyLite(const EcPrivateKeyLite& other);
198  EcPrivateKeyLite& operator=(const EcPrivateKeyLite& other);
199 };
200 
201 }
202 
203 #endif
A struct ndn_EcPrivateKey holds a decoded EC private key for use in crypto operations.
Definition: ec-private-key-types.h:34
size_t size() const
Return size given to the constructor.
Definition: blob-lite.hpp:61
static EcPrivateKeyLite & downCast(ndn_EcPrivateKey &blob)
Downcast the reference to the ndn_EcPrivateKey struct to a EcPrivateKeyLite.
Definition: ec-private-key-lite.hpp:190
EcPrivateKeyLite()
Create an EcPrivateKeyLite with a null value.
ndn_Error encodePrivateKey(bool includeParameters, uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded private key.
ndn_Error decode(const BlobLite &privateKeyDer)
Decode the privateKeyDer and set this EcPrivateKeyLite, allocating memory as needed.
Definition: ec-private-key-lite.hpp:66
ndn_Error setByCurve(int curveId, const BlobLite &value)
Set the the private key from the given curveId, using the value to create a BIGNUM, allocating memory as needed.
Definition: ec-private-key-lite.hpp:92
~EcPrivateKeyLite()
Finalize the EcPrivateKeyLite, freeing memory if needed.
ndn_Error signWithSha256(const uint8_t *data, size_t dataLength, uint8_t *signature, size_t &signatureLength) const
Use this private key to sign the data using EcdsaWithSha256.
An EcPrivateKeyLite holds a decoded or generated EC private key for use in crypto operations...
Definition: ec-private-key-lite.hpp:35
ndn_Error generate(uint32_t keySize)
Generate a key pair and set this EcPrivateKeyLite, allocating memory as needed.
A BlobLite holds a pointer to an immutable pre-allocated buffer and its length This is like a JavaScr...
Definition: blob-lite.hpp:37
const uint8_t * buf() const
Return buf given to the constructor.
Definition: blob-lite.hpp:55
ndn_Error getCurveId(int &curveId) const
Get the OpenSSL curve ID.
ndn_Error decode(const uint8_t *privateKeyDer, size_t privateKeyDerLength)
Decode the privateKeyDer and set this EcPrivateKeyLite, allocating memory as needed.
ndn_Error encodePublicKey(bool includeParameters, uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded EC SubjectPublicKeyInfo.
ndn_Error setByCurve(int curveId, const uint8_t *value, size_t valueLength)
Set the the private key from the given curveId, using the value to create a BIGNUM, allocating memory as needed.