Support swap promises that are pinned to a particular layer tree.
[chromium-blink-merge.git] / chromecast / crypto / signature_cache.cc
blob268391e70090e0455ebd59da74fb720788083b51
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 #include "chromecast/crypto/signature_cache.h"
7 #include "base/logging.h"
9 namespace chromecast {
11 namespace {
12 const int kSignatureCacheSize = 10;
13 } // namespace
15 SignatureCache::SignatureCache()
16 : contents_(kSignatureCacheSize) {}
18 SignatureCache::~SignatureCache() {}
20 std::string SignatureCache::Get(const std::string& wrapped_private_key,
21 const std::string& hash) {
22 std::string result;
23 base::AutoLock lock(lock_);
25 if (wrapped_private_key != key_)
26 return result;
28 const auto iter = contents_.Get(hash);
29 if (iter != contents_.end())
30 result = iter->second;
32 return result;
35 void SignatureCache::Put(const std::string& wrapped_private_key,
36 const std::string& hash,
37 const std::string& signature) {
38 base::AutoLock lock(lock_);
40 if (wrapped_private_key != key_) {
41 key_ = wrapped_private_key;
42 contents_.Clear();
45 contents_.Put(hash, signature);
48 } // namespace chromecast