Skip to content

feat(apple): surface CryptoKit error details through FFI bridge#159

Merged
jgowdy-godaddy merged 1 commit into
mainfrom
fix/surface-swift-bridge-errors
May 21, 2026
Merged

feat(apple): surface CryptoKit error details through FFI bridge#159
jgowdy-godaddy merged 1 commit into
mainfrom
fix/surface-swift-bridge-errors

Conversation

@jgowdy-godaddy
Copy link
Copy Markdown
Contributor

Summary

  • Add enclaveapp_se_last_error() FFI function to the Swift bridge that exposes the last CryptoKit/Security error string
  • Update all 7 catch blocks in bridge.swift to call setLastError() with the exception detail before returning numeric error codes
  • Update all Rust FFI error sites (keychain.rs, sign.rs, encrypt.rs) to query last_bridge_error() and include the detail in error messages
  • Improves diagnostics for issue gdcorp-engineering/gocode-dev#134 where SE key generation fails with only "FFI returned error code 1" and no detail

Example

Before: FFI returned error code 1
After: FFI returned error code 1: key generation failed: A required entitlement isn't present.

Test plan

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace --all-targets (all 269+ tests pass)

The Swift bridge previously swallowed CryptoKit exception details in
catch blocks, returning only numeric error codes (e.g. SE_ERR_GENERATE=1).
This made it impossible to diagnose why SE key operations failed on
managed devices.

Add enclaveapp_se_last_error() FFI function that exposes the last
CryptoKit/Security error string. Update all 7 catch blocks to call
setLastError() before returning, and update all Rust FFI error sites
(keychain.rs, sign.rs, encrypt.rs) to query and include the detail.
@jgowdy-godaddy jgowdy-godaddy merged commit 5c5a420 into main May 21, 2026
3 checks passed
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