aboutsummaryrefslogtreecommitdiff
path: root/tests/rsa.nim
blob: a4aa64b57d41945ee945b9fbbc4b1e2f8d084146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import strutils

import nimterop/[build, cimport]

setDefines(@["cryptoStd"])
getHeader("openssl/crypto.h")

const
  basePath = cryptoPath.parentDir
  FLAGS {.strdefine.} = ""

static:
  cSkipSymbol(@["ERR_load_crypto_strings", "OpenSSLDie"])

cPlugin:
  import strutils

  proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
    sym.name = sym.name.strip(chars = {'_'}).replace("__", "_")

    if sym.name in [
      "AES_ENCRYPT", "AES_DECRYPT",
      "BIO_CTRL_PENDING", "BIO_CTRL_WPENDING",
      "BN_F_BNRAND", "BN_F_BNRAND_RANGE",
      "CRYPTO_LOCK", "CRYPTO_NUM_LOCKS", "CRYPTO_THREADID",
      "EVP_CIPHER",
      "OPENSSL_VERSION",
      "PKCS7_ENCRYPT", "PKCS7_STREAM",
      "SSLEAY_VERSION",
      "SSL_TXT_ADH", "SSL_TXT_AECDH", "SSL_TXT_kECDHE"
    ]:
      sym.name = "C_" & sym.name

cOverride:
  proc OPENSSL_die*(assertion: cstring; file: cstring; line: cint) {.importc.}

# Skip comments for https://github.com/tree-sitter/tree-sitter-c/issues/44
cImport(@[
  basePath / "rsa.h",
  basePath / "err.h",
], recurse = true, flags = "-f:ast2 -s -c " & FLAGS)

{.passL: cryptoLPath.}

OpensslInit()
echo $OPENSSL_VERSION_TEXT