Use Deimos OpenSSL instead of hunt-openssl
This commit is contained in:
parent
6b352fad20
commit
fdbe0b706e
4
dub.json
4
dub.json
|
@ -12,6 +12,6 @@
|
||||||
"copyright": "Copyright © 2021, HuntLabs",
|
"copyright": "Copyright © 2021, HuntLabs",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"hunt-openssl": "~>1.0.4"
|
"openssl": {"repository": "git+https://github.com/HenkKalkwater/openssl.git", "version": "163395f4d8ec04c41a5cf60ef19a327c2ef40770"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ module hunt.jwt.JwtOpenSSL;
|
||||||
|
|
||||||
import deimos.openssl.ssl;
|
import deimos.openssl.ssl;
|
||||||
import deimos.openssl.pem;
|
import deimos.openssl.pem;
|
||||||
|
import deimos.openssl.ecdsa;
|
||||||
import deimos.openssl.rsa;
|
import deimos.openssl.rsa;
|
||||||
import deimos.openssl.hmac;
|
import deimos.openssl.hmac;
|
||||||
import deimos.openssl.err;
|
import deimos.openssl.err;
|
||||||
|
@ -22,19 +23,11 @@ string sign(string msg, string key, JwtAlgorithm algo = JwtAlgorithm.HS256) {
|
||||||
|
|
||||||
void sign_hs(const(EVP_MD)* evp, uint signLen) {
|
void sign_hs(const(EVP_MD)* evp, uint signLen) {
|
||||||
sign = new ubyte[signLen];
|
sign = new ubyte[signLen];
|
||||||
|
|
||||||
HMAC_CTX ctx;
|
if (null is HMAC(evp, key.ptr, cast(int) key.length,
|
||||||
scope(exit) HMAC_CTX_reset(&ctx);
|
cast(const(ubyte)*) msg.ptr, cast(ulong) msg.length,
|
||||||
HMAC_CTX_reset(&ctx);
|
cast(ubyte*) sign.ptr, &signLen)) {
|
||||||
|
throw new Exception("Cannot sign the data using HMAC");
|
||||||
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.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,4 +427,4 @@ private bool verifyShaPem(const(EVP_MD) *alg, int type, string head, const(ubyte
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue