Require BearSSL 0.3
This commit is contained in:
1 parent
d037c84e8c
commit
70862cb9e4
3 files changed
+16
-12
No files matched your search
@@ -13,30 +13,28 @@ proc decodePem*(
|
||||
) =
|
||||
|
||||
var pemCtx: PemDecoderContext
|
||||
pemDecoderInit(pemCtx)
|
||||
pemCtx.init()
|
||||
|
||||
var offset: uint = 0
|
||||
var bytesRemaining: uint = uint len(pem)
|
||||
var offset = 0
|
||||
var readingObj = false
|
||||
|
||||
while bytesRemaining > 0:
|
||||
let bytesRead = pemDecoderPush(pemCtx, unsafeAddr pem[offset], uint bytesRemaining)
|
||||
while offset < pem.len:
|
||||
let bytesRead = pemCtx.push(pem.toOpenArray(offset, pem.high))
|
||||
offset += bytesRead
|
||||
bytesRemaining -= bytesRead
|
||||
|
||||
case pemDecoderEvent(pemCtx):
|
||||
case pemCtx.lastEvent():
|
||||
of PEM_BEGIN_OBJ:
|
||||
if readingObj:
|
||||
raise newException(ValueError,
|
||||
"Invalid PEM: saw a second BEGIN before seeing END.")
|
||||
|
||||
if pemDecoderName(pemCtx) != expectedObjectName:
|
||||
if pemCtx.banner() != expectedObjectName:
|
||||
raise newException(ValueError,
|
||||
"Invalid PEM: expected BEGIN " & expectedObjectName &
|
||||
" but got BEGIN " & $pemDecoderName(pemCtx))
|
||||
" but got BEGIN " & pemCtx.banner())
|
||||
|
||||
readingObj = true
|
||||
pemDecoderSetdest(pemCtx, callback, keyCtx)
|
||||
pemCtx.setdest(callback, keyCtx)
|
||||
|
||||
of PEM_END_OBJ:
|
||||
if readingObj: readingObj = false
|
||||
|
||||
Reference in new issue
Block a user