OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "remoting/base/rsa_key_pair.h" | 7 #include "remoting/base/rsa_key_pair.h" |
8 #include "remoting/base/test_rsa_key_pair.h" | 8 #include "remoting/base/test_rsa_key_pair.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // Sign a message and check that we get the expected signature. | 68 // Sign a message and check that we get the expected signature. |
69 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); | 69 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::FromString(kTestRsaKeyPair); |
70 | 70 |
71 std::string signature_base64 = key_pair->SignMessage(kTestMessage); | 71 std::string signature_base64 = key_pair->SignMessage(kTestMessage); |
72 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); | 72 ASSERT_EQ(signature_base64, std::string(kExpectedSignature)); |
73 } | 73 } |
74 | 74 |
75 TEST_F(RsaKeyPairTest, GenerateKey) { | 75 TEST_F(RsaKeyPairTest, GenerateKey) { |
76 // Test that we can generate a valid key. | 76 // Test that we can generate a valid key. |
77 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); | 77 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); |
78 ASSERT_TRUE(key_pair); | 78 ASSERT_TRUE(key_pair.get()); |
79 ASSERT_NE(key_pair->ToString(), ""); | 79 ASSERT_NE(key_pair->ToString(), ""); |
80 ASSERT_NE(key_pair->GetPublicKey(), ""); | 80 ASSERT_NE(key_pair->GetPublicKey(), ""); |
81 ASSERT_NE(key_pair->SignMessage(kTestMessage), ""); | 81 ASSERT_NE(key_pair->SignMessage(kTestMessage), ""); |
82 } | 82 } |
83 | 83 |
84 TEST_F(RsaKeyPairTest, SignaturesDiffer) { | 84 TEST_F(RsaKeyPairTest, SignaturesDiffer) { |
85 // Sign using different keys/messages and check that signatures are different. | 85 // Sign using different keys/messages and check that signatures are different. |
86 scoped_refptr<RsaKeyPair> key_pair1 = RsaKeyPair::FromString(kTestRsaKeyPair); | 86 scoped_refptr<RsaKeyPair> key_pair1 = RsaKeyPair::FromString(kTestRsaKeyPair); |
87 scoped_refptr<RsaKeyPair> key_pair2 = RsaKeyPair::FromString( | 87 scoped_refptr<RsaKeyPair> key_pair2 = RsaKeyPair::FromString( |
88 kTestRsaKeyPair2); | 88 kTestRsaKeyPair2); |
89 | 89 |
90 std::string signature_kp1_msg1_base64 = key_pair1->SignMessage(kTestMessage); | 90 std::string signature_kp1_msg1_base64 = key_pair1->SignMessage(kTestMessage); |
91 std::string signature_kp2_msg1_base64 = key_pair2->SignMessage(kTestMessage); | 91 std::string signature_kp2_msg1_base64 = key_pair2->SignMessage(kTestMessage); |
92 std::string signature_kp1_msg2_base64 = key_pair1->SignMessage("Different"); | 92 std::string signature_kp1_msg2_base64 = key_pair1->SignMessage("Different"); |
93 ASSERT_NE(signature_kp1_msg1_base64, signature_kp2_msg1_base64); | 93 ASSERT_NE(signature_kp1_msg1_base64, signature_kp2_msg1_base64); |
94 ASSERT_NE(signature_kp1_msg1_base64, signature_kp1_msg2_base64); | 94 ASSERT_NE(signature_kp1_msg1_base64, signature_kp1_msg2_base64); |
95 ASSERT_NE(key_pair1->GetPublicKey(), key_pair2->GetPublicKey()); | 95 ASSERT_NE(key_pair1->GetPublicKey(), key_pair2->GetPublicKey()); |
96 } | 96 } |
97 | 97 |
98 } // namespace remoting | 98 } // namespace remoting |
OLD | NEW |