1 /*
2  * Copyright (c) 2011-2017 Contributors to the Eclipse Foundation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7  * which is available at https://www.apache.org/licenses/LICENSE-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10  */
11 
12 module hunt.net.OpenSSLEngineOptions;
13 
14 
15 /**
16  * Configures a {@link TCPSSLOptions} to use OpenSsl.
17  *
18  * @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
19  */
20 class OpenSSLEngineOptions {
21 
22     /**
23      * @return when OpenSSL is available
24      */
25     static bool isAvailable() {
26         // return OpenSsl.isAvailable();
27         // FIXME: Needing refactor or cleanup -@zxp at 7/31/2019, 9:14:58 AM        
28         // 
29         return false;
30     }
31 
32     /**
33      * @return when alpn support is available via OpenSSL engine
34      */
35     static bool isAlpnAvailable() {
36         // return OpenSsl.isAlpnSupported();
37         return false;
38     }
39 
40     /**
41      * Default value of whether connection cache is enabled in open SSL connection server context = true
42      */
43     enum bool DEFAULT_SESSION_CACHE_ENABLED = true;
44 
45     private bool connectionCacheEnabled;
46 
47     this() {
48         connectionCacheEnabled = DEFAULT_SESSION_CACHE_ENABLED;
49     }
50 
51     this(OpenSSLEngineOptions other) {
52         this.connectionCacheEnabled = other.isConnectionCacheEnabled();
53     }
54 
55     /**
56      * Set whether connection cache is enabled in open SSL connection server context
57      *
58      * @param connectionCacheEnabled true if connection cache is enabled
59      * @return a reference to this, so the API can be used fluently
60      */
61     OpenSSLEngineOptions setConnectionCacheEnabled(bool connectionCacheEnabled) {
62         this.connectionCacheEnabled = connectionCacheEnabled;
63         return this;
64     }
65 
66     /**
67      * Whether connection cache is enabled in open SSL connection server context
68      *
69      * @return true if connection cache is enabled
70      */
71     bool isConnectionCacheEnabled() {
72         return connectionCacheEnabled;
73     }
74 
75     override
76     bool opEquals(Object o) {
77         if (this is o) return true;
78 
79         OpenSSLEngineOptions that = cast(OpenSSLEngineOptions) o;
80         if(that is null)
81             return false;
82 
83         if (connectionCacheEnabled != that.connectionCacheEnabled) return false;
84 
85         return true;
86     }
87 
88     override
89     size_t toHash() @trusted nothrow {
90         return connectionCacheEnabled ? 1 : 0;
91     }
92 
93     OpenSSLEngineOptions clone() {
94         return new OpenSSLEngineOptions(this);
95     }
96 
97 }