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 
11 #include <folly/Range.h>
12 #include <folly/futures/Future.h>
13 
14 namespace fizz {
15 namespace server {
16 
17 enum ReplayCacheResult {
18   NotChecked,
19   NotReplay,
20   MaybeReplay,
21   DefinitelyReplay,
22 };
23 }
24 
25 folly::StringPiece toString(server::ReplayCacheResult);
26 
27 namespace server {
28 
29 /**
30  * Anti-replay cache that checks if a unique identifier has been received
31  * before.
32  */
33 class ReplayCache {
34  public:
35   virtual ~ReplayCache() = default;
36 
37   virtual folly::Future<ReplayCacheResult> check(
38       folly::ByteRange identifier) = 0;
39 };
40 
41 /**
42  * Replay cache implementation that allows replays.
43  */
44 class AllowAllReplayReplayCache : public ReplayCache {
45  public:
46   ~AllowAllReplayReplayCache() override = default;
47 
check(folly::ByteRange)48   folly::Future<ReplayCacheResult> check(folly::ByteRange) override {
49     return ReplayCacheResult::NotReplay;
50   }
51 };
52 } // namespace server
53 } // namespace fizz
54