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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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_encrypter.h" 5 #include "net/quic/crypto/null_encrypter.h"
6 #include "net/quic/quic_data_writer.h" 6 #include "net/quic/quic_data_writer.h"
7 #include "net/quic/quic_utils.h" 7 #include "net/quic/quic_utils.h"
8 8
9 using base::StringPiece; 9 using base::StringPiece;
10 using std::string; 10 using std::string;
11 11
12 namespace net { 12 namespace net {
13 13
14 const size_t kHashSizeShort = 12; // size of uint128 serialized short 14 const size_t kHashSizeShort = 12; // size of uint128 serialized short
15 15
16 NullEncrypter::NullEncrypter() {} 16 NullEncrypter::NullEncrypter() {
17 }
17 18
18 bool NullEncrypter::SetKey(StringPiece key) { return key.empty(); } 19 bool NullEncrypter::SetKey(StringPiece key) {
20 return key.empty();
21 }
19 22
20 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) { 23 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) {
21 return nonce_prefix.empty(); 24 return nonce_prefix.empty();
22 } 25 }
23 26
24 bool NullEncrypter::Encrypt( 27 bool NullEncrypter::Encrypt(StringPiece /*nonce*/,
25 StringPiece /*nonce*/, 28 StringPiece associated_data,
26 StringPiece associated_data, 29 StringPiece plaintext,
27 StringPiece plaintext, 30 unsigned char* output) {
28 unsigned char* output) {
29 string buffer = associated_data.as_string(); 31 string buffer = associated_data.as_string();
30 plaintext.AppendToString(&buffer); 32 plaintext.AppendToString(&buffer);
31 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length()); 33 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length());
32 QuicUtils::SerializeUint128Short(hash, output); 34 QuicUtils::SerializeUint128Short(hash, output);
33 memcpy(output + GetHashLength(), plaintext.data(), plaintext.size()); 35 memcpy(output + GetHashLength(), plaintext.data(), plaintext.size());
34 return true; 36 return true;
35 } 37 }
36 38
37 QuicData* NullEncrypter::EncryptPacket( 39 QuicData* NullEncrypter::EncryptPacket(
38 QuicPacketSequenceNumber /*sequence_number*/, 40 QuicPacketSequenceNumber /*sequence_number*/,
39 StringPiece associated_data, 41 StringPiece associated_data,
40 StringPiece plaintext) { 42 StringPiece plaintext) {
41 const size_t len = plaintext.size() + GetHashLength(); 43 const size_t len = plaintext.size() + GetHashLength();
42 uint8* buffer = new uint8[len]; 44 uint8* buffer = new uint8[len];
43 Encrypt(StringPiece(), associated_data, plaintext, buffer); 45 Encrypt(StringPiece(), associated_data, plaintext, buffer);
44 return new QuicData(reinterpret_cast<char*>(buffer), len, true); 46 return new QuicData(reinterpret_cast<char*>(buffer), len, true);
45 } 47 }
46 48
47 size_t NullEncrypter::GetKeySize() const { return 0; } 49 size_t NullEncrypter::GetKeySize() const {
50 return 0;
51 }
48 52
49 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; } 53 size_t NullEncrypter::GetNoncePrefixSize() const {
54 return 0;
55 }
50 56
51 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { 57 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
52 return ciphertext_size - GetHashLength(); 58 return ciphertext_size - GetHashLength();
53 } 59 }
54 60
55 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { 61 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const {
56 return plaintext_size + GetHashLength(); 62 return plaintext_size + GetHashLength();
57 } 63 }
58 64
59 StringPiece NullEncrypter::GetKey() const { return StringPiece(); } 65 StringPiece NullEncrypter::GetKey() const {
66 return StringPiece();
67 }
60 68
61 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); } 69 StringPiece NullEncrypter::GetNoncePrefix() const {
70 return StringPiece();
71 }
62 72
63 size_t NullEncrypter::GetHashLength() const { 73 size_t NullEncrypter::GetHashLength() const {
64 return kHashSizeShort; 74 return kHashSizeShort;
65 } 75 }
66 76
67 } // namespace net 77 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698