Skip to content

Commit

Permalink
Merge pull request #102 from Geod24/mlang_fix_3.0.10
Browse files Browse the repository at this point in the history
Version handling: Handle multiple digits
  • Loading branch information
CyberShadow authored Aug 10, 2023
2 parents cb15445 + 4ee0e55 commit 1f88418
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions source/deimos/openssl/opensslv.di
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,100 @@ version (DeimosOpenSSL_1_0_0)
{
// https://www.openssl.org/news/changelog.html#openssl-100
// OpenSSL 1.0.0t was released 2015-12-03
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.0t";
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.0t");
}
else version (DeimosOpenSSL_1_0_1)
{
// https://www.openssl.org/news/changelog.html#openssl-101
// OpenSSL 1.0.1u was released 2016-09-22
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.1u";
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.1u");
}
else version (DeimosOpenSSL_1_0_2)
{
// https://www.openssl.org/news/changelog.html#openssl-102
// OpenSSL 1.0.2t was released 2019-09-10
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.2t";
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.2t");
}
else version (DeimosOpenSSL_1_1_0)
{
// https://www.openssl.org/news/changelog.html#openssl-110
// OpenSSL 1.1.0l was released 2019-09-10
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0l";
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.0l");
}
else version (DeimosOpenSSL_1_1_1)
{
// https://www.openssl.org/news/changelog.html#openssl-111
// OpenSSL 1.1.1m was released 2021-12-14
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.1m";
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.1m");
}
else version (DeimosOpenSSL_3_0)
{
// https://www.openssl.org/news/changelog.html#openssl-30
// OpenSSL 3.0.3 was released 2022-05-03
public alias OpenSSLVersion = OpenSSLVersionTemplate!"3.0.3";
public enum OpenSSLVersion = parseOpenSSLVersion("3.0.3");
}
else version (DeimosOpenSSLAutoDetect)
{
import deimos.openssl.version_;

public alias OpenSSLVersion = OpenSSLVersionTemplate!OpenSSLTextVersion;
public enum OpenSSLVersion = parseOpenSSLVersion(OpenSSLTextVersion);
}
else
{
// It was decided in https://github.com/D-Programming-Deimos/openssl/pull/66
// that we should fall back to the latest supported version of the bindings,
// should the user provide neither explicit version nor `DeimosOpenSSLAutoDetect`
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0h";
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.0h");
}

// Publicly aliased above
private struct OpenSSLVersionTemplate (string textVersion)
private struct OpenSSLVersionStruct
{
enum text = textVersion;
string text;
uint major, minor, patch;
int build;
}

private OpenSSLVersionStruct parseOpenSSLVersion()(string textVersion)
{
OpenSSLVersionStruct v;

import std.ascii : isDigit;
import std.algorithm.iteration : splitter;
import std.algorithm.searching : canFind;
import std.conv : to;
import std.range : dropExactly;

enum int major = (text[0] - '0');
static assert (major >= 0);
v.text = textVersion;

enum int minor = (text[2] - '0');
static assert (minor >= 0);
v.major = textVersion.splitter('.')
.front.to!uint;
assert (v.major >= 0);

enum int patch = (text[4] - '0');
static assert (patch >= 0);
v.minor = textVersion.splitter('.')
.dropExactly(1)
.front.to!uint;
assert (v.minor >= 0);

static if (text.length == "1.1.0h".length)
// `std.algorithm.iteration : splitWhen` not usable at CT
// so we're using `canFind`.
string patchText = textVersion.splitter('.')
.dropExactly(2).front;
auto patchChar = patchText.canFind!(
(dchar c) => !c.isDigit());

v.patch = patchText[0 .. $ - patchChar].to!uint;
assert (v.patch >= 0);

if (patchChar)
{
enum int build = (text[5] - '`');
static assert (build >= 0);
v.build = (patchText[$ - 1] - '`');
assert (v.build >= 0);
}
else
enum int build = 0;
v.build = 0;

return v;
}

/* Numeric release version identifier:
Expand Down

0 comments on commit 1f88418

Please sign in to comment.