rsa-private-key-lite.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_RSA_PRIVATE_KEY_LITE_HPP
23 #define NDN_RSA_PRIVATE_KEY_LITE_HPP
24 
25 #include "../util/blob-lite.hpp"
26 #include "../../c/errors.h"
27 #include "../../c/encrypt/algo/encrypt-params-types.h"
28 #include "../../c/security/rsa-private-key-types.h"
29 
30 namespace ndn {
31 
37 public:
42 
47 
56  ndn_Error
57  decode(const uint8_t* privateKeyDer, size_t privateKeyDerLength);
58 
66  ndn_Error
67  decode(const BlobLite& privateKeyDer)
68  {
69  return decode(privateKeyDer.buf(), privateKeyDer.size());
70  }
71 
79  ndn_Error
80  generate(uint32_t keySize);
81 
93  ndn_Error
94  encodePrivateKey(uint8_t* encoding, size_t& encodingLength) const;
95 
107  ndn_Error
108  encodePublicKey(uint8_t* encoding, size_t& encodingLength) const;
109 
121  ndn_Error
123  (const uint8_t* data, size_t dataLength, uint8_t* signature,
124  size_t& signatureLength) const;
125 
136  ndn_Error
138  (const BlobLite& data, uint8_t* signature, size_t& signatureLength) const
139  {
140  return signWithSha256(data.buf(), data.size(), signature, signatureLength);
141  }
142 
156  ndn_Error
157  decrypt
158  (const uint8_t* encryptedData, size_t encryptedDataLength,
159  ndn_EncryptAlgorithmType algorithmType, uint8_t* plainData,
160  size_t& plainDataLength);
161 
174  ndn_Error
175  decrypt
176  (const BlobLite& encryptedData, ndn_EncryptAlgorithmType algorithmType,
177  uint8_t* plainData, size_t& plainDataLength)
178  {
179  return decrypt
180  (encryptedData.buf(), encryptedData.size(), algorithmType, plainData,
181  plainDataLength);
182  }
183 
189  static RsaPrivateKeyLite&
190  downCast(ndn_RsaPrivateKey& blob) { return *(RsaPrivateKeyLite*)&blob; }
191 
192  static const RsaPrivateKeyLite&
193  downCast(const ndn_RsaPrivateKey& blob) { return *(RsaPrivateKeyLite*)&blob; }
194 
195 private:
196  // Don't allow copying since we don't reference count the allocated value.
197  RsaPrivateKeyLite(const RsaPrivateKeyLite& other);
198  RsaPrivateKeyLite& operator=(const RsaPrivateKeyLite& other);
199 };
200 
201 }
202 
203 #endif
size_t size() const
Return size given to the constructor.
Definition: blob-lite.hpp:61
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:36
ndn_Error decode(const BlobLite &privateKeyDer)
Decode the DER-encoded PKCS #1 privateKeyDer and set this RsaPrivateKeyLite, allocating memory as nee...
Definition: rsa-private-key-lite.hpp:67
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 RsaWithSha256.
Definition: rsa-private-key-lite.cpp:64
ndn_Error decrypt(const uint8_t *encryptedData, size_t encryptedDataLength, ndn_EncryptAlgorithmType algorithmType, uint8_t *plainData, size_t &plainDataLength)
Use the private key to decrypt encryptedData according to the algorithmType.
Definition: rsa-private-key-lite.cpp:73
A struct ndn_RsaPrivateKey holds a decoded RSA private key for use in crypto operations.
Definition: rsa-private-key-types.h:34
ndn_Error encodePrivateKey(uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded PKCS #1 private key.
Definition: rsa-private-key-lite.cpp:51
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 encodePublicKey(uint8_t *encoding, size_t &encodingLength) const
Encode the DER-encoded SubjectPublicKeyInfo.
Definition: rsa-private-key-lite.cpp:57
ndn_Error decode(const uint8_t *privateKeyDer, size_t privateKeyDerLength)
Decode the DER-encoded PKCS #1 privateKeyDer and set this RsaPrivateKeyLite, allocating memory as nee...
Definition: rsa-private-key-lite.cpp:39
ndn_Error generate(uint32_t keySize)
Generate a key pair and set this RsaPrivateKeyLite, allocating memory as needed.
Definition: rsa-private-key-lite.cpp:45
RsaPrivateKeyLite()
Create an RsaPrivateKeyLite with a null value.
Definition: rsa-private-key-lite.cpp:27
static RsaPrivateKeyLite & downCast(ndn_RsaPrivateKey &blob)
Downcast the reference to the ndn_RsaPrivateKey struct to a RsaPrivateKeyLite.
Definition: rsa-private-key-lite.hpp:190
An RsaPrivateKeyLite holds a decoded or generated RSA private key for use in crypto operations...
Definition: rsa-private-key-lite.hpp:36
~RsaPrivateKeyLite()
Finalize the RsaPrivateKeyLite, freeing memory if needed.
Definition: rsa-private-key-lite.cpp:32