blob: a2237fa0ea44e4d5d9e8e8c679bbd94893f36ea9 [file] [log] [blame]
Jeff Thompsonc0573432013-09-19 17:41:36 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Yingdi Yu <yingdi@cs.ucla.edu>
5 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
6 * See COPYING for copyright and distribution information.
7 */
8
9#ifndef NDN_PUBLIC_KEY_HPP
Jeff Thompsone589c3f2013-10-12 17:30:50 -070010#define NDN_PUBLIC_KEY_HPP
Jeff Thompsonc0573432013-09-19 17:41:36 -070011
12#include "../../util/blob.hpp"
Jeff Thompson31b5c2f2013-10-12 15:13:16 -070013#include "../../encoding/oid.hpp"
Jeff Thompsonc0573432013-09-19 17:41:36 -070014#include "../security-common.hpp"
15
16namespace ndn {
17
Jeff Thompson07996712013-10-17 17:31:40 -070018 namespace der { class DerNode; }
19
Jeff Thompsonc0573432013-09-19 17:41:36 -070020class PublicKey {
21public:
22 /**
23 * The default constructor.
24 */
25 PublicKey() {}
26
27 /**
Jeff Thompson10a8c382013-12-13 11:53:43 -080028 * Create a new PublicKey with the given values.
Jeff Thompsonc0573432013-09-19 17:41:36 -070029 * @param algorithm The algorithm of the public key.
30 * @param keyDer The blob of the PublicKeyInfo in terms of DER.
31 */
32 PublicKey(const OID& algorithm, const Blob& keyDer)
33 : algorithm_(algorithm), keyDer_(keyDer)
34 {
35 }
36
Jeff Thompsonc0573432013-09-19 17:41:36 -070037 /**
38 * Encode the public key into DER.
39 * @return the encoded DER syntax tree.
40 */
Jeff Thompson07996712013-10-17 17:31:40 -070041 ptr_lib::shared_ptr<der::DerNode>
Jeff Thompsonc0573432013-09-19 17:41:36 -070042 toDer();
Jeff Thompsonc0573432013-09-19 17:41:36 -070043
44 /**
45 * Decode the public key from DER blob.
46 * @param keyDer The DER blob.
47 * @return The decoded public key.
48 */
49 static ptr_lib::shared_ptr<PublicKey>
50 fromDer(const Blob& keyDer);
51
52 /*
Jeff Thompson10a8c382013-12-13 11:53:43 -080053 * Get the digest of the public key.
54 * @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_ALGORITHM_SHA256 by default.
Jeff Thompsonc0573432013-09-19 17:41:36 -070055 */
56 Blob
57 getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
58
59 /*
60 * Get the raw bytes of the public key in DER format.
61 */
62 const Blob&
63 getKeyDer() const { return keyDer_; }
64
65private:
66 OID algorithm_; /**< Algorithm */
67 Blob keyDer_; /**< PublicKeyInfo in DER */
68};
69
70}
71
72#endif