Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: net/quic/crypto/null_decrypter_test.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/crypto/null_decrypter.cc ('k') | net/quic/crypto/null_encrypter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/crypto/null_decrypter.h" 5 #include "net/quic/crypto/null_decrypter.h"
6 #include "net/quic/test_tools/quic_test_utils.h" 6 #include "net/quic/test_tools/quic_test_utils.h"
7 7
8 using base::StringPiece; 8 using base::StringPiece;
9 9
10 namespace net { 10 namespace net {
11 namespace test { 11 namespace test {
12 12
13 class NullDecrypterTest : public ::testing::TestWithParam<bool> { 13 class NullDecrypterTest : public ::testing::TestWithParam<bool> {
14 }; 14 };
15 15
16 TEST_F(NullDecrypterTest, Decrypt) { 16 TEST_F(NullDecrypterTest, Decrypt) {
17 unsigned char expected[] = { 17 unsigned char expected[] = {
18 // fnv hash 18 // fnv hash
19 0xa0, 0x6f, 0x44, 0x8a, 19 0xa0, 0x6f, 0x44, 0x8a,
20 0x44, 0xf8, 0x18, 0x3b, 20 0x44, 0xf8, 0x18, 0x3b,
21 0x47, 0x91, 0xb2, 0x13, 21 0x47, 0x91, 0xb2, 0x13,
22 // payload 22 // payload
23 'g', 'o', 'o', 'd', 23 'g', 'o', 'o', 'd',
24 'b', 'y', 'e', '!', 24 'b', 'y', 'e', '!',
25 }; 25 };
26 const char* data = reinterpret_cast<const char*>(expected); 26 const char* data = reinterpret_cast<const char*>(expected);
27 size_t len = arraysize(expected); 27 size_t len = arraysize(expected);
28 NullDecrypter decrypter; 28 NullDecrypter decrypter;
29 scoped_ptr<QuicData> decrypted( 29 char buffer[256];
30 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); 30 size_t length = 0;
31 ASSERT_TRUE(decrypted.get()); 31 ASSERT_TRUE(decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len),
32 EXPECT_EQ("goodbye!", decrypted->AsStringPiece()); 32 buffer, &length, 256));
33 EXPECT_LT(0u, length);
34 EXPECT_EQ("goodbye!", StringPiece(buffer, length));
33 } 35 }
34 36
35 TEST_F(NullDecrypterTest, BadHash) { 37 TEST_F(NullDecrypterTest, BadHash) {
36 unsigned char expected[] = { 38 unsigned char expected[] = {
37 // fnv hash 39 // fnv hash
38 0x46, 0x11, 0xea, 0x5f, 40 0x46, 0x11, 0xea, 0x5f,
39 0xcf, 0x1d, 0x66, 0x5b, 41 0xcf, 0x1d, 0x66, 0x5b,
40 0xba, 0xf0, 0xbc, 0xfd, 42 0xba, 0xf0, 0xbc, 0xfd,
41 // payload 43 // payload
42 'g', 'o', 'o', 'd', 44 'g', 'o', 'o', 'd',
43 'b', 'y', 'e', '!', 45 'b', 'y', 'e', '!',
44 }; 46 };
45 const char* data = reinterpret_cast<const char*>(expected); 47 const char* data = reinterpret_cast<const char*>(expected);
46 size_t len = arraysize(expected); 48 size_t len = arraysize(expected);
47 NullDecrypter decrypter; 49 NullDecrypter decrypter;
48 scoped_ptr<QuicData> decrypted( 50 char buffer[256];
49 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); 51 size_t length = 0;
50 ASSERT_FALSE(decrypted.get()); 52 ASSERT_FALSE(decrypter.DecryptPacket(
53 0, "hello world!", StringPiece(data, len), buffer, &length, 256));
51 } 54 }
52 55
53 TEST_F(NullDecrypterTest, ShortInput) { 56 TEST_F(NullDecrypterTest, ShortInput) {
54 unsigned char expected[] = { 57 unsigned char expected[] = {
55 // fnv hash (truncated) 58 // fnv hash (truncated)
56 0x46, 0x11, 0xea, 0x5f, 59 0x46, 0x11, 0xea, 0x5f,
57 0xcf, 0x1d, 0x66, 0x5b, 60 0xcf, 0x1d, 0x66, 0x5b,
58 0xba, 0xf0, 0xbc, 61 0xba, 0xf0, 0xbc,
59 }; 62 };
60 const char* data = reinterpret_cast<const char*>(expected); 63 const char* data = reinterpret_cast<const char*>(expected);
61 size_t len = arraysize(expected); 64 size_t len = arraysize(expected);
62 NullDecrypter decrypter; 65 NullDecrypter decrypter;
63 scoped_ptr<QuicData> decrypted( 66 char buffer[256];
64 decrypter.DecryptPacket(0, "hello world!", StringPiece(data, len))); 67 size_t length = 0;
65 ASSERT_FALSE(decrypted.get()); 68 ASSERT_FALSE(decrypter.DecryptPacket(
69 0, "hello world!", StringPiece(data, len), buffer, &length, 256));
66 } 70 }
67 71
68 } // namespace test 72 } // namespace test
69 } // namespace net 73 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/null_decrypter.cc ('k') | net/quic/crypto/null_encrypter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698