OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/quic/crypto/null_decrypter.h" |
| 6 #include "net/quic/test_tools/quic_test_utils.h" |
| 7 |
| 8 using base::StringPiece; |
| 9 |
| 10 namespace net { |
| 11 |
| 12 namespace test { |
| 13 |
| 14 TEST(NullDecrypterTest, Decrypt) { |
| 15 unsigned char expected[] = { |
| 16 // fnv hash |
| 17 0x07, 0x2d, 0x42, 0xf0, |
| 18 0xbe, 0x69, 0x12, 0x3d, |
| 19 0x20, 0x80, 0x5f, 0x9a, |
| 20 0x84, 0x9d, 0xd6, 0x0a, |
| 21 /* TODO(rch): replace this when uint128 multiplication is implemented. |
| 22 0x47, 0x11, 0xea, 0x5f, |
| 23 0xcf, 0x1d, 0x66, 0x5b, |
| 24 0xba, 0xf0, 0xbc, 0xfd, |
| 25 0x88, 0x79, 0xca, 0x37, |
| 26 */ |
| 27 // payload |
| 28 'g', 'o', 'o', 'd', |
| 29 'b', 'y', 'e', '!', |
| 30 }; |
| 31 NullDecrypter decrypter; |
| 32 scoped_ptr<QuicData> decrypted( |
| 33 decrypter.Decrypt("hello world!", |
| 34 StringPiece(reinterpret_cast<const char*>(expected), |
| 35 arraysize(expected)))); |
| 36 ASSERT_TRUE(decrypted.get()); |
| 37 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); |
| 38 } |
| 39 |
| 40 TEST(NullDecrypterTest, BadHash) { |
| 41 unsigned char expected[] = { |
| 42 // fnv hash |
| 43 0x46, 0x11, 0xea, 0x5f, |
| 44 0xcf, 0x1d, 0x66, 0x5b, |
| 45 0xba, 0xf0, 0xbc, 0xfd, |
| 46 0x88, 0x79, 0xca, 0x37, |
| 47 // payload |
| 48 'g', 'o', 'o', 'd', |
| 49 'b', 'y', 'e', '!', |
| 50 }; |
| 51 NullDecrypter decrypter; |
| 52 scoped_ptr<QuicData> decrypted( |
| 53 decrypter.Decrypt("hello world!", |
| 54 StringPiece(reinterpret_cast<const char*>(expected), |
| 55 arraysize(expected)))); |
| 56 ASSERT_FALSE(decrypted.get()); |
| 57 } |
| 58 |
| 59 TEST(NullDecrypterTest, ShortInput) { |
| 60 unsigned char expected[] = { |
| 61 // fnv hash (truncated) |
| 62 0x46, 0x11, 0xea, 0x5f, |
| 63 0xcf, 0x1d, 0x66, 0x5b, |
| 64 0xba, 0xf0, 0xbc, 0xfd, |
| 65 0x88, 0x79, 0xca, |
| 66 }; |
| 67 NullDecrypter decrypter; |
| 68 scoped_ptr<QuicData> decrypted( |
| 69 decrypter.Decrypt("hello world!", |
| 70 StringPiece(reinterpret_cast<const char*>(expected), |
| 71 arraysize(expected)))); |
| 72 ASSERT_FALSE(decrypted.get()); |
| 73 } |
| 74 |
| 75 } // namespace test |
| 76 |
| 77 } // namespace net |
OLD | NEW |