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 #ifndef NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ | 5 #ifndef NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ |
6 #define NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ | 6 #define NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 SSL_CONNECTION_VERSION_SHIFT = 20, | 28 SSL_CONNECTION_VERSION_SHIFT = 20, |
29 SSL_CONNECTION_VERSION_MASK = 7, | 29 SSL_CONNECTION_VERSION_MASK = 7, |
30 | 30 |
31 // 1 << 31 (the sign bit) is reserved so that the SSL connection status will | 31 // 1 << 31 (the sign bit) is reserved so that the SSL connection status will |
32 // never be negative. | 32 // never be negative. |
33 }; | 33 }; |
34 | 34 |
35 // NOTE: the SSL version enum constants must be between 0 and | 35 // NOTE: the SSL version enum constants must be between 0 and |
36 // SSL_CONNECTION_VERSION_MASK, inclusive. These values are persisted to disk | 36 // SSL_CONNECTION_VERSION_MASK, inclusive. These values are persisted to disk |
37 // and used in UMA, so they must remain stable. | 37 // and used in UMA, so they must remain stable. |
38 enum { | 38 enum SSLVersion { |
39 SSL_CONNECTION_VERSION_UNKNOWN = 0, // Unknown SSL version. | 39 SSL_CONNECTION_VERSION_UNKNOWN = 0, // Unknown SSL version. |
40 SSL_CONNECTION_VERSION_SSL2 = 1, | 40 SSL_CONNECTION_VERSION_SSL2 = 1, |
41 SSL_CONNECTION_VERSION_SSL3 = 2, | 41 SSL_CONNECTION_VERSION_SSL3 = 2, |
42 SSL_CONNECTION_VERSION_TLS1 = 3, | 42 SSL_CONNECTION_VERSION_TLS1 = 3, |
43 SSL_CONNECTION_VERSION_TLS1_1 = 4, | 43 SSL_CONNECTION_VERSION_TLS1_1 = 4, |
44 SSL_CONNECTION_VERSION_TLS1_2 = 5, | 44 SSL_CONNECTION_VERSION_TLS1_2 = 5, |
45 SSL_CONNECTION_VERSION_TLS1_3 = 6, | 45 SSL_CONNECTION_VERSION_TLS1_3 = 6, |
46 SSL_CONNECTION_VERSION_QUIC = 7, | 46 SSL_CONNECTION_VERSION_QUIC = 7, |
47 SSL_CONNECTION_VERSION_MAX, | 47 SSL_CONNECTION_VERSION_MAX, |
48 }; | 48 }; |
49 static_assert(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK, | 49 static_assert(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK, |
50 "SSL_CONNECTION_VERSION_MASK too small"); | 50 "SSL_CONNECTION_VERSION_MASK too small"); |
51 | 51 |
52 inline uint16_t SSLConnectionStatusToCipherSuite(int connection_status) { | 52 inline uint16_t SSLConnectionStatusToCipherSuite(int connection_status) { |
53 return static_cast<uint16_t>(connection_status); | 53 return static_cast<uint16_t>(connection_status); |
54 } | 54 } |
55 | 55 |
56 inline int SSLConnectionStatusToVersion(int connection_status) { | 56 inline SSLVersion SSLConnectionStatusToVersion(int connection_status) { |
57 return (connection_status >> SSL_CONNECTION_VERSION_SHIFT) & | 57 return static_cast<SSLVersion>( |
58 SSL_CONNECTION_VERSION_MASK; | 58 (connection_status >> SSL_CONNECTION_VERSION_SHIFT) & |
| 59 SSL_CONNECTION_VERSION_MASK); |
59 } | 60 } |
60 | 61 |
61 inline void SSLConnectionStatusSetCipherSuite(uint16_t cipher_suite, | 62 inline void SSLConnectionStatusSetCipherSuite(uint16_t cipher_suite, |
62 int* connection_status) { | 63 int* connection_status) { |
63 // Clear out the old ciphersuite. | 64 // Clear out the old ciphersuite. |
64 *connection_status &= ~SSL_CONNECTION_CIPHERSUITE_MASK; | 65 *connection_status &= ~SSL_CONNECTION_CIPHERSUITE_MASK; |
65 // Set the new ciphersuite. | 66 // Set the new ciphersuite. |
66 *connection_status |= cipher_suite; | 67 *connection_status |= cipher_suite; |
67 } | 68 } |
68 | 69 |
69 inline void SSLConnectionStatusSetVersion(int version, int* connection_status) { | 70 inline void SSLConnectionStatusSetVersion(int version, int* connection_status) { |
70 DCHECK_GT(version, 0); | 71 DCHECK_GT(version, 0); |
71 DCHECK_LT(version, SSL_CONNECTION_VERSION_MAX); | 72 DCHECK_LT(version, SSL_CONNECTION_VERSION_MAX); |
72 | 73 |
73 // Clear out the old version. | 74 // Clear out the old version. |
74 *connection_status &= | 75 *connection_status &= |
75 ~(SSL_CONNECTION_VERSION_MASK << SSL_CONNECTION_VERSION_SHIFT); | 76 ~(SSL_CONNECTION_VERSION_MASK << SSL_CONNECTION_VERSION_SHIFT); |
76 // Set the new version. | 77 // Set the new version. |
77 *connection_status |= | 78 *connection_status |= |
78 ((version & SSL_CONNECTION_VERSION_MASK) << SSL_CONNECTION_VERSION_SHIFT); | 79 ((version & SSL_CONNECTION_VERSION_MASK) << SSL_CONNECTION_VERSION_SHIFT); |
79 } | 80 } |
80 | 81 |
81 } // namespace net | 82 } // namespace net |
82 | 83 |
83 #endif // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ | 84 #endif // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ |
OLD | NEW |