| 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 "net/quic/crypto/null_decrypter.h" | 5 #include "net/quic/crypto/null_decrypter.h" |
| 6 #include "net/quic/test_tools/quic_test_utils.h" | 6 #include "net/quic/test_tools/quic_test_utils.h" |
| 7 | 7 |
| 8 using base::StringPiece; | 8 using base::StringPiece; |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 namespace test { | 11 namespace test { |
| 12 | 12 |
| 13 class NullDecrypterTest : public ::testing::TestWithParam<bool> { | 13 class NullDecrypterTest : public ::testing::TestWithParam<bool> {}; |
| 14 }; | |
| 15 | 14 |
| 16 TEST_F(NullDecrypterTest, Decrypt) { | 15 TEST_F(NullDecrypterTest, Decrypt) { |
| 17 unsigned char expected[] = { | 16 unsigned char expected[] = {// fnv hash |
| 18 // fnv hash | 17 0xa0, 0x6f, 0x44, 0x8a, 0x44, 0xf8, 0x18, 0x3b, |
| 19 0xa0, 0x6f, 0x44, 0x8a, | 18 0x47, 0x91, 0xb2, 0x13, |
| 20 0x44, 0xf8, 0x18, 0x3b, | 19 // payload |
| 21 0x47, 0x91, 0xb2, 0x13, | 20 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', |
| 22 // payload | |
| 23 'g', 'o', 'o', 'd', | |
| 24 'b', 'y', 'e', '!', | |
| 25 }; | 21 }; |
| 26 const char* data = reinterpret_cast<const char*>(expected); | 22 const char* data = reinterpret_cast<const char*>(expected); |
| 27 size_t len = arraysize(expected); | 23 size_t len = arraysize(expected); |
| 28 NullDecrypter decrypter; | 24 NullDecrypter decrypter; |
| 29 scoped_ptr<QuicData> decrypted( | 25 scoped_ptr<QuicData> decrypted( |
| 30 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); | 26 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); |
| 31 ASSERT_TRUE(decrypted.get()); | 27 ASSERT_TRUE(decrypted.get()); |
| 32 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); | 28 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); |
| 33 } | 29 } |
| 34 | 30 |
| 35 TEST_F(NullDecrypterTest, BadHash) { | 31 TEST_F(NullDecrypterTest, BadHash) { |
| 36 unsigned char expected[] = { | 32 unsigned char expected[] = {// fnv hash |
| 37 // fnv hash | 33 0x46, 0x11, 0xea, 0x5f, 0xcf, 0x1d, 0x66, 0x5b, |
| 38 0x46, 0x11, 0xea, 0x5f, | 34 0xba, 0xf0, 0xbc, 0xfd, |
| 39 0xcf, 0x1d, 0x66, 0x5b, | 35 // payload |
| 40 0xba, 0xf0, 0xbc, 0xfd, | 36 'g', 'o', 'o', 'd', 'b', 'y', 'e', '!', |
| 41 // payload | |
| 42 'g', 'o', 'o', 'd', | |
| 43 'b', 'y', 'e', '!', | |
| 44 }; | 37 }; |
| 45 const char* data = reinterpret_cast<const char*>(expected); | 38 const char* data = reinterpret_cast<const char*>(expected); |
| 46 size_t len = arraysize(expected); | 39 size_t len = arraysize(expected); |
| 47 NullDecrypter decrypter; | 40 NullDecrypter decrypter; |
| 48 scoped_ptr<QuicData> decrypted( | 41 scoped_ptr<QuicData> decrypted( |
| 49 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); | 42 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); |
| 50 ASSERT_FALSE(decrypted.get()); | 43 ASSERT_FALSE(decrypted.get()); |
| 51 } | 44 } |
| 52 | 45 |
| 53 TEST_F(NullDecrypterTest, ShortInput) { | 46 TEST_F(NullDecrypterTest, ShortInput) { |
| 54 unsigned char expected[] = { | 47 unsigned char expected[] = { |
| 55 // fnv hash (truncated) | 48 // fnv hash (truncated) |
| 56 0x46, 0x11, 0xea, 0x5f, | 49 0x46, 0x11, 0xea, 0x5f, 0xcf, 0x1d, 0x66, 0x5b, 0xba, 0xf0, 0xbc, |
| 57 0xcf, 0x1d, 0x66, 0x5b, | |
| 58 0xba, 0xf0, 0xbc, | |
| 59 }; | 50 }; |
| 60 const char* data = reinterpret_cast<const char*>(expected); | 51 const char* data = reinterpret_cast<const char*>(expected); |
| 61 size_t len = arraysize(expected); | 52 size_t len = arraysize(expected); |
| 62 NullDecrypter decrypter; | 53 NullDecrypter decrypter; |
| 63 scoped_ptr<QuicData> decrypted( | 54 scoped_ptr<QuicData> decrypted( |
| 64 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); | 55 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); |
| 65 ASSERT_FALSE(decrypted.get()); | 56 ASSERT_FALSE(decrypted.get()); |
| 66 } | 57 } |
| 67 | 58 |
| 68 } // namespace test | 59 } // namespace test |
| 69 } // namespace net | 60 } // namespace net |
| OLD | NEW |