gunsch | 5ed6d7d | 2015-08-31 22:56:19 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_ |
| 6 | #define CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/containers/mru_cache.h" |
| 11 | #include "base/macros.h" |
| 12 | #include "base/synchronization/lock.h" |
| 13 | |
| 14 | namespace chromecast { |
| 15 | |
| 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(); |
| 25 | |
| 26 | std::string Get(const std::string& wrapped_private_key, |
| 27 | const std::string& hash); |
| 28 | |
| 29 | void Put(const std::string& wrapped_private_key, |
| 30 | const std::string& hash, |
| 31 | const std::string& signature); |
| 32 | |
| 33 | private: |
| 34 | std::string key_; |
| 35 | base::Lock lock_; |
| 36 | base::HashingMRUCache<std::string, std::string> contents_; |
| 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(SignatureCache); |
| 39 | }; |
| 40 | |
| 41 | } // namespace chromecast |
| 42 | |
| 43 | #endif // CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_ |