chore: make quictls optional (#19)

This commit is contained in:
richΛrd
2025-09-03 16:09:11 -04:00
committed by GitHub
parent 6ca91ea115
commit 50c9d44f76
6 changed files with 192 additions and 163 deletions

View File

@@ -1,18 +1,14 @@
ngtcp2 for Nim
==============
# ngtcp2 for Nim
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
![Github action](https://github.com/status-im/nim-bearssl/workflows/CI/badge.svg)
<img src="https://img.shields.io/badge/nim-%3E%3D1.2.0-orange.svg?style=flat-square" />
Wrapper around the [ngtcp2](https://github.com/ngtcp2/ngtcp2) C library for
[Nim](https://nim-lang.org/).
Updating to a newer version
---------------------------
## Updating to a newer version
Follow these steps when updating the wrapper to a newer version of ngtcp2:
@@ -21,3 +17,9 @@ Follow these steps when updating the wrapper to a newer version of ngtcp2:
- run `build.sh` (requires Nim, CMake and clang to be installed)
- increase the `version` property in the `ngtcp2.nimble` file
- commit the changes
### Enabling QuicTLS
```
`-d:ngtcp2_enable_quictls`
```

View File

@@ -13,6 +13,7 @@ type
ptls_handshake_properties_t_anon0_t_server_t_cookie_t* =
struct_st_ptls_handshake_properties_t_anon0_t_server_t_cookie_t
when defined(ngtcp2_enable_quictls):
# OpenSSL/QuicTLS crypto support
# OpenSSL/QuicTLS type definitions
type

View File

@@ -34,9 +34,10 @@ const picotlsInclude = root/"libs"/"picotls"/"include"
{.passc: fmt"-I{ngtcp2LibIncludes}".}
{.passc: fmt"-I{picotlsInclude}".}
when defined(ngtcp2_enable_quictls):
# QuicTLS/OpenSSL crypto support
{.passc: "-DNGTCP2_CRYPTO_QUICTLS".}
{.passc: "-I/usr/include/openssl".}
{.localpassc: "-DNGTCP2_CRYPTO_QUICTLS".}
{.localpassc: "-I/usr/include/openssl".}
{.compile: "./libs/picotls/picotlsvs/picotls/wintimeofday.c".}
{.compile: "./libs/picotls/lib/pembase64.c".}
@@ -1056,11 +1057,11 @@ type
handshake_properties*: ptls_handshake_properties_t_553648999
ngtcp2_crypto_picotls_ctx_553649050 = struct_ngtcp2_crypto_picotls_ctx_553649049 ## Generated based on /nim-ngtcp2/libs/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h:53:3
struct_ptls_cred_buffer_s_553649052 {.pure, inheritable, bycopy.} = object
base*: cstring ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/utils/cred_buffer.h:8:16
base*: cstring ## Generated based on /home/r/vacp2p/nim-ngtcp2/build/lib/includes/utils/cred_buffer.h:8:16
len*: csize_t
off*: csize_t
owns_base*: cint
ptls_cred_buffer_t_553649054 = struct_ptls_cred_buffer_s_553649053 ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/utils/cred_buffer.h:16:3
ptls_cred_buffer_t_553649054 = struct_ptls_cred_buffer_s_553649053 ## Generated based on /home/r/vacp2p/nim-ngtcp2/build/lib/includes/utils/cred_buffer.h:16:3
sa_family_t_553649056 = cushort ## Generated based on /usr/include/x86_64-linux-gnu/bits/sockaddr.h:28:28
in_port_t_553649058 = uint16 ## Generated based on /usr/include/netinet/in.h:125:18
compiler_socklen_t_553649060 = cuint ## Generated based on /usr/include/x86_64-linux-gnu/bits/types.h:210:23
@@ -4804,21 +4805,21 @@ else:
hint("Declaration of " & "struct_ngtcp2_ccerr" &
" already exists, not redeclaring")
when not declared(NGTCP2_VERSION):
when "1.6.0" is static:
when "1.11.0-DEV" is static:
const
NGTCP2_VERSION* = "1.6.0" ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/ngtcp2/version.h:39:9
NGTCP2_VERSION* = "1.11.0-DEV" ## Generated based on /nim-ngtcp2/libs/ngtcp2/lib/includes/ngtcp2/version.h:39:9
else:
let NGTCP2_VERSION* = "1.6.0" ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/ngtcp2/version.h:39:9
let NGTCP2_VERSION* = "1.11.0-DEV" ## Generated based on /nim-ngtcp2/libs/ngtcp2/lib/includes/ngtcp2/version.h:39:9
else:
static :
hint("Declaration of " & "NGTCP2_VERSION" &
" already exists, not redeclaring")
when not declared(NGTCP2_VERSION_NUM):
when 67072 is static:
when 68352 is static:
const
NGTCP2_VERSION_NUM* = 67072 ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/ngtcp2/version.h:49:9
NGTCP2_VERSION_NUM* = 68352 ## Generated based on /nim-ngtcp2/libs/ngtcp2/lib/includes/ngtcp2/version.h:49:9
else:
let NGTCP2_VERSION_NUM* = 67072 ## Generated based on /home/andrew/opensource/Vac/nim-ngtcp2/build/lib/includes/ngtcp2/version.h:49:9
let NGTCP2_VERSION_NUM* = 68352 ## Generated based on /nim-ngtcp2/libs/ngtcp2/lib/includes/ngtcp2/version.h:49:9
else:
static :
hint("Declaration of " & "NGTCP2_VERSION_NUM" &
@@ -10433,6 +10434,7 @@ type
ptls_handshake_properties_t_anon0_t_server_t_cookie_t* =
struct_st_ptls_handshake_properties_t_anon0_t_server_t_cookie_t
when defined(ngtcp2_enable_quictls):
# OpenSSL/QuicTLS crypto support
# OpenSSL/QuicTLS type definitions
type
@@ -10451,42 +10453,64 @@ const
# ngtcp2_crypto_quictls function bindings
when not declared(ngtcp2_crypto_quictls_init):
proc ngtcp2_crypto_quictls_init*(): cint {.
cdecl, importc: "ngtcp2_crypto_quictls_init".}
cdecl, importc: "ngtcp2_crypto_quictls_init"
.}
else:
static:
hint("Declaration of " & "ngtcp2_crypto_quictls_init" &
" already exists, not redeclaring")
hint(
"Declaration of " & "ngtcp2_crypto_quictls_init" &
" already exists, not redeclaring"
)
when not declared(ngtcp2_crypto_quictls_from_ossl_encryption_level):
proc ngtcp2_crypto_quictls_from_ossl_encryption_level*(
ossl_level: OSSL_ENCRYPTION_LEVEL): ngtcp2_encryption_level_553648745 {.
cdecl, importc: "ngtcp2_crypto_quictls_from_ossl_encryption_level".}
ossl_level: OSSL_ENCRYPTION_LEVEL
): ngtcp2_encryption_level_553648745 {.
cdecl, importc: "ngtcp2_crypto_quictls_from_ossl_encryption_level"
.}
else:
static:
hint("Declaration of " & "ngtcp2_crypto_quictls_from_ossl_encryption_level" &
" already exists, not redeclaring")
hint(
"Declaration of " & "ngtcp2_crypto_quictls_from_ossl_encryption_level" &
" already exists, not redeclaring"
)
when not declared(ngtcp2_crypto_quictls_from_ngtcp2_encryption_level):
proc ngtcp2_crypto_quictls_from_ngtcp2_encryption_level*(
encryption_level: ngtcp2_encryption_level_553648745): OSSL_ENCRYPTION_LEVEL {.
cdecl, importc: "ngtcp2_crypto_quictls_from_ngtcp2_encryption_level".}
encryption_level: ngtcp2_encryption_level_553648745
): OSSL_ENCRYPTION_LEVEL {.
cdecl, importc: "ngtcp2_crypto_quictls_from_ngtcp2_encryption_level"
.}
else:
static:
hint("Declaration of " & "ngtcp2_crypto_quictls_from_ngtcp2_encryption_level" &
" already exists, not redeclaring")
hint(
"Declaration of " & "ngtcp2_crypto_quictls_from_ngtcp2_encryption_level" &
" already exists, not redeclaring"
)
when not declared(ngtcp2_crypto_quictls_configure_server_context):
proc ngtcp2_crypto_quictls_configure_server_context*(ssl_ctx: SSL_CTX): cint {.
cdecl, importc: "ngtcp2_crypto_quictls_configure_server_context".}
proc ngtcp2_crypto_quictls_configure_server_context*(
ssl_ctx: SSL_CTX
): cint {.cdecl, importc: "ngtcp2_crypto_quictls_configure_server_context".}
else:
static:
hint("Declaration of " & "ngtcp2_crypto_quictls_configure_server_context" &
" already exists, not redeclaring")
hint(
"Declaration of " & "ngtcp2_crypto_quictls_configure_server_context" &
" already exists, not redeclaring"
)
when not declared(ngtcp2_crypto_quictls_configure_client_context):
proc ngtcp2_crypto_quictls_configure_client_context*(ssl_ctx: SSL_CTX): cint {.
cdecl, importc: "ngtcp2_crypto_quictls_configure_client_context".}
proc ngtcp2_crypto_quictls_configure_client_context*(
ssl_ctx: SSL_CTX
): cint {.cdecl, importc: "ngtcp2_crypto_quictls_configure_client_context".}
else:
static:
hint("Declaration of " & "ngtcp2_crypto_quictls_configure_client_context" &
" already exists, not redeclaring")
hint(
"Declaration of " & "ngtcp2_crypto_quictls_configure_client_context" &
" already exists, not redeclaring"
)

View File

@@ -1,5 +1,5 @@
packageName = "ngtcp2"
version = "0.37.0"
version = "0.38.0"
author = "Status Research & Development GmbH"
description = "Nim wrapper around the ngtcp2 library"
license = "MIT"

View File

@@ -34,6 +34,7 @@ const picotlsInclude = root/"libs"/"picotls"/"include"
{.passc: fmt"-I{ngtcp2LibIncludes}".}
{.passc: fmt"-I{picotlsInclude}".}
when defined(ngtcp2_enable_quictls):
# QuicTLS/OpenSSL crypto support
{.passc: "-DNGTCP2_CRYPTO_QUICTLS".}
{.passc: "-I/usr/include/openssl".}
{.localpassc: "-DNGTCP2_CRYPTO_QUICTLS".}
{.localpassc: "-I/usr/include/openssl".}

View File

@@ -23,6 +23,7 @@ test "ptls_instantiation":
var tls: ptr ptls_t = ptls_client_new(addr ctx)
check tls != nil
when defined(ngtcp2_enable_quictls):
test "QuicTLS bindings":
# Test error constants
check NGTCP2_CRYPTO_QUICTLS_ERR_TLS_WANT_X509_LOOKUP == -10001