summaryrefslogtreecommitdiffstats
path: root/chromecast/crypto/signature_cache.h
blob: b132b8e4b1733b6550e2687d57a974c2906dd731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_
#define CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_

#include <string>

#include "base/containers/mru_cache.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"

namespace chromecast {

// Cache the signatures of hashes corresponding to a particular private key
// (only the most recent one for which a signature was cached). We expect that
// normally the same private key will be used always, however we also
// accommodate the case where the key is changed and a new key becomes current.
// In this case we flush the cache and start over with the new key.
class SignatureCache {
 public:
  SignatureCache();
  ~SignatureCache();

  std::string Get(const std::string& wrapped_private_key,
                  const std::string& hash);

  void Put(const std::string& wrapped_private_key,
           const std::string& hash,
           const std::string& signature);

 private:
  std::string key_;
  base::Lock lock_;
  base::HashingMRUCache<std::string, std::string> contents_;

  DISALLOW_COPY_AND_ASSIGN(SignatureCache);
};

}  // namespace chromecast

#endif  // CHROMECAST_CRYPTO_SIGNATURE_CACHE_H_