Require BearSSL 0.3

This commit is contained in:
jdb committed 2026-10-05 20:59:26 -05:00
1 parent d037c84e8c
commit 70862cb9e4
3 files changed
+16 -12

No files matched your search

+6
View File
@@ -1,5 +1,11 @@
# Changelog # Changelog
## 0.5.1 - 2026-10-05
### Changed
- Require BearSSL 0.3.0 or newer and use its managed PEM decoder interface.
## 0.5.0 - 2026-09-29 ## 0.5.0 - 2026-09-29
### Added ### Added
+2 -2
View File
@@ -1,6 +1,6 @@
# Package # Package
version = "0.5.0" version = "0.5.1"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Full JWT, JWS, JWE, and JWK implementation for Nim, compliant with RFCs 7515-7519." description = "Full JWT, JWS, JWE, and JWK implementation for Nim, compliant with RFCs 7515-7519."
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
@@ -9,7 +9,7 @@ srcDir = "src/main"
# Dependencies # Dependencies
requires "nim >= 1.4.8" requires "nim >= 1.4.8"
requires "bearssl" requires "bearssl >= 0.3.0"
requires "https://github.com/yglukhov/bearssl_pkey_decoder" requires "https://github.com/yglukhov/bearssl_pkey_decoder"
task unittest, "Run the unit test suites.": task unittest, "Run the unit test suites.":
+8 -10
View File
@@ -13,30 +13,28 @@ proc decodePem*(
) = ) =
var pemCtx: PemDecoderContext var pemCtx: PemDecoderContext
pemDecoderInit(pemCtx) pemCtx.init()
var offset: uint = 0 var offset = 0
var bytesRemaining: uint = uint len(pem)
var readingObj = false var readingObj = false
while bytesRemaining > 0: while offset < pem.len:
let bytesRead = pemDecoderPush(pemCtx, unsafeAddr pem[offset], uint bytesRemaining) let bytesRead = pemCtx.push(pem.toOpenArray(offset, pem.high))
offset += bytesRead offset += bytesRead
bytesRemaining -= bytesRead
case pemDecoderEvent(pemCtx): case pemCtx.lastEvent():
of PEM_BEGIN_OBJ: of PEM_BEGIN_OBJ:
if readingObj: if readingObj:
raise newException(ValueError, raise newException(ValueError,
"Invalid PEM: saw a second BEGIN before seeing END.") "Invalid PEM: saw a second BEGIN before seeing END.")
if pemDecoderName(pemCtx) != expectedObjectName: if pemCtx.banner() != expectedObjectName:
raise newException(ValueError, raise newException(ValueError,
"Invalid PEM: expected BEGIN " & expectedObjectName & "Invalid PEM: expected BEGIN " & expectedObjectName &
" but got BEGIN " & $pemDecoderName(pemCtx)) " but got BEGIN " & pemCtx.banner())
readingObj = true readingObj = true
pemDecoderSetdest(pemCtx, callback, keyCtx) pemCtx.setdest(callback, keyCtx)
of PEM_END_OBJ: of PEM_END_OBJ:
if readingObj: readingObj = false if readingObj: readingObj = false