Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / ssl / ssl_connection_status_flags.h
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
3 // found in the LICENSE file.
4
5 #ifndef NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_
6 #define NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_
7
8 namespace net {
9
10 // Status flags for SSLInfo::connection_status.
11 enum {
12   // The lower 16 bits are reserved for the TLS ciphersuite id.
13   SSL_CONNECTION_CIPHERSUITE_SHIFT = 0,
14   SSL_CONNECTION_CIPHERSUITE_MASK = 0xffff,
15
16   // The next two bits are reserved for the compression used.
17   SSL_CONNECTION_COMPRESSION_SHIFT = 16,
18   SSL_CONNECTION_COMPRESSION_MASK = 3,
19
20   // We fell back to an older protocol version for this connection.
21   SSL_CONNECTION_VERSION_FALLBACK = 1 << 18,
22
23   // The server doesn't support the renegotiation_info extension. If this bit
24   // is not set then either the extension isn't supported, or we don't have any
25   // knowledge either way. (The latter case will occur when we use an SSL
26   // library that doesn't report it, like SChannel.)
27   SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION = 1 << 19,
28
29   // The next three bits are reserved for the SSL version.
30   SSL_CONNECTION_VERSION_SHIFT = 20,
31   SSL_CONNECTION_VERSION_MASK = 7,
32
33   // 1 << 31 (the sign bit) is reserved so that the SSL connection status will
34   // never be negative.
35 };
36
37 // NOTE: the SSL version enum constants must be between 0 and
38 // SSL_CONNECTION_VERSION_MASK, inclusive.
39 enum {
40   SSL_CONNECTION_VERSION_UNKNOWN = 0,  // Unknown SSL version.
41   SSL_CONNECTION_VERSION_SSL2 = 1,
42   SSL_CONNECTION_VERSION_SSL3 = 2,
43   SSL_CONNECTION_VERSION_TLS1 = 3,
44   SSL_CONNECTION_VERSION_TLS1_1 = 4,
45   SSL_CONNECTION_VERSION_TLS1_2 = 5,
46   // Reserve 6 for TLS 1.3.
47   SSL_CONNECTION_VERSION_QUIC = 7,
48   SSL_CONNECTION_VERSION_MAX,
49 };
50 COMPILE_ASSERT(SSL_CONNECTION_VERSION_MAX - 1 <= SSL_CONNECTION_VERSION_MASK,
51                SSL_CONNECTION_VERSION_MASK_too_small);
52
53 inline int SSLConnectionStatusToCipherSuite(int connection_status) {
54   return (connection_status >> SSL_CONNECTION_CIPHERSUITE_SHIFT) &
55          SSL_CONNECTION_CIPHERSUITE_MASK;
56 }
57
58 inline int SSLConnectionStatusToVersion(int connection_status) {
59   return (connection_status >> SSL_CONNECTION_VERSION_SHIFT) &
60          SSL_CONNECTION_VERSION_MASK;
61 }
62
63 }  // namespace net
64
65 #endif  // NET_SSL_SSL_CONNECTION_STATUS_FLAGS_H_