Skip to content

fix!: reject bad FFI pointers instead of panicking, and report keygen failures - #144

Merged
WingZer0o merged 1 commit into
mainfrom
t3/ffi-no-panic
Nov 25, 2026
Merged

WingZer0o merged 1 commit into
mainfrom
t3/ffi-no-panic

Conversation

@WingZer0o

Copy link
Copy Markdown
Member

Summary

  • Every export reads caller buffers through bytes_from_ffi. A null pointer with a non-zero length, or a length above isize::MAX, returns InvalidInput (4). A null pointer with length 0 is still an empty buffer, including an empty message to sign or hash.
  • assert!, unwrap(), and unchecked from_raw_parts are gone from the export path. RSA PEM strings that cannot be a C string return KeyGenerationFailed instead of panicking.
  • Key generation, nonce generation, SHA, and BLAKE2 results now include error_code. Success is 0. This changes those struct layouts, so cas-dotnet-sdk has to regenerate NativeMethods.g.cs.

cargo test --release --locked --lib: 106 passed.

Closes #85
Closes #86

… failures

A null pointer with a non-zero length, or a length above isize::MAX, is now
InvalidInput on every export. Empty buffers stay valid. Key generation, hash,
and nonce results carry error_code so a failure is not only a null pointer.

Closes #85
Closes #86

Co-authored-by: Cursor <cursoragent@cursor.com>
@WingZer0o
WingZer0o merged commit 939c8b4 into main Nov 25, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
This was referenced Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant