1
+ /**
2
+ * Module to deal with the library version being used
3
+ *
4
+ * This library provide bindings for a wide range of OpenSSL versions,
5
+ * ranging from v0.9.x to v3.0.x. Some versions are not compatible with
6
+ * one another, either due to different ABI or different behavior,
7
+ * for example OpenSSL 1.0 requires initialization but later versions do not.
8
+ *
9
+ * While things tend to mostly work or error out while linking when the version
10
+ * the bindings assume and the actually C library version are too different,
11
+ * we prefer to try detecting the currently used version, and allow users
12
+ * to specify the version explicitly, before falling back to the latest bindings
13
+ */
1
14
module deimos.openssl.opensslv ;
2
15
3
16
import deimos.openssl._d_util;
4
17
18
+ version (DeimosOpenSSL_1_0_0)
19
+ {
20
+ // https://www.openssl.org/news/changelog.html#openssl-100
21
+ // OpenSSL 1.0.0t was released 2015-12-03
22
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.0.0t" ;
23
+ }
24
+ else version (DeimosOpenSSL_1_0_1)
25
+ {
26
+ // https://www.openssl.org/news/changelog.html#openssl-101
27
+ // OpenSSL 1.0.1u was released 2016-09-22
28
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.0.1u" ;
29
+ }
30
+ else version (DeimosOpenSSL_1_0_2)
31
+ {
32
+ // https://www.openssl.org/news/changelog.html#openssl-102
33
+ // OpenSSL 1.0.2t was released 2019-09-10
34
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.0.2t" ;
35
+ }
36
+ else version (DeimosOpenSSL_1_1_0)
37
+ {
38
+ // https://www.openssl.org/news/changelog.html#openssl-110
39
+ // OpenSSL 1.1.0l was released 2019-09-10
40
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.1.0l" ;
41
+ }
42
+ else version (DeimosOpenSSL_1_1_1)
43
+ {
44
+ // https://www.openssl.org/news/changelog.html#openssl-111
45
+ // OpenSSL 1.1.1m was released 2021-12-14
46
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.1.1m" ;
47
+ }
48
+ else version (DeimosOpenSSL_3_0)
49
+ {
50
+ // https://www.openssl.org/news/changelog.html#openssl-30
51
+ // OpenSSL 3.0.3 was released 2022-05-03
52
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 3.0.3" ;
53
+ }
54
+ else version (DeimosOpenSSLAutoDetect)
55
+ {
56
+ import deimos.openssl.version_;
57
+
58
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! OpenSSLTextVersion;
59
+ }
60
+ else
61
+ {
62
+ // It was decided in https://github.com/D-Programming-Deimos/openssl/pull/66
63
+ // that we should fall back to the latest supported version of the bindings,
64
+ // should the user provide neither explicit version nor `DeimosOpenSSLAutoDetect`
65
+ public alias OpenSSLVersion = OpenSSLVersionTemplate! " 1.1.0h" ;
66
+ }
67
+
68
+ // Publicly aliased above
69
+ private struct OpenSSLVersionTemplate (string textVersion)
70
+ {
71
+ enum text = textVersion;
72
+
73
+ enum int major = (text[0 ] - ' 0' );
74
+ static assert (major >= 0 );
75
+
76
+ enum int minor = (text[2 ] - ' 0' );
77
+ static assert (minor >= 0 );
78
+
79
+ enum int patch = (text[4 ] - ' 0' );
80
+ static assert (patch >= 0 );
81
+
82
+ static if (text.length == " 1.1.0h" .length)
83
+ {
84
+ enum int build = (text[5 ] - ' `' );
85
+ static assert (build >= 0 );
86
+ }
87
+ else
88
+ enum int build = 0 ;
89
+ }
90
+
5
91
/* Numeric release version identifier:
6
92
* MNNFFPPS: major minor fix patch status
7
93
* The status nibble has one of the values 0 for development, 1 to e for betas
@@ -28,21 +114,22 @@ import deimos.openssl._d_util;
28
114
*/
29
115
30
116
/* Version macros for compile-time API version detection */
31
- enum
32
- {
33
- OPENSSL_VERSION_MAJOR = 1 ,
34
- OPENSSL_VERSION_MINOR = 1 ,
35
- OPENSSL_VERSION_PATCH = 0 ,
36
- OPENSSL_VERSION_BUILD = ' h ' - ' ` '
37
- }
117
+ enum OPENSSL_VERSION_MAJOR = OpenSSLVersion.major;
118
+
119
+ enum OPENSSL_VERSION_MINOR = OpenSSLVersion.minor;
120
+
121
+ enum OPENSSL_VERSION_PATCH = OpenSSLVersion.patch;
122
+
123
+ enum OPENSSL_VERSION_BUILD = OpenSSLVersion.build;
38
124
39
125
int OPENSSL_MAKE_VERSION (int major, int minor, int patch, int build)
40
126
{
41
127
return (major << 28 ) | (minor << 20 ) | (patch << 12 ) | (build << 4 ) | 0xf ;
42
128
}
43
129
44
130
enum OPENSSL_VERSION_NUMBER =
45
- OPENSSL_MAKE_VERSION (OPENSSL_VERSION_MAJOR , OPENSSL_VERSION_MINOR , OPENSSL_VERSION_PATCH , OPENSSL_VERSION_BUILD );
131
+ OPENSSL_MAKE_VERSION (OpenSSLVersion.major, OpenSSLVersion.minor,
132
+ OpenSSLVersion.patch, OpenSSLVersion.build);
46
133
47
134
bool OPENSSL_VERSION_AT_LEAST (int major, int minor, int patch = 0 , int build = 0 )
48
135
{
@@ -54,13 +141,6 @@ bool OPENSSL_VERSION_BEFORE(int major, int minor, int patch = 0, int build = 0)
54
141
return OPENSSL_VERSION_NUMBER < OPENSSL_MAKE_VERSION (major, minor, patch, build);
55
142
}
56
143
57
- version (OPENSSL_FIPS) {
58
- enum OPENSSL_VERSION_TEXT = " OpenSSL 1.1.0h-fips 27 Mar 2018" ;
59
- } else {
60
- enum OPENSSL_VERSION_TEXT = " OpenSSL 1.1.0h 27 Mar 2018" ;
61
- }
62
- enum OPENSSL_VERSION_PTEXT = " part of " ~ OPENSSL_VERSION_TEXT ;
63
-
64
144
/* The macros below are to be used for shared library (.so, .dll, ...)
65
145
* versioning. That kind of versioning works a bit differently between
66
146
* operating systems. The most usual scheme is to set a major and a minor
0 commit comments