blob: 95f1a194cd9e3bd40cc7a7cfcea1daea2770eb92 [file] [log] [blame]
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/containers/lru_cache.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 {
SignatureCache(const SignatureCache&) = delete;
SignatureCache& operator=(const SignatureCache&) = delete;
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);
std::string key_;
base::Lock lock_;
base::HashingLRUCache<std::string, std::string> contents_;
} // namespace chromecast