security-rs
Safe Rust bindings for Apple's Security framework on macOS.
Status: v0.2.1 extends the Swift-bridge-backed safe API with access-control creation, Security item import/export, raw key import, modern signatures, and generic policy property builders.
Highlights
- Swift bridge over
Security.frameworkwith retained opaque handles and ergonomic Rust wrappers. - Raw C FFI preserved behind the
raw-ffiCargo feature. - Safe modules for all primary logical areas:
keychainidentitycertificatekeypolicytrustauthorizationcoderandom_bytestransformsecure_transportcmskey_derivationkey_agreement
- 14 numbered headless examples plus smoke tests across every area.
Quick start
use *;
Area overview
Keychain: generic-password CRUD, service account listing, and access-control creation.Identity: PKCS#12 import, certificate access, and private-key attribute inspection.Certificate: DER/PEM loading, Security item import/export, summaries, names, emails, serials, validity dates, and public keys.Key: raw/private-key import plus modern signing and signature verification helpers.Policy/Trust: basic X.509, SSL, revocation, generic property builders, custom anchors, and evaluated trust results.Authorization: authorization creation and external-form round trips.Code: current-process code objects, static-code inspection, designated requirements, and task entitlements.RandomBytes:SecRandomCopyByteswrappers.Transform: base64 encode/decode using deprecated but still functionalSecTransformAPIs.SecureTransport: minimal context creation, protocol bounds, and state inspection.CMS: certificate-bag encode/decode.KeyDerivation: PBKDF2-style symmetric-key derivation throughSecKeyDeriveFromPassword.KeyAgreement: ephemeral P-256 key generation and ECDH shared-secret derivation.
Examples
Run every numbered example:
for; do ; done
Key examples:
01_keychain_password05_trust_evaluate07_code_signing_info11_cms_cert_bag13_key_agreement_shared_secret14_key_import_sign_verify
Raw FFI
Enable the legacy raw C declarations when you need direct Security.framework symbols:
The default API path stays on the Swift bridge so Rust code does not call the C-only framework surface directly.
Coverage notes
See COVERAGE.md for the header audit and per-area implementation / partial / skipped status.
License
Licensed under either of Apache-2.0 or MIT at your option.