Roll src/third_party/WebKit 56db356:7227c61 (svn 201871:201874)
[chromium-blink-merge.git] / chromecast / crypto / signature_cache.h
blobb132b8e4b1733b6550e2687d57a974c2906dd731
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_
6 #define CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_
8 #include <string>
10 #include "base/containers/mru_cache.h"
11 #include "base/macros.h"
12 #include "base/synchronization/lock.h"
14 namespace chromecast {
16 // Cache the signatures of hashes corresponding to a particular private key
17 // (only the most recent one for which a signature was cached). We expect that
18 // normally the same private key will be used always, however we also
19 // accommodate the case where the key is changed and a new key becomes current.
20 // In this case we flush the cache and start over with the new key.
21 class SignatureCache {
22 public:
23 SignatureCache();
24 ~SignatureCache();
26 std::string Get(const std::string& wrapped_private_key,
27 const std::string& hash);
29 void Put(const std::string& wrapped_private_key,
30 const std::string& hash,
31 const std::string& signature);
33 private:
34 std::string key_;
35 base::Lock lock_;
36 base::HashingMRUCache<std::string, std::string> contents_;
38 DISALLOW_COPY_AND_ASSIGN(SignatureCache);
41 } // namespace chromecast
43 #endif // CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_