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