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_encrypter.h"
6 #include "net/quic/test_tools/quic_test_utils.h"
8 using base::StringPiece;
13 class NullEncrypterTest : public ::testing::TestWithParam<bool> {
16 INSTANTIATE_TEST_CASE_P(HashLength, NullEncrypterTest,
17 ::testing::Values(false, true));
19 TEST_P(NullEncrypterTest, Encrypt) {
20 unsigned char expected[] = {
22 0xa0, 0x6f, 0x44, 0x8a,
23 0x44, 0xf8, 0x18, 0x3b,
24 0x47, 0x91, 0xb2, 0x13,
25 0x6b, 0x09, 0xbb, 0xae,
30 unsigned char expected_short[] = {
32 0xa0, 0x6f, 0x44, 0x8a,
33 0x44, 0xf8, 0x18, 0x3b,
34 0x47, 0x91, 0xb2, 0x13,
39 NullEncrypter encrypter(GetParam());
40 scoped_ptr<QuicData> encrypted(
41 encrypter.EncryptPacket(0, "hello world!", "goodbye!"));
42 ASSERT_TRUE(encrypted.get());
44 test::CompareCharArraysWithHexError(
45 "encrypted data", encrypted->data(), encrypted->length(),
46 reinterpret_cast<const char*>(expected_short),
47 arraysize(expected_short));
49 test::CompareCharArraysWithHexError(
50 "encrypted data", encrypted->data(), encrypted->length(),
51 reinterpret_cast<const char*>(expected), arraysize(expected));
55 TEST_P(NullEncrypterTest, GetMaxPlaintextSize) {
56 NullEncrypter encrypter(GetParam());
58 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1012));
59 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(112));
60 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(22));
62 EXPECT_EQ(1000u, encrypter.GetMaxPlaintextSize(1016));
63 EXPECT_EQ(100u, encrypter.GetMaxPlaintextSize(116));
64 EXPECT_EQ(10u, encrypter.GetMaxPlaintextSize(26));
68 TEST_P(NullEncrypterTest, GetCiphertextSize) {
69 NullEncrypter encrypter(GetParam());
71 EXPECT_EQ(1012u, encrypter.GetCiphertextSize(1000));
72 EXPECT_EQ(112u, encrypter.GetCiphertextSize(100));
73 EXPECT_EQ(22u, encrypter.GetCiphertextSize(10));
75 EXPECT_EQ(1016u, encrypter.GetCiphertextSize(1000));
76 EXPECT_EQ(116u, encrypter.GetCiphertextSize(100));
77 EXPECT_EQ(26u, encrypter.GetCiphertextSize(10));