key-handle-mem.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #include "key-handle-mem.hpp"
23 #include "../../encoding/buffer-stream.hpp"
24 #include "../transform.hpp"
25 #include "../transform/private-key.hpp"
26 
27 namespace ndn {
28 namespace security {
29 namespace tpm {
30 
32 
33 KeyHandleMem::KeyHandleMem(shared_ptr<PrivateKey> key)
34  : m_key(key)
35 {
36  BOOST_ASSERT(key != nullptr);
37 }
38 
40 KeyHandleMem::doSign(DigestAlgorithm digestAlgorithm, const uint8_t* buf, size_t size) const
41 {
42  switch (digestAlgorithm) {
44  using namespace transform;
45 
46  OBufferStream sigOs;
47  bufferSource(buf, size) >> signerFilter(digestAlgorithm, *m_key) >> streamSink(sigOs);
48  return sigOs.buf();
49  }
50  default:
51  return nullptr;
52  }
53 }
54 
56 KeyHandleMem::doDecrypt(const uint8_t* cipherText, size_t cipherTextLen) const
57 {
58  return m_key->decrypt(cipherText, cipherTextLen);
59 }
60 
62 KeyHandleMem::doDerivePublicKey() const
63 {
64  return m_key->derivePublicKey();
65 }
66 
67 } // namespace tpm
68 } // namespace security
69 } // namespace ndn
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
unique_ptr< Transform > signerFilter(DigestAlgorithm algo, const PrivateKey &key)
KeyHandleMem(shared_ptr< transform::PrivateKey > key)
unique_ptr< Sink > streamSink(std::ostream &os)
Definition: stream-sink.cpp:51
Use the SHA256 hash of the public key as the key id.
shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
implements an output stream that constructs ndn::Buffer
shared_ptr< const Buffer > ConstBufferPtr
Definition: buffer.hpp:33