| 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 TEST(NullDecrypterTest, Decrypt) { | 13 TEST(NullDecrypterTest, Decrypt) { |
| 14 unsigned char expected[] = { | 14 unsigned char expected[] = { |
| 15 // fnv hash | 15 // fnv hash |
| 16 0x47, 0x11, 0xea, 0x5f, | 16 0x47, 0x11, 0xea, 0x5f, |
| 17 0xcf, 0x1d, 0x66, 0x5b, | 17 0xcf, 0x1d, 0x66, 0x5b, |
| 18 0xba, 0xf0, 0xbc, 0xfd, | 18 0xba, 0xf0, 0xbc, 0xfd, |
| 19 0x88, 0x79, 0xca, 0x37, | 19 0x88, 0x79, 0xca, 0x37, |
| 20 // payload | 20 // payload |
| 21 'g', 'o', 'o', 'd', | 21 'g', 'o', 'o', 'd', |
| 22 'b', 'y', 'e', '!', | 22 'b', 'y', 'e', '!', |
| 23 }; | 23 }; |
| 24 NullDecrypter decrypter; | 24 NullDecrypter decrypter; |
| 25 scoped_ptr<QuicData> decrypted( | 25 scoped_ptr<QuicData> decrypted( |
| 26 decrypter.Decrypt("hello world!", | 26 decrypter.Decrypt(0, "hello world!", |
| 27 StringPiece(reinterpret_cast<const char*>(expected), | 27 StringPiece(reinterpret_cast<const char*>(expected), |
| 28 arraysize(expected)))); | 28 arraysize(expected)))); |
| 29 ASSERT_TRUE(decrypted.get()); | 29 ASSERT_TRUE(decrypted.get()); |
| 30 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); | 30 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 TEST(NullDecrypterTest, BadHash) { | 33 TEST(NullDecrypterTest, BadHash) { |
| 34 unsigned char expected[] = { | 34 unsigned char expected[] = { |
| 35 // fnv hash | 35 // fnv hash |
| 36 0x46, 0x11, 0xea, 0x5f, | 36 0x46, 0x11, 0xea, 0x5f, |
| 37 0xcf, 0x1d, 0x66, 0x5b, | 37 0xcf, 0x1d, 0x66, 0x5b, |
| 38 0xba, 0xf0, 0xbc, 0xfd, | 38 0xba, 0xf0, 0xbc, 0xfd, |
| 39 0x88, 0x79, 0xca, 0x37, | 39 0x88, 0x79, 0xca, 0x37, |
| 40 // payload | 40 // payload |
| 41 'g', 'o', 'o', 'd', | 41 'g', 'o', 'o', 'd', |
| 42 'b', 'y', 'e', '!', | 42 'b', 'y', 'e', '!', |
| 43 }; | 43 }; |
| 44 NullDecrypter decrypter; | 44 NullDecrypter decrypter; |
| 45 scoped_ptr<QuicData> decrypted( | 45 scoped_ptr<QuicData> decrypted( |
| 46 decrypter.Decrypt("hello world!", | 46 decrypter.Decrypt(0, "hello world!", |
| 47 StringPiece(reinterpret_cast<const char*>(expected), | 47 StringPiece(reinterpret_cast<const char*>(expected), |
| 48 arraysize(expected)))); | 48 arraysize(expected)))); |
| 49 ASSERT_FALSE(decrypted.get()); | 49 ASSERT_FALSE(decrypted.get()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST(NullDecrypterTest, ShortInput) { | 52 TEST(NullDecrypterTest, ShortInput) { |
| 53 unsigned char expected[] = { | 53 unsigned char expected[] = { |
| 54 // fnv hash (truncated) | 54 // fnv hash (truncated) |
| 55 0x46, 0x11, 0xea, 0x5f, | 55 0x46, 0x11, 0xea, 0x5f, |
| 56 0xcf, 0x1d, 0x66, 0x5b, | 56 0xcf, 0x1d, 0x66, 0x5b, |
| 57 0xba, 0xf0, 0xbc, 0xfd, | 57 0xba, 0xf0, 0xbc, 0xfd, |
| 58 0x88, 0x79, 0xca, | 58 0x88, 0x79, 0xca, |
| 59 }; | 59 }; |
| 60 NullDecrypter decrypter; | 60 NullDecrypter decrypter; |
| 61 scoped_ptr<QuicData> decrypted( | 61 scoped_ptr<QuicData> decrypted( |
| 62 decrypter.Decrypt("hello world!", | 62 decrypter.Decrypt(0, "hello world!", |
| 63 StringPiece(reinterpret_cast<const char*>(expected), | 63 StringPiece(reinterpret_cast<const char*>(expected), |
| 64 arraysize(expected)))); | 64 arraysize(expected)))); |
| 65 ASSERT_FALSE(decrypted.get()); | 65 ASSERT_FALSE(decrypted.get()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace test | 68 } // namespace test |
| 69 } // namespace net | 69 } // namespace net |
| OLD | NEW |