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"
6 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(SignatureCache
, Hit
) {
12 const std::string
private_key1("key1");
13 const std::string
hash1("hash1");
14 const std::string
hash2("hash2");
15 const std::string
signature1("signature1");
16 const std::string
signature2("signature2");
18 cache
.Put(private_key1
, hash1
, signature1
);
19 cache
.Put(private_key1
, hash2
, signature2
);
20 ASSERT_EQ(signature1
, cache
.Get(private_key1
, hash1
));
21 ASSERT_EQ(signature2
, cache
.Get(private_key1
, hash2
));
24 TEST(SignatureCache
, Miss
) {
25 const std::string
private_key1("key1");
26 const std::string
hash1("hash1");
27 const std::string
hash2("hash2");
28 const std::string
signature1("signature1");
30 cache
.Put(private_key1
, hash1
, signature1
);
31 ASSERT_EQ("", cache
.Get(private_key1
, hash2
));
34 TEST(SignatureCache
, NewPrivateKeyHit
) {
35 const std::string
private_key1("key1");
36 const std::string
private_key2("key2");
37 const std::string
hash1("hash1");
38 const std::string
signature1("signature1");
40 cache
.Put(private_key1
, hash1
, signature1
);
41 cache
.Put(private_key2
, hash1
, signature1
);
42 ASSERT_EQ(signature1
, cache
.Get(private_key2
, hash1
));
45 TEST(SignatureCache
, NewPrivateKeyMiss
) {
46 const std::string
private_key1("key1");
47 const std::string
private_key2("key2");
48 const std::string
hash1("hash1");
49 const std::string
signature1("signature1");
51 cache
.Put(private_key1
, hash1
, signature1
);
52 ASSERT_EQ("", cache
.Get(private_key2
, hash1
));
53 cache
.Put(private_key2
, hash1
, signature1
);
54 ASSERT_NE(signature1
, cache
.Get(private_key1
, hash1
));
58 } // namespace chromecast