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