Fixes for new OpenSSL

This commit is contained in:
Yuriy Glukhov
2016-12-05 13:45:11 +02:00
parent 549aa1eb13
commit 12098313c2
2 changed files with 17 additions and 11 deletions

View File

@@ -1,5 +1,4 @@
[Package]
name = "jwt"
# Package
version = "0.0.1"
author = "Endre Karlson"
description = "JSON Web Tokens for Nim"
@@ -7,5 +6,6 @@ license = "MIT"
srcDir = "src"
[Deps]
Requires: "nim >= 0.10.3"
# Deps
requires "nim >= 0.10.3"
requires "https://github.com/yglukhov/linktools"

View File

@@ -1,17 +1,21 @@
import openssl
import openssl, linktools
# TODO: Linkage flags should probably need more attention because of different
# openssl versions. E.g. DigestSign* functions are not available in old openssl.
when defined(macosx):
{.passL: "-lcrypto.35".}
const libcrypto = "crypto.35"
else:
{.passL: "-lcrypto".}
const libcrypto = "crypto"
{.passL: "-l" & libcrypto.}
export EVP_PKEY_RSA
const
HMAC_MAX_MD_CBLOCK* = 128
const sslIsOld = libHasSymbol(libcrypto, "EVP_MD_CTX_create")
type
EVP_MD* = SslPtr
EVP_MD_CTX* = SslPtr
@@ -42,10 +46,12 @@ proc PEM_read_bio_PrivateKey*(bp: BIO, x: ptr EVP_PKEY,
cb: pointer, u: pointer): EVP_PKEY {.cdecl, importc.}
proc EVP_PKEY_free*(p: EVP_PKEY) {.cdecl, importc.}
proc EVP_MD_CTX_create*(): EVP_MD_CTX {.cdecl, importc.}
proc EVP_MD_CTX_destroy*(ctx: EVP_MD_CTX) {.cdecl, importc.}
when sslIsOld:
proc EVP_MD_CTX_create*(): EVP_MD_CTX {.cdecl, importc.}
proc EVP_MD_CTX_destroy*(ctx: EVP_MD_CTX) {.cdecl, importc.}
else:
proc EVP_MD_CTX_create*(): EVP_MD_CTX {.cdecl, importc: "EVP_MD_CTX_new".}
proc EVP_MD_CTX_destroy*(ctx: EVP_MD_CTX) {.cdecl, importc: "EVP_MD_CTX_free".}
proc EVP_DigestSignInit*(ctx: EVP_MD_CTX, pctx: ptr EVP_PKEY_CTX,
typ: EVP_MD, e: ENGINE, pkey: EVP_PKEY): cint {.cdecl, importc.}