Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/cert/ct_serialization.h" | 5 #include "net/cert/ct_serialization.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 std::string expected_prefix("\0\0\0\x2\xCE", 5); | 87 std::string expected_prefix("\0\0\0\x2\xCE", 5); |
| 88 // Note we use std::string comparison rather than ASSERT_STREQ due | 88 // Note we use std::string comparison rather than ASSERT_STREQ due |
| 89 // to null characters in the buffer. | 89 // to null characters in the buffer. |
| 90 EXPECT_EQ(expected_prefix, encoded.substr(0, 5)); | 90 EXPECT_EQ(expected_prefix, encoded.substr(0, 5)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 TEST_F(CtSerializationTest, EncodesV1SCTSignedData) { | 93 TEST_F(CtSerializationTest, EncodesV1SCTSignedData) { |
| 94 base::Time timestamp = base::Time::UnixEpoch() + | 94 base::Time timestamp = base::Time::UnixEpoch() + |
| 95 base::TimeDelta::FromMilliseconds(1348589665525); | 95 base::TimeDelta::FromMilliseconds(1348589665525); |
| 96 std::string dummy_entry("abc"); | 96 std::string dummy_entry("abc"); |
| 97 std::string empty_extensions(""); | 97 std::string empty_extensions(); |
|
Nico
2014/01/29 22:15:24
Isn't this a function declaration now? Drop the pa
Lei Zhang
2014/01/29 22:20:16
Done.
| |
| 98 // For now, no known failure cases. | 98 // For now, no known failure cases. |
| 99 std::string encoded; | 99 std::string encoded; |
| 100 ASSERT_TRUE(ct::EncodeV1SCTSignedData( | 100 ASSERT_TRUE(ct::EncodeV1SCTSignedData( |
| 101 timestamp, | 101 timestamp, |
| 102 dummy_entry, | 102 dummy_entry, |
| 103 empty_extensions, | 103 empty_extensions, |
| 104 &encoded)); | 104 &encoded)); |
| 105 EXPECT_EQ((size_t) 15, encoded.size()); | 105 EXPECT_EQ((size_t) 15, encoded.size()); |
| 106 // Byte 0 is version, byte 1 is signature type | 106 // Byte 0 is version, byte 1 is signature type |
| 107 // Bytes 2-10 are timestamp | 107 // Bytes 2-10 are timestamp |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 138 scoped_refptr<ct::SignedCertificateTimestamp> sct; | 138 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
| 139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); | 139 ASSERT_TRUE(ct::DecodeSignedCertificateTimestamp(&encoded_sct, &sct)); |
| 140 EXPECT_EQ(0, sct->version); | 140 EXPECT_EQ(0, sct->version); |
| 141 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); | 141 EXPECT_EQ(ct::GetTestPublicKeyId(), sct->log_id); |
| 142 base::Time expected_time = base::Time::UnixEpoch() + | 142 base::Time expected_time = base::Time::UnixEpoch() + |
| 143 base::TimeDelta::FromMilliseconds(1365181456089); | 143 base::TimeDelta::FromMilliseconds(1365181456089); |
| 144 EXPECT_EQ(expected_time, sct->timestamp); | 144 EXPECT_EQ(expected_time, sct->timestamp); |
| 145 // Subtracting 4 bytes for signature data (hash & sig algs), | 145 // Subtracting 4 bytes for signature data (hash & sig algs), |
| 146 // actual signature data should be 71 bytes. | 146 // actual signature data should be 71 bytes. |
| 147 EXPECT_EQ((size_t) 71, sct->signature.signature_data.size()); | 147 EXPECT_EQ((size_t) 71, sct->signature.signature_data.size()); |
| 148 EXPECT_EQ(std::string(""), sct->extensions); | 148 EXPECT_TRUE(sct->extensions.empty()); |
| 149 } | 149 } |
| 150 | 150 |
| 151 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { | 151 TEST_F(CtSerializationTest, FailsDecodingInvalidSignedCertificateTimestamp) { |
| 152 // Invalid version | 152 // Invalid version |
| 153 base::StringPiece invalid_version_sct("\x2\x0", 2); | 153 base::StringPiece invalid_version_sct("\x2\x0", 2); |
| 154 scoped_refptr<ct::SignedCertificateTimestamp> sct; | 154 scoped_refptr<ct::SignedCertificateTimestamp> sct; |
| 155 | 155 |
| 156 ASSERT_FALSE( | 156 ASSERT_FALSE( |
| 157 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); | 157 ct::DecodeSignedCertificateTimestamp(&invalid_version_sct, &sct)); |
| 158 | 158 |
| 159 // Valid version, invalid length (missing data) | 159 // Valid version, invalid length (missing data) |
| 160 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); | 160 base::StringPiece invalid_length_sct("\x0\xa\xb\xc", 4); |
| 161 ASSERT_FALSE( | 161 ASSERT_FALSE( |
| 162 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); | 162 ct::DecodeSignedCertificateTimestamp(&invalid_length_sct, &sct)); |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace net | 165 } // namespace net |
| 166 | 166 |
| OLD | NEW |