private-key-storage.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_PRIVATE_KEY_STORAGE_HPP
24 #define NDN_PRIVATE_KEY_STORAGE_HPP
25 
26 #include <string>
27 #include "../../util/blob.hpp"
28 #include "../certificate/public-key.hpp"
29 #include "../security-common.hpp"
30 #include "../key-params.hpp"
31 #include "../../name.hpp"
32 
33 namespace ndn {
34 
36 public:
40  virtual
42 
48  virtual void
49  generateKeyPair(const Name& keyName, const KeyParams& params) = 0;
50 
55  virtual void
56  deleteKeyPair(const Name& keyName) = 0;
57 
63  virtual ptr_lib::shared_ptr<PublicKey>
64  getPublicKey(const Name& keyName) = 0;
65 
74  virtual Blob
75  sign(const uint8_t *data, size_t dataLength, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) = 0;
76 
77  Blob
78  sign(const Blob& data, const Name& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256)
79  {
80  return sign(data.buf(), data.size(), keyName, digestAlgorithm);
81  }
82 
91  virtual Blob
92  decrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
93 
94  Blob
95  decrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
96  {
97  return decrypt(keyName, data.buf(), data.size(), isSymmetric);
98  }
99 
108  virtual Blob
109  encrypt(const Name& keyName, const uint8_t* data, size_t dataLength, bool isSymmetric = false) = 0;
110 
111  Blob
112  encrypt(const Name& keyName, const Blob& data, bool isSymmetric = false)
113  {
114  return encrypt(keyName, data.buf(), data.size(), isSymmetric);
115  }
116 
122  virtual void
123  generateKey(const Name& keyName, const KeyParams& params) = 0;
124 
131  virtual bool
132  doesKeyExist(const Name& keyName, KeyClass keyClass) = 0;
133 };
134 
135 }
136 
137 #endif
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
virtual Blob sign(const uint8_t *data, size_t dataLength, const Name &keyName, DigestAlgorithm digestAlgorithm=DIGEST_ALGORITHM_SHA256)=0
Fetch the private key for keyName and sign the data, returning a signature Blob.
virtual void deleteKeyPair(const Name &keyName)=0
Delete a pair of asymmetric keys.
virtual void generateKeyPair(const Name &keyName, const KeyParams &params)=0
Generate a pair of asymmetric keys.
virtual Blob encrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
Encrypt data.
virtual void generateKey(const Name &keyName, const KeyParams &params)=0
Generate a symmetric key.
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:42
virtual Blob decrypt(const Name &keyName, const uint8_t *data, size_t dataLength, bool isSymmetric=false)=0
Decrypt data.
virtual ~PrivateKeyStorage()
The virtual destructor.
Definition: private-key-storage.hpp:41
A Blob holds a pointer to an immutable byte array implemented as const std::vector.
Definition: blob.hpp:42
const uint8_t * buf() const
Return a const pointer to the first byte of the immutable byte array, or 0 if the pointer is null...
Definition: blob.hpp:138
size_t size() const
Return the length of the immutable byte array.
Definition: blob.hpp:126
KeyParams is a base class for key parameters.
Definition: key-params.hpp:34
virtual ptr_lib::shared_ptr< PublicKey > getPublicKey(const Name &keyName)=0
Get the public key.
virtual bool doesKeyExist(const Name &keyName, KeyClass keyClass)=0
Check if a particular key exists.
Definition: private-key-storage.hpp:35