proxygen
OpenSSLKeyExchange-inl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 namespace fizz {
10 namespace detail {
11 
12 template <class T>
14  public:
15  void generateKeyPair() {
16  key_ = generateECKeyPair(T::curveNid);
17  }
18 
20  validateECKey(privateKey, T::curveNid);
21  key_ = std::move(privateKey);
22  }
23 
25  return key_;
26  }
27 
28  std::unique_ptr<folly::IOBuf> generateSharedSecret(
29  const folly::ssl::EvpPkeyUniquePtr& peerKey) const {
30  if (!key_) {
31  throw std::runtime_error("Key not generated");
32  }
33  return generateEvpSharedSecret(key_, peerKey);
34  }
35 
36  private:
38 };
39 
40 template <class T>
42  public:
44  return decodeECPublicKey(range, T::curveNid);
45  }
46 };
47 
49  public:
50  static std::unique_ptr<folly::IOBuf> encode(
51  const folly::ssl::EvpPkeyUniquePtr& key) {
52  return encodeECPublicKey(key);
53  }
54 };
55 } // namespace detail
56 } // namespace fizz
std::unique_ptr< folly::IOBuf > generateSharedSecret(const folly::ssl::EvpPkeyUniquePtr &peerKey) const
static folly::ssl::EvpPkeyUniquePtr decode(folly::ByteRange range)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
void setPrivateKey(folly::ssl::EvpPkeyUniquePtr privateKey)
folly::ssl::EvpPkeyUniquePtr decodeECPublicKey(folly::ByteRange range, int curveNid)
Gen range(Value begin, Value end)
Definition: Base.h:467
folly::ssl::EvpPkeyUniquePtr key_
void validateECKey(const folly::ssl::EvpPkeyUniquePtr &key, int curveNid)
Definition: Actions.h:16
const folly::ssl::EvpPkeyUniquePtr & getKey() const
static std::unique_ptr< folly::IOBuf > encode(const folly::ssl::EvpPkeyUniquePtr &key)
std::unique_ptr< folly::IOBuf > generateEvpSharedSecret(const folly::ssl::EvpPkeyUniquePtr &key, const folly::ssl::EvpPkeyUniquePtr &peerKey)
std::unique_ptr< folly::IOBuf > encodeECPublicKey(const folly::ssl::EvpPkeyUniquePtr &key)
folly::ssl::EvpPkeyUniquePtr generateECKeyPair(int curveNid)