Jeff Thompson | c057343 | 2013-09-19 17:41:36 -0700 | [diff] [blame^] | 1 | /* -*- 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 |
| 10 | #define NDN_PUBLIC_KEY_HPP |
| 11 | |
| 12 | #include "../../util/blob.hpp" |
| 13 | #include "oid.hpp" |
| 14 | #include "../security-common.hpp" |
| 15 | |
| 16 | namespace ndn { |
| 17 | |
| 18 | class PublicKey { |
| 19 | public: |
| 20 | /** |
| 21 | * The default constructor. |
| 22 | */ |
| 23 | PublicKey() {} |
| 24 | |
| 25 | /** |
| 26 | * Constructor |
| 27 | * @param algorithm The algorithm of the public key. |
| 28 | * @param keyDer The blob of the PublicKeyInfo in terms of DER. |
| 29 | */ |
| 30 | PublicKey(const OID& algorithm, const Blob& keyDer) |
| 31 | : algorithm_(algorithm), keyDer_(keyDer) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | #if 0 |
| 36 | /** |
| 37 | * Encode the public key into DER. |
| 38 | * @return the encoded DER syntax tree. |
| 39 | */ |
| 40 | Ptr<der::DerNode> |
| 41 | toDer(); |
| 42 | #endif |
| 43 | |
| 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 | /* |
| 53 | * @brief get the digest of the public key |
| 54 | * @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_SHA256 by default. |
| 55 | */ |
| 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 | |
| 65 | private: |
| 66 | OID algorithm_; /**< Algorithm */ |
| 67 | Blob keyDer_; /**< PublicKeyInfo in DER */ |
| 68 | }; |
| 69 | |
| 70 | } |
| 71 | |
| 72 | #endif |