Skip to content

feat: add jwt helpers - #53

Merged
funlang merged 6 commits into
mainfrom
feat-jwt
Nov 11, 2026
Merged

funlang merged 6 commits into
mainfrom
feat-jwt

Conversation

@taadis

@taadis taadis commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

taadis and others added 4 commits November 11, 2026 11:57
win64 getapi() runs on the libffi backend (lffi.pas), where a 'p' argument
is a raw pointer value. `var h` therefore passed h's value (0) as
phAlgorithm, so BCryptOpenAlgorithmProvider returned
STATUS_INVALID_PARAMETER (0xC000000D) and every SHA384/512 hash failed.

Pass the address of an 8-byte buffer instead and read the handle back with a
pointer-width little-endian helper (the same _zr idiom as lib-ado-unx.fun).
Also:
- gate CNG on host.bits >= 64; 32-bit Windows keeps the CryptoAPI path,
  whose winapi.pas 'p' means "address of this value";
- use the real signatures 'pppi:i' / 'pi:i' / 'ppipipi:i' and pass the
  UTF-16 name by address;
- terminate the UTF-16 name with two NUL bytes;
- pass a non-NULL pointer for an empty message, which CNG rejects.

Verified on Linux with a fake bcrypt: `var h` returned -1073741811 while the
buffer form opened, hashed and closed with a full 64-bit handle.
win32's winapi.pas has always passed the address of the value for a 'p'
argument, so `var x` is the natural way to receive an OUT handle. lffi
(Unix and win64) sent the numeric value instead, silently handing the
callee 0/NULL; the auth SHA384/512 path hit this as an unknown NTSTATUS.

For a CRef argument with a 'p' parameter, allocate a pointer-width scratch
cell, pass its address, and copy the result back into the referenced
variable after the call. String and object targets keep their existing
handling, and the explicit raw-address idiom (buf.toNum(-1)) is unchanged.

Cover it with setout/addout in the FFI helper and a ffi-var-ref.fun
snapshot that runs on Linux/macOS and the win64 runner.
The win64 job restored a cached libffitest.dll built before setout/addout
existed, so ffi-var-ref.fun failed with 'symbol not found'. Include the C
source hash in the cache key so adding an export rebuilds the DLL, and list
the new symbols in the build diagnostic.
@funlang
funlang merged commit 3ea28ba into main Nov 11, 2026
7 checks passed
@taadis
taadis deleted the feat-jwt branch November 11, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants