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 "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 // Status flags for SSLInfo::connection_status. | 13 // Status flags for SSLInfo::connection_status. |
14 enum { | 14 enum { |
15 // The lower 16 bits are reserved for the TLS ciphersuite id. | 15 // The lower 16 bits are reserved for the TLS ciphersuite id. |
16 SSL_CONNECTION_CIPHERSUITE_SHIFT = 0, | |
17 SSL_CONNECTION_CIPHERSUITE_MASK = 0xffff, | 16 SSL_CONNECTION_CIPHERSUITE_MASK = 0xffff, |
18 | 17 |
19 // The next two bits are reserved for the compression used. | 18 // The next two bits are reserved for the compression used. |
20 SSL_CONNECTION_COMPRESSION_SHIFT = 16, | 19 SSL_CONNECTION_COMPRESSION_SHIFT = 16, |
21 SSL_CONNECTION_COMPRESSION_MASK = 3, | 20 SSL_CONNECTION_COMPRESSION_MASK = 3, |
22 | 21 |
23 // We fell back to an older protocol version for this connection. | 22 // We fell back to an older protocol version for this connection. |
24 SSL_CONNECTION_VERSION_FALLBACK = 1 << 18, | 23 SSL_CONNECTION_VERSION_FALLBACK = 1 << 18, |
25 | 24 |
26 // The server doesn't support the renegotiation_info extension. If this bit | 25 // The server doesn't support the renegotiation_info extension. If this bit |
(...skipping 19 matching lines...) Expand all Loading... |
46 SSL_CONNECTION_VERSION_TLS1 = 3, | 45 SSL_CONNECTION_VERSION_TLS1 = 3, |
47 SSL_CONNECTION_VERSION_TLS1_1 = 4, | 46 SSL_CONNECTION_VERSION_TLS1_1 = 4, |
48 SSL_CONNECTION_VERSION_TLS1_2 = 5, | 47 SSL_CONNECTION_VERSION_TLS1_2 = 5, |
49 // Reserve 6 for TLS 1.3. | 48 // Reserve 6 for TLS 1.3. |
50 SSL_CONNECTION_VERSION_QUIC = 7, | 49 SSL_CONNECTION_VERSION_QUIC = 7, |
51 SSL_CONNECTION_VERSION_MAX, | 50 SSL_CONNECTION_VERSION_MAX, |
52 }; | 51 }; |
53 COMPILE_ASSERT(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK, | 52 COMPILE_ASSERT(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK, |
54 SSL_CONNECTION_VERSION_MASK_too_small); | 53 SSL_CONNECTION_VERSION_MASK_too_small); |
55 | 54 |
56 inline int SSLConnectionStatusToCipherSuite(int connection_status) { | 55 inline uint16 SSLConnectionStatusToCipherSuite(int connection_status) { |
57 return (connection_status >> SSL_CONNECTION_CIPHERSUITE_SHIFT) & | 56 return static_cast<uint16>(connection_status); |
58 SSL_CONNECTION_CIPHERSUITE_MASK; | |
59 } | 57 } |
60 | 58 |
61 inline int SSLConnectionStatusToVersion(int connection_status) { | 59 inline int SSLConnectionStatusToVersion(int connection_status) { |
62 return (connection_status >> SSL_CONNECTION_VERSION_SHIFT) & | 60 return (connection_status >> SSL_CONNECTION_VERSION_SHIFT) & |
63 SSL_CONNECTION_VERSION_MASK; | 61 SSL_CONNECTION_VERSION_MASK; |
64 } | 62 } |
65 | 63 |
66 inline void SSLConnectionStatusSetCipherSuite(int cipher_suite, | 64 inline void SSLConnectionStatusSetCipherSuite(uint16 cipher_suite, |
67 int* connection_status) { | 65 int* connection_status) { |
68 // Clear out the old ciphersuite. | 66 // Clear out the old ciphersuite. |
69 *connection_status &= | 67 *connection_status &= ~SSL_CONNECTION_CIPHERSUITE_MASK; |
70 ~(SSL_CONNECTION_CIPHERSUITE_MASK << SSL_CONNECTION_CIPHERSUITE_SHIFT); | |
71 // Set the new ciphersuite. | 68 // Set the new ciphersuite. |
72 *connection_status |= ((cipher_suite & SSL_CONNECTION_CIPHERSUITE_MASK) | 69 *connection_status |= cipher_suite; |
73 << SSL_CONNECTION_CIPHERSUITE_SHIFT); | |
74 } | 70 } |
75 | 71 |
76 inline void SSLConnectionStatusSetVersion(int version, int* connection_status) { | 72 inline void SSLConnectionStatusSetVersion(int version, int* connection_status) { |
77 DCHECK_GT(version, 0); | 73 DCHECK_GT(version, 0); |
78 DCHECK_LT(version, SSL_CONNECTION_VERSION_MAX); | 74 DCHECK_LT(version, SSL_CONNECTION_VERSION_MAX); |
79 | 75 |
80 // Clear out the old version. | 76 // Clear out the old version. |
81 *connection_status &= | 77 *connection_status &= |
82 ~(SSL_CONNECTION_VERSION_MASK << SSL_CONNECTION_VERSION_SHIFT); | 78 ~(SSL_CONNECTION_VERSION_MASK << SSL_CONNECTION_VERSION_SHIFT); |
83 // Set the new version. | 79 // Set the new version. |
84 *connection_status |= | 80 *connection_status |= |
85 ((version & SSL_CONNECTION_VERSION_MASK) << SSL_CONNECTION_VERSION_SHIFT); | 81 ((version & SSL_CONNECTION_VERSION_MASK) << SSL_CONNECTION_VERSION_SHIFT); |
86 } | 82 } |
87 | 83 |
88 } // namespace net | 84 } // namespace net |
89 | 85 |
90 #endif // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ | 86 #endif // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_ |
OLD | NEW |