blob: a2237fa0ea44e4d5d9e8e8c679bbd94893f36ea9 [file] [log] [blame]
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/**
* Copyright (C) 2013 Regents of the University of California.
* @author: Yingdi Yu <yingdi@cs.ucla.edu>
* @author: Jeff Thompson <jefft0@remap.ucla.edu>
* See COPYING for copyright and distribution information.
*/
#ifndef NDN_PUBLIC_KEY_HPP
#define NDN_PUBLIC_KEY_HPP
#include "../../util/blob.hpp"
#include "../../encoding/oid.hpp"
#include "../security-common.hpp"
namespace ndn {
namespace der { class DerNode; }
class PublicKey {
public:
/**
* The default constructor.
*/
PublicKey() {}
/**
* Create a new PublicKey with the given values.
* @param algorithm The algorithm of the public key.
* @param keyDer The blob of the PublicKeyInfo in terms of DER.
*/
PublicKey(const OID& algorithm, const Blob& keyDer)
: algorithm_(algorithm), keyDer_(keyDer)
{
}
/**
* Encode the public key into DER.
* @return the encoded DER syntax tree.
*/
ptr_lib::shared_ptr<der::DerNode>
toDer();
/**
* Decode the public key from DER blob.
* @param keyDer The DER blob.
* @return The decoded public key.
*/
static ptr_lib::shared_ptr<PublicKey>
fromDer(const Blob& keyDer);
/*
* Get the digest of the public key.
* @param digestAlgorithm The digest algorithm. If omitted, use DIGEST_ALGORITHM_SHA256 by default.
*/
Blob
getDigest(DigestAlgorithm digestAlgorithm = DIGEST_ALGORITHM_SHA256) const;
/*
* Get the raw bytes of the public key in DER format.
*/
const Blob&
getKeyDer() const { return keyDer_; }
private:
OID algorithm_; /**< Algorithm */
Blob keyDer_; /**< PublicKeyInfo in DER */
};
}
#endif