OLD | NEW |
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/core/crypto/null_encrypter.h" | 5 #include "net/quic/core/crypto/null_encrypter.h" |
6 | 6 |
7 #include "net/quic/core/quic_data_writer.h" | 7 #include "net/quic/core/quic_data_writer.h" |
8 #include "net/quic/core/quic_utils.h" | 8 #include "net/quic/core/quic_utils.h" |
9 | 9 |
10 using base::StringPiece; | |
11 using std::string; | 10 using std::string; |
12 | 11 |
13 namespace net { | 12 namespace net { |
14 | 13 |
15 const size_t kHashSizeShort = 12; // size of uint128 serialized short | 14 const size_t kHashSizeShort = 12; // size of uint128 serialized short |
16 | 15 |
17 NullEncrypter::NullEncrypter(Perspective perspective) | 16 NullEncrypter::NullEncrypter(Perspective perspective) |
18 : perspective_(perspective) {} | 17 : perspective_(perspective) {} |
19 | 18 |
20 bool NullEncrypter::SetKey(StringPiece key) { | 19 bool NullEncrypter::SetKey(QuicStringPiece key) { |
21 return key.empty(); | 20 return key.empty(); |
22 } | 21 } |
23 | 22 |
24 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) { | 23 bool NullEncrypter::SetNoncePrefix(QuicStringPiece nonce_prefix) { |
25 return nonce_prefix.empty(); | 24 return nonce_prefix.empty(); |
26 } | 25 } |
27 | 26 |
28 bool NullEncrypter::EncryptPacket(QuicVersion version, | 27 bool NullEncrypter::EncryptPacket(QuicVersion version, |
29 QuicPacketNumber /*packet_number*/, | 28 QuicPacketNumber /*packet_number*/, |
30 StringPiece associated_data, | 29 QuicStringPiece associated_data, |
31 StringPiece plaintext, | 30 QuicStringPiece plaintext, |
32 char* output, | 31 char* output, |
33 size_t* output_length, | 32 size_t* output_length, |
34 size_t max_output_length) { | 33 size_t max_output_length) { |
35 const size_t len = plaintext.size() + GetHashLength(); | 34 const size_t len = plaintext.size() + GetHashLength(); |
36 if (max_output_length < len) { | 35 if (max_output_length < len) { |
37 return false; | 36 return false; |
38 } | 37 } |
39 uint128 hash; | 38 uint128 hash; |
40 if (version > QUIC_VERSION_36) { | 39 if (version > QUIC_VERSION_36) { |
41 if (perspective_ == Perspective::IS_SERVER) { | 40 if (perspective_ == Perspective::IS_SERVER) { |
(...skipping 24 matching lines...) Expand all Loading... |
66 } | 65 } |
67 | 66 |
68 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { | 67 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { |
69 return ciphertext_size - GetHashLength(); | 68 return ciphertext_size - GetHashLength(); |
70 } | 69 } |
71 | 70 |
72 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { | 71 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { |
73 return plaintext_size + GetHashLength(); | 72 return plaintext_size + GetHashLength(); |
74 } | 73 } |
75 | 74 |
76 StringPiece NullEncrypter::GetKey() const { | 75 QuicStringPiece NullEncrypter::GetKey() const { |
77 return StringPiece(); | 76 return QuicStringPiece(); |
78 } | 77 } |
79 | 78 |
80 StringPiece NullEncrypter::GetNoncePrefix() const { | 79 QuicStringPiece NullEncrypter::GetNoncePrefix() const { |
81 return StringPiece(); | 80 return QuicStringPiece(); |
82 } | 81 } |
83 | 82 |
84 size_t NullEncrypter::GetHashLength() const { | 83 size_t NullEncrypter::GetHashLength() const { |
85 return kHashSizeShort; | 84 return kHashSizeShort; |
86 } | 85 } |
87 | 86 |
88 } // namespace net | 87 } // namespace net |
OLD | NEW |