proxygen
PskCache.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 #include <fizz/protocol/Types.h>
13 #include <fizz/record/Types.h>
14 #include <chrono>
15 #include <unordered_map>
16 
17 namespace fizz {
18 namespace client {
19 
20 struct CachedPsk {
24 
28  std::shared_ptr<const Cert> serverCert;
29  std::shared_ptr<const Cert> clientCert;
30 
33 
35  std::chrono::system_clock::time_point ticketIssueTime;
36  std::chrono::system_clock::time_point ticketExpirationTime;
37 };
38 
39 class PskCache {
40  public:
41  virtual ~PskCache() = default;
42 
46  virtual folly::Optional<CachedPsk> getPsk(const std::string& identity) = 0;
47 
51  virtual void putPsk(const std::string& identity, CachedPsk) = 0;
52 
56  virtual void removePsk(const std::string& identity) = 0;
57 };
58 
63 class BasicPskCache : public PskCache {
64  public:
65  ~BasicPskCache() override = default;
66 
67  folly::Optional<CachedPsk> getPsk(const std::string& identity) override {
68  auto result = cache_.find(identity);
69  if (result != cache_.end()) {
70  return result->second;
71  } else {
72  return folly::none;
73  }
74  }
75 
76  void putPsk(const std::string& identity, CachedPsk psk) override {
77  cache_[identity] = std::move(psk);
78  }
79 
80  void removePsk(const std::string& identity) override {
81  cache_.erase(identity);
82  }
83 
84  private:
85  std::unordered_map<std::string, CachedPsk> cache_;
86 };
87 } // namespace client
88 } // namespace fizz
std::shared_ptr< const Cert > clientCert
Definition: PskCache.h:29
std::chrono::system_clock::time_point ticketIssueTime
Definition: PskCache.h:35
folly::Optional< std::string > alpn
Definition: PskCache.h:32
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CipherSuite
Definition: Types.h:153
void removePsk(const std::string &identity) override
Definition: PskCache.h:80
ProtocolVersion version
Definition: PskCache.h:25
ProtocolVersion
Definition: Types.h:24
void putPsk(const std::string &identity, CachedPsk psk) override
Definition: PskCache.h:76
folly::Optional< NamedGroup > group
Definition: PskCache.h:27
std::string secret
Definition: PskCache.h:22
Definition: Actions.h:16
std::unordered_map< std::string, CachedPsk > cache_
Definition: PskCache.h:85
std::shared_ptr< const Cert > serverCert
Definition: PskCache.h:28
PskType
Definition: Types.h:18
const char * string
Definition: Conv.cpp:212
folly::Optional< CachedPsk > getPsk(const std::string &identity) override
Definition: PskCache.h:67
CipherSuite cipher
Definition: PskCache.h:26
uint32_t maxEarlyDataSize
Definition: PskCache.h:31
std::chrono::system_clock::time_point ticketExpirationTime
Definition: PskCache.h:36
constexpr None none
Definition: Optional.h:87