| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // Some helpers for quic crypto | 5 // Some helpers for quic crypto |
| 6 | 6 |
| 7 #ifndef NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 7 #ifndef NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
| 8 #define NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 8 #define NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | |
| 12 | 11 |
| 13 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
| 13 #include "net/quic/crypto/crypto_protocol.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 class QuicClock; | 17 class QuicClock; |
| 18 class QuicRandom; | 18 class QuicRandom; |
| 19 struct CryptoHandshakeMessage; | |
| 20 struct QuicCryptoConfig; | |
| 21 struct QuicCryptoNegotiatedParams; | |
| 22 | 19 |
| 23 class NET_EXPORT_PRIVATE CryptoUtils { | 20 class NET_EXPORT_PRIVATE CryptoUtils { |
| 24 public: | 21 public: |
| 25 // Encodes a single value as a string for CryptoTagValueMap. | 22 // FindMutualTag sets |out_result| to the first tag in |preference| that is |
| 26 template <class T> | 23 // also in |supported| and returns true. If there is no intersection between |
| 27 static std::string EncodeSingleValue(const T& value) { | 24 // |preference| and |supported| it returns false. |
| 28 return std::string(reinterpret_cast<const char*>(&value), sizeof(value)); | 25 static bool FindMutualTag(const CryptoTagVector& preference, |
| 29 } | 26 const CryptoTagVector& supported, |
| 30 | 27 CryptoTag* out_result); |
| 31 // Encodes a vector value as a string for CryptoTagValueMap. | |
| 32 template <class T> | |
| 33 static std::string EncodeVectorValue(const std::vector<T>& value) { | |
| 34 return std::string(reinterpret_cast<const char*>(&value[0]), | |
| 35 value.size() * sizeof(value[0])); | |
| 36 } | |
| 37 | 28 |
| 38 // Generates the connection nonce. | 29 // Generates the connection nonce. |
| 39 static void GenerateNonce(const QuicClock* clock, | 30 static void GenerateNonce(const QuicClock* clock, |
| 40 QuicRandom* random_generator, | 31 QuicRandom* random_generator, |
| 41 std::string* nonce); | 32 std::string* nonce); |
| 42 | |
| 43 static void FillClientHelloMessage(const QuicCryptoConfig& client_config, | |
| 44 const std::string& nonce, | |
| 45 const std::string& server_hostname, | |
| 46 CryptoHandshakeMessage* message); | |
| 47 | |
| 48 static void FillServerHelloMessage( | |
| 49 const QuicCryptoNegotiatedParams& negotiated_params, | |
| 50 const std::string& nonce, | |
| 51 CryptoHandshakeMessage* message); | |
| 52 }; | 33 }; |
| 53 | 34 |
| 54 } // namespace net | 35 } // namespace net |
| 55 | 36 |
| 56 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ | 37 #endif // NET_QUIC_CRYPTO_CRYPTO_UTILS_H_ |
| OLD | NEW |