blob: 6fa9c0a9c07cda7a8760494b3f3b5d7ae1a68732 [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 Thompson3392fd62013-08-09 12:20:04 -07009#include "data.hpp"
Jeff Thompson47c93cf2013-08-09 00:38:48 -070010
11namespace ndn {
12
13class KeyChain {
14public:
15 /**
Jeff Thompson3c73da42013-08-12 11:19:05 -070016 * In data, set the signed info publisher public key digest and key locator key to the public key and set the
17 * 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
19 * data.getSignedInfo().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.
25 */
26 static void sign
27 (Data &data, const unsigned char *publicKeyDer, unsigned int publicKeyDerLength,
28 const unsigned char *privateKeyDer, unsigned int privateKeyDerLength);
29
30 /**
31 * Call sign with the default public and private keys.
32 * @param data
Jeff Thompson47c93cf2013-08-09 00:38:48 -070033 */
34 static void defaultSign(Data &data);
Jeff Thompson1e90d8c2013-08-12 16:09:25 -070035
36 /**
37 * Use the WireFormat to decode the input as a Data packet and use the public key in the key locator to
38 * verify the signature.
39 * This does just uses the public key without checking whether it is certified.
40 * @param input A pointer to the input buffer to decode.
41 * @param inputLength The number of bytes in input.
42 * @param wireFormat The WireFormat for calling decodeData.
43 * @return true if the public key in the Data object verifies the object, false if not or if the Data object
44 * doesn't have a public key.
45 */
46 static bool selfVerifyData(const unsigned char *input, unsigned int inputLength, WireFormat &wireFormat);
47
48 static bool selfVerifyData(const unsigned char *input, unsigned int inputLength)
49 {
50 return selfVerifyData(input, inputLength, *WireFormat::getDefaultWireFormat());
51 }
Jeff Thompson47c93cf2013-08-09 00:38:48 -070052};
53
54}
55
56#endif