1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  *
7  */
8 
9 #include <quic/fizz/server/handshake/FizzServerQuicHandshakeContext.h>
10 
11 #include <quic/fizz/server/handshake/FizzServerHandshake.h>
12 
13 namespace quic {
14 
FizzServerQuicHandshakeContext(std::shared_ptr<const fizz::server::FizzServerContext> context)15 FizzServerQuicHandshakeContext::FizzServerQuicHandshakeContext(
16     std::shared_ptr<const fizz::server::FizzServerContext> context)
17     : context_(std::move(context)) {}
18 
FizzServerQuicHandshakeContext(std::shared_ptr<const fizz::server::FizzServerContext> context,std::unique_ptr<CryptoFactory> cryptoFactory)19 FizzServerQuicHandshakeContext::FizzServerQuicHandshakeContext(
20     std::shared_ptr<const fizz::server::FizzServerContext> context,
21     std::unique_ptr<CryptoFactory> cryptoFactory)
22     : context_(std::move(context)), cryptoFactory_(std::move(cryptoFactory)) {}
23 
24 std::unique_ptr<ServerHandshake>
makeServerHandshake(QuicServerConnectionState * conn)25 FizzServerQuicHandshakeContext::makeServerHandshake(
26     QuicServerConnectionState* conn) && {
27   if (!cryptoFactory_) {
28     cryptoFactory_ = std::make_unique<FizzCryptoFactory>();
29   }
30   return std::make_unique<FizzServerHandshake>(
31       conn, shared_from_this(), std::move(cryptoFactory_));
32 }
33 
34 std::shared_ptr<FizzServerQuicHandshakeContext>
build()35 FizzServerQuicHandshakeContext::Builder::build() && {
36   if (!context_) {
37     context_ = std::make_shared<const fizz::server::FizzServerContext>();
38   }
39 
40   return std::shared_ptr<FizzServerQuicHandshakeContext>(
41       new FizzServerQuicHandshakeContext(
42           std::move(context_), std::move(cryptoFactory_)));
43 }
44 
45 } // namespace quic
46