blob: 0afa4b55ac9cb8e9b2792f2a1483865d48dec1cb [file] [log] [blame]
Jeff Thompson47c93cf2013-08-09 00:38:48 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_KEY_CHAIN_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_KEY_CHAIN_HPP
Jeff Thompson47c93cf2013-08-09 00:38:48 -07008
Jeff Thompson7a67cb62013-08-26 11:43:18 -07009#include "../data.hpp"
Jeff Thompson47c93cf2013-08-09 00:38:48 -070010
11namespace ndn {
12
13class KeyChain {
14public:
15 /**
Jeff Thompsonfec716d2013-09-11 13:54:36 -070016 * In data, set the meta info publisher public key digest and key locator key to the public key and set the
Jeff Thompson3c73da42013-08-12 11:19:05 -070017 * signature using the private key.
Jeff Thompsonade5b1e2013-08-09 12:16:45 -070018 * Note: the caller must make sure the timestamp is correct, for example with
Jeff Thompsonfec716d2013-09-11 13:54:36 -070019 * data.getMetaInfo().setTimestampMilliseconds(time(NULL) * 1000.0).
Jeff Thompson3c73da42013-08-12 11:19:05 -070020 * @param data The Data object to sign and set the key and signature.
21 * @param publicKeyDer A pointer to a buffer with the DER-encoded public key.
22 * @param publicKeyDerLength The number of bytes in publicKeyDer.
23 * @param privateKeyDer A pointer to a buffer with the DER-encoded private key.
24 * @param privateKeyDerLength The number of bytes in privateKeyDer.
Jeff Thompson8efe5ad2013-08-20 17:36:38 -070025 * @param wireFormat The WireFormat for calling encodeData.
Jeff Thompson3c73da42013-08-12 11:19:05 -070026 */
27 static void sign
Jeff Thompson1656e6a2013-08-29 18:01:48 -070028 (Data& data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength,
29 const unsigned char *privateKeyDer, unsigned int privateKeyDerLength, WireFormat& wireFormat);
Jeff Thompson3c73da42013-08-12 11:19:05 -070030
31 /**
32 * Call sign with the default public and private keys.
33 * @param data
Jeff Thompsona7516e02013-09-11 17:12:25 -070034 * @param wireFormat The WireFormat for calling encodeData, or WireFormat::getDefaultWireFormat() if omitted.
Jeff Thompson8efe5ad2013-08-20 17:36:38 -070035 */
Jeff Thompsona7516e02013-09-11 17:12:25 -070036 static void defaultSign(Data& data, WireFormat& wireFormat = *WireFormat::getDefaultWireFormat());
Jeff Thompson8efe5ad2013-08-20 17:36:38 -070037
38 /**
Jeff Thompson1e90d8c2013-08-12 16:09:25 -070039 * Use the WireFormat to decode the input as a Data packet and use the public key in the key locator to
40 * verify the signature.
41 * This does just uses the public key without checking whether it is certified.
42 * @param input A pointer to the input buffer to decode.
43 * @param inputLength The number of bytes in input.
44 * @param wireFormat The WireFormat for calling decodeData.
45 * @return true if the public key in the Data object verifies the object, false if not or if the Data object
46 * doesn't have a public key.
47 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070048 static bool selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat& wireFormat);
Jeff Thompson1e90d8c2013-08-12 16:09:25 -070049
50 static bool selfVerifyData(const unsigned char *input, unsigned int inputLength)
51 {
52 return selfVerifyData(input, inputLength, *WireFormat::getDefaultWireFormat());
53 }
Jeff Thompson47c93cf2013-08-09 00:38:48 -070054};
55
56}
57
58#endif