From b9a6b67a3951b8e72b00d1a9891eadc00227d4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chaloupka?= Date: Fri, 10 Jan 2025 13:16:20 +0100 Subject: [PATCH] Fix compilation with newer openssl --- src/openssl/source/jwtlited/openssl.d | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/openssl/source/jwtlited/openssl.d b/src/openssl/source/jwtlited/openssl.d index faaa638..b1e702a 100644 --- a/src/openssl/source/jwtlited/openssl.d +++ b/src/openssl/source/jwtlited/openssl.d @@ -4,6 +4,7 @@ public import jwtlited; version (assert) import core.stdc.stdio; import deimos.openssl.ec; +import deimos.openssl.ecdsa; import deimos.openssl.err; import deimos.openssl.evp; import deimos.openssl.hmac; @@ -38,7 +39,7 @@ private struct HMACImpl(JWTAlgorithm implAlg) private { const(char)[] key; - HMAC_CTX ctx; + HMAC_CTX* ctx; ubyte[signLen] sigBuf; } @@ -46,7 +47,7 @@ private struct HMACImpl(JWTAlgorithm implAlg) ~this() @trusted { - HMAC_CTX_reset(&ctx); + if (ctx) HMAC_CTX_free(ctx); } bool loadKey(K)(K key) if (isToken!K) @@ -60,8 +61,13 @@ private struct HMACImpl(JWTAlgorithm implAlg) else static if (implAlg == JWTAlgorithm.HS384) alias evp = EVP_sha384; else static if (implAlg == JWTAlgorithm.HS512) alias evp = EVP_sha512; - HMAC_CTX_reset(&ctx); - return HMAC_Init_ex(&ctx, this.key.ptr, cast(int)key.length, evp(), null); + if (ctx is null) + { + ctx = HMAC_CTX_new(); + if (ctx is null) onOutOfMemoryError; + } + else HMAC_CTX_reset(ctx); + return HMAC_Init_ex(ctx, this.key.ptr, cast(int)key.length, evp(), null); }(); if (!ret) return false; return true; @@ -90,13 +96,13 @@ private struct HMACImpl(JWTAlgorithm implAlg) assert(key.length, "Secret key not set"); if (!key.length || !value.length) return false; - scope (exit) HMAC_Init_ex(&ctx, null, 0, null, null); + scope (exit) HMAC_Init_ex(ctx, null, 0, null, null); - auto ret = HMAC_Update(&ctx, cast(const(ubyte)*)value.ptr, cast(ulong)value.length); + auto ret = HMAC_Update(ctx, cast(const(ubyte)*)value.ptr, cast(ulong)value.length); if (!ret) return false; uint slen; - ret = HMAC_Final(&ctx, sigBuf.ptr, &slen); + ret = HMAC_Final(ctx, sigBuf.ptr, &slen); assert(slen == signLen); if (!ret) return false; return true;