proxygen
DualTicketCipher.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 #pragma once
10 
12 
13 namespace fizz {
14 namespace server {
15 
22  public:
24  std::unique_ptr<TicketCipher> cipher,
25  std::unique_ptr<TicketCipher> fallbackCipher)
26  : cipher_(std::move(cipher)),
27  fallbackCipher_(std::move(fallbackCipher)) {}
28 
30  std::pair<std::unique_ptr<folly::IOBuf>, std::chrono::seconds>>>
31  encrypt(ResumptionState resState) const override {
32  return cipher_->encrypt(std::move(resState));
33  }
34 
36  std::unique_ptr<folly::IOBuf> encryptedTicket) const override {
37  auto bufClone = encryptedTicket->clone();
38  return cipher_->decrypt(std::move(encryptedTicket))
39  .thenValue([this, ticket = std::move(bufClone)](
41  res) mutable {
42  if (std::get<0>(res) == PskType::Rejected) {
43  return fallbackCipher_->decrypt(std::move(ticket));
44  }
45  return folly::makeFuture(std::move(res));
46  });
47  }
48 
49  private:
50  std::unique_ptr<TicketCipher> cipher_;
51  std::unique_ptr<TicketCipher> fallbackCipher_;
52 };
53 } // namespace server
54 } // namespace fizz
DualTicketCipher(std::unique_ptr< TicketCipher > cipher, std::unique_ptr< TicketCipher > fallbackCipher)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
STL namespace.
folly::Future< folly::Optional< std::pair< std::unique_ptr< folly::IOBuf >, std::chrono::seconds > > > encrypt(ResumptionState resState) const override
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
CipherSuite cipher
static constexpr StringPiece ticket
std::unique_ptr< TicketCipher > fallbackCipher_
folly::Future< std::pair< PskType, folly::Optional< ResumptionState > > > decrypt(std::unique_ptr< folly::IOBuf > encryptedTicket) const override
Definition: Actions.h:16
PskType
Definition: Types.h:18
std::unique_ptr< TicketCipher > cipher_
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310