blob: 4bc91b9782c0fd3b5929c99759303c48ad4c93bc [file] [log] [blame]
Jeff Thompson7b79eb62013-09-12 18:48:29 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
Jeff Thompson7b79eb62013-09-12 18:48:29 -07003 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
Jeff Thompson7687dc02013-09-13 11:54:07 -07004 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompson7b79eb62013-09-12 18:48:29 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_PRIVATE_KEY_STORAGE_HPP
9#define NDN_PRIVATE_KEY_STORAGE_HPP
10
11#include <string>
12#include "../../util/blob.hpp"
13#include "../security-common.hpp"
14
15namespace ndn {
16
17class PrivateKeyStorage {
Jeff Thompsona50703f2013-09-17 14:24:15 -070018public:
Jeff Thompson7b79eb62013-09-12 18:48:29 -070019 /**
20 * The virtual destructor
21 */
22 virtual
23 ~PrivateKeyStorage();
24
25#if 0
26 /**
27 * @brief generate a pair of asymmetric keys
28 * @param keyName the name of the key pair
29 * @param keyType the type of the key pair, e.g. RSA
30 * @param keySize the size of the key pair
31 */
32 virtual void
33 generateKeyPair(const string & keyName, KeyType keyType = KEY_TYPE_RSA, int keySize = 2048) = 0;
34
35 /**
36 * @brief get the public key
37 * @param keyName the name of public key
38 * @return the public key
39 */
40 virtual Ptr<Publickey>
41 getPublickey(const string & keyName) = 0;
42#endif
43
44 /**
Jeff Thompson4c11b9f2013-09-13 11:05:28 -070045 * Fetch the private key for keyName and sign the data, returning a signature Blob.
46 * @param data Pointer to the input byte array.
47 * @param dataLength The length of data.
Jeff Thompson7b79eb62013-09-12 18:48:29 -070048 * @param keyName The name of the signing key.
49 * @param digestAlgorithm the digest algorithm.
50 * @return The signature, or 0 if signing fails.
51 */
52 virtual Blob
Jeff Thompson4c11b9f2013-09-13 11:05:28 -070053 sign(const unsigned char *data, unsigned int dataLength, const std::string& keyName, DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256);
Jeff Thompson7b79eb62013-09-12 18:48:29 -070054
55#if 0
56 /**
57 * @brief decrypt data
58 * @param keyName the name of the decrypting key
59 * @param blob the blob to be decrypted
60 * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used.
61 * @return decrypted data
62 */
63 virtual Ptr<Blob>
64 decrypt(const string & keyName, const Blob & data, bool sym = false) = 0;
65
66 /**
67 * @brief encrypt data
68 * @param keyName the name of the encrypting key
69 * @param blob the blob to be encrypted
70 * @param sym if true symmetric encryption is used, otherwise asymmetric decryption is used.
71 * @return encrypted data
72 */
73 virtual Ptr<Blob>
74 encrypt(const string & keyName, const Blob & pData, bool sym = false) = 0;
75
76 /**
77 * @brief generate a symmetric key
78 * @param keyName the name of the key
79 * @param keyType the type of the key, e.g. AES
80 * @param keySize the size of the key
81 */
82 virtual void
83 generateKey(const string & keyName, KeyType keyType = KEY_TYPE_AES, int keySize = 256) = 0;
84
85 /**
86 * @brief check if a particular key exist
87 * @param keyName the name of the key
88 * @param keyClass the class of the key, e.g. public, private, or symmetric
89 * @return true if the key exists, otherwise false
90 */
91 virtual bool
92 doesKeyExist(const string & keyName, KeyClass keyClass) = 0;
93#endif
94};
95
96}
97
98#endif