Use Deimos OpenSSL instead of hunt-openssl

This commit is contained in:
Chris Josten 2022-09-16 13:09:03 +02:00
parent 6b352fad20
commit fdbe0b706e
2 changed files with 9 additions and 16 deletions

View file

@ -12,6 +12,6 @@
"copyright": "Copyright © 2021, HuntLabs",
"license": "MIT",
"dependencies": {
"hunt-openssl": "~>1.0.4"
"openssl": {"repository": "git+https://github.com/HenkKalkwater/openssl.git", "version": "163395f4d8ec04c41a5cf60ef19a327c2ef40770"}
}
}

View file

@ -2,6 +2,7 @@ module hunt.jwt.JwtOpenSSL;
import deimos.openssl.ssl;
import deimos.openssl.pem;
import deimos.openssl.ecdsa;
import deimos.openssl.rsa;
import deimos.openssl.hmac;
import deimos.openssl.err;
@ -23,18 +24,10 @@ string sign(string msg, string key, JwtAlgorithm algo = JwtAlgorithm.HS256) {
void sign_hs(const(EVP_MD)* evp, uint signLen) {
sign = new ubyte[signLen];
HMAC_CTX ctx;
scope(exit) HMAC_CTX_reset(&ctx);
HMAC_CTX_reset(&ctx);
if(0 == HMAC_Init_ex(&ctx, key.ptr, cast(int)key.length, evp, null)) {
throw new Exception("Can't initialize HMAC context.");
}
if(0 == HMAC_Update(&ctx, cast(const(ubyte)*)msg.ptr, cast(ulong)msg.length)) {
throw new Exception("Can't update HMAC.");
}
if(0 == HMAC_Final(&ctx, cast(ubyte*)sign.ptr, &signLen)) {
throw new Exception("Can't finalize HMAC.");
if (null is HMAC(evp, key.ptr, cast(int) key.length,
cast(const(ubyte)*) msg.ptr, cast(ulong) msg.length,
cast(ubyte*) sign.ptr, &signLen)) {
throw new Exception("Cannot sign the data using HMAC");
}
}