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.
5 #include "net/quic/crypto/null_decrypter.h"
6 #include "net/quic/test_tools/quic_test_utils.h"
8 using base::StringPiece
;
13 class NullDecrypterTest
: public ::testing::TestWithParam
<bool> {
16 TEST_F(NullDecrypterTest
, Decrypt
) {
17 unsigned char expected
[] = {
19 0xa0, 0x6f, 0x44, 0x8a,
20 0x44, 0xf8, 0x18, 0x3b,
21 0x47, 0x91, 0xb2, 0x13,
26 const char* data
= reinterpret_cast<const char*>(expected
);
27 size_t len
= arraysize(expected
);
28 NullDecrypter decrypter
;
29 scoped_ptr
<QuicData
> decrypted(
30 decrypter
.DecryptPacket(0, "hello world!", StringPiece(data
, len
)));
31 ASSERT_TRUE(decrypted
.get());
32 EXPECT_EQ("goodbye!", decrypted
->AsStringPiece());
35 TEST_F(NullDecrypterTest
, BadHash
) {
36 unsigned char expected
[] = {
38 0x46, 0x11, 0xea, 0x5f,
39 0xcf, 0x1d, 0x66, 0x5b,
40 0xba, 0xf0, 0xbc, 0xfd,
45 const char* data
= reinterpret_cast<const char*>(expected
);
46 size_t len
= arraysize(expected
);
47 NullDecrypter decrypter
;
48 scoped_ptr
<QuicData
> decrypted(
49 decrypter
.DecryptPacket(0, "hello world!", StringPiece(data
, len
)));
50 ASSERT_FALSE(decrypted
.get());
53 TEST_F(NullDecrypterTest
, ShortInput
) {
54 unsigned char expected
[] = {
55 // fnv hash (truncated)
56 0x46, 0x11, 0xea, 0x5f,
57 0xcf, 0x1d, 0x66, 0x5b,
60 const char* data
= reinterpret_cast<const char*>(expected
);
61 size_t len
= arraysize(expected
);
62 NullDecrypter decrypter
;
63 scoped_ptr
<QuicData
> decrypted(
64 decrypter
.DecryptPacket(0, "hello world!", StringPiece(data
, len
)));
65 ASSERT_FALSE(decrypted
.get());