mirror of
https://github.com/logos-storage/nim-bearssl.git
synced 2026-01-02 13:33:06 +00:00
work around C++ linking issue (#50)
* test c++ support, work around linking issue * fix imports, don't test C++ after all
This commit is contained in:
parent
e4f0977b54
commit
917b7274f9
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -159,3 +159,5 @@ jobs:
|
||||
nimble --version
|
||||
nimble install -y --depsOnly
|
||||
env NIMLANG=c nimble test
|
||||
# C++ support requires fixing const pointer proc assignments
|
||||
# env NIMLANG=cpp nimble test
|
||||
|
||||
@ -612,8 +612,7 @@ proc sslEngineSetSuites*(cc: var SslEngineContext; suites: ptr uint16;
|
||||
suitesNum: uint) {.importcFunc,
|
||||
importc: "br_ssl_engine_set_suites", header: "bearssl_ssl.h".}
|
||||
|
||||
proc sslEngineSetX509*(cc: var SslEngineContext; x509ctx: ptr ptr X509Class) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineSetX509*(cc: var SslEngineContext; x509ctx: ptr ptr X509Class) {.inline.} =
|
||||
cc.x509ctx = x509ctx
|
||||
|
||||
|
||||
@ -633,8 +632,7 @@ proc sslEngineSetHash*(ctx: var SslEngineContext; id: cint; impl: ptr HashClass)
|
||||
multihashSetimpl(ctx.mhash, id, impl)
|
||||
|
||||
|
||||
proc sslEngineGetHash*(ctx: var SslEngineContext; id: cint): ptr HashClass {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineGetHash*(ctx: var SslEngineContext; id: cint): ptr HashClass {.inline.} =
|
||||
return multihashGetimpl(ctx.mhash, id)
|
||||
|
||||
|
||||
@ -659,8 +657,7 @@ proc sslEngineSetAesCbc*(cc: var SslEngineContext; implEnc: ptr BlockCbcencClass
|
||||
proc sslEngineSetDefaultAesCbc*(cc: var SslEngineContext) {.importcFunc,
|
||||
importc: "br_ssl_engine_set_default_aes_cbc", header: "bearssl_ssl.h".}
|
||||
|
||||
proc sslEngineSetAesCtr*(cc: var SslEngineContext; impl: ptr BlockCtrClass) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineSetAesCtr*(cc: var SslEngineContext; impl: ptr BlockCtrClass) {.inline.} =
|
||||
cc.iaesCtr = impl
|
||||
|
||||
|
||||
@ -680,13 +677,11 @@ proc sslEngineSetGhash*(cc: var SslEngineContext; impl: Ghash) {.inline.} =
|
||||
cc.ighash = impl
|
||||
|
||||
|
||||
proc sslEngineSetChacha20*(cc: var SslEngineContext; ichacha: Chacha20Run) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineSetChacha20*(cc: var SslEngineContext; ichacha: Chacha20Run) {.inline.} =
|
||||
cc.ichacha = ichacha
|
||||
|
||||
|
||||
proc sslEngineSetPoly1305*(cc: var SslEngineContext; ipoly: Poly1305Run) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineSetPoly1305*(cc: var SslEngineContext; ipoly: Poly1305Run) {.inline.} =
|
||||
cc.ipoly = ipoly
|
||||
|
||||
|
||||
@ -735,8 +730,7 @@ proc sslEngineGetEc*(cc: var SslEngineContext): ptr EcImpl {.inline.} =
|
||||
return cc.iec
|
||||
|
||||
|
||||
proc sslEngineSetRsavrfy*(cc: var SslEngineContext; irsavrfy: RsaPkcs1Vrfy) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslEngineSetRsavrfy*(cc: var SslEngineContext; irsavrfy: RsaPkcs1Vrfy) {.inline.} =
|
||||
cc.irsavrfy = irsavrfy
|
||||
|
||||
|
||||
@ -972,8 +966,7 @@ proc sslClientSetRsapub*(cc: var SslClientContext; irsapub: RsaPublic) {.inline.
|
||||
proc sslClientSetDefaultRsapub*(cc: var SslClientContext) {.importcFunc,
|
||||
importc: "br_ssl_client_set_default_rsapub", header: "bearssl_ssl.h".}
|
||||
|
||||
proc sslClientSetMinClienthelloLen*(cc: var SslClientContext; len: uint16) {.inline,
|
||||
importcFunc.} =
|
||||
proc sslClientSetMinClienthelloLen*(cc: var SslClientContext; len: uint16) {.inline.} =
|
||||
cc.minClienthelloLen = len
|
||||
|
||||
|
||||
|
||||
@ -330,8 +330,7 @@ proc x509MinimalSetTime*(ctx: var X509MinimalContext; days: uint32; seconds: uin
|
||||
|
||||
|
||||
proc x509MinimalSetTimeCallback*(ctx: var X509MinimalContext; itimeCtx: pointer;
|
||||
itime: X509TimeCheck) {.inline, importcFunc,
|
||||
importc: "br_x509_minimal_set_time_callback".} =
|
||||
itime: X509TimeCheck) {.inline.} =
|
||||
ctx.itimeCtx = itimeCtx
|
||||
ctx.itime = itime
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import
|
||||
"."/[csources, bearssl_x509]
|
||||
"."/[csources, bearssl_block, bearssl_pem, bearssl_x509]
|
||||
|
||||
{.pragma: importcFunc, cdecl, gcsafe, noSideEffect, raises: [].}
|
||||
{.used.}
|
||||
@ -7,7 +7,6 @@ import
|
||||
const
|
||||
bearToolsPath = bearPath & "tools/"
|
||||
|
||||
|
||||
{.compile: bearToolsPath & "vector.c".}
|
||||
{.compile: bearToolsPath & "xmem.c".}
|
||||
{.compile: bearToolsPath & "names.c".}
|
||||
@ -15,12 +14,12 @@ const
|
||||
{.compile: bearToolsPath & "files.c".}
|
||||
|
||||
type
|
||||
X509NoanchorContext* {.importc: "x509_noanchor_context", header: "brssl.h", bycopy.} = object
|
||||
X509NoanchorContext* {.importc: "x509_noanchor_context", header: "brssl_cpp.h", bycopy.} = object
|
||||
vtable* {.importc: "vtable".}: ptr X509Class
|
||||
inner* {.importc: "inner".}: ptr ptr X509Class
|
||||
|
||||
proc x509NoanchorInit*(xwc: var X509NoanchorContext; inner: ptr ptr X509Class) {.importcFunc,
|
||||
importc: "x509_noanchor_init", header: "brssl.h".}
|
||||
importc: "x509_noanchor_init", header: "brssl_cpp.h".}
|
||||
|
||||
proc initNoAnchor*(xwc: var X509NoanchorContext, inner: ptr ptr X509Class) {.
|
||||
importcFunc, importc: "x509_noanchor_init", header: "brssl.h", deprecated: "x509NoanchorInit".}
|
||||
importcFunc, importc: "x509_noanchor_init", header: "brssl_cpp.h", deprecated: "x509NoanchorInit".}
|
||||
|
||||
12
bearssl/abi/brssl_cpp.h
Normal file
12
bearssl/abi/brssl_cpp.h
Normal file
@ -0,0 +1,12 @@
|
||||
/* workaround until upstream fixes header */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "brssl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -35,10 +35,12 @@ const
|
||||
|
||||
# TODO https://github.com/nim-lang/Nim/issues/19864
|
||||
|
||||
{.passc: "-I" & quoteShell(currentSourcePath.rsplit({DirSep, AltSep}, 1)[0]).}
|
||||
{.passc: "-I" & quoteShell(bearSrcPath)}
|
||||
{.passc: "-I" & quoteShell(bearIncPath)}
|
||||
{.passc: "-I" & quoteShell(bearToolsPath)}
|
||||
|
||||
|
||||
when defined(windows):
|
||||
{.passc: "-DBR_USE_WIN32_TIME=1".}
|
||||
{.passc: "-DBR_USE_WIN32_RAND=1".}
|
||||
|
||||
12
tests/test_brssl.nim
Normal file
12
tests/test_brssl.nim
Normal file
@ -0,0 +1,12 @@
|
||||
import unittest2,
|
||||
../bearssl/[x509, brssl]
|
||||
|
||||
{.used.}
|
||||
|
||||
suite "x509":
|
||||
test "init":
|
||||
var xwc: X509NoanchorContext
|
||||
var x509: X509MinimalContext
|
||||
|
||||
x509MinimalInit(x509, nil, nil, 0)
|
||||
x509NoanchorInit(xwc, addr x509.vtable)
|
||||
@ -2,8 +2,7 @@
|
||||
|
||||
import ../bearssl
|
||||
|
||||
# TODO doesn't work from C++ due to missing `export "C"`
|
||||
# discard getConfig()
|
||||
discard getConfig()
|
||||
|
||||
# TODO doesn't work from C++ due to `const`:ness issues
|
||||
# discard ecGetDefault()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user