Swift package
This page has the details of the polyjose Swift package that you don’t need to get started: what printing a record shows, how to wipe secret results, and which copies of secrets stay in memory. To install it and sign your first token, see Get started in Swift.
Secrets in records
Section titled “Secrets in records”-
Printing redacts secret fields.
String(describing:),String(reflecting:), string interpolation,print,debugPrintanddumpshow a secret field’s length only:<redacted, N chars>for aString,<redacted, N bytes>for aData, andnilwhen it is absent. The other fields print as usual. The redacted fields are:JwsSigner.keyandJweRecipient.keyJwsVerified.payloadandJwsVerifyOptions.detachedPayloadJweDecrypted.plaintextandaadJweEncryptOptions.aad; itsrecipientsprint redacted too.
The package’s own
Redaction.swiftdoes this; the generatedPolyjose.swiftis unchanged. -
Reading a field still gives the secret. Only the printed form changes, so don’t log a field itself.
-
JWT claims are not redacted (
JwtVerified.claims, also insideJwtNestedVerified). Put secrets in a JWE payload, not in claims. -
Wipe returned
Datawhen you are done with it. For example,result.payload.resetBytes(in: result.payload.indices)on avar.Datais copy-on-write, so this wipes the bytes only if no other copy shares them; wiping a copy leaves the original. SwiftStrings, such as keys and JWKs, can’t be wiped. -
Wiping returned
Datadoesn’t remove every copy. The generatedPolyjose.swiftcopies secret inputs (keys, payloads, plaintexts,aad,detachedPayload) and secret outputs (payload,plaintext,aad) through temporary Swift arrays, and frees them without wiping them. The Rust side of the call leaves unwiped copies on its own heap too, as the Kotlin library does, through the same generated interface layer. Your wipe reaches only theDatayou hold. Reading the freed memory needs access to your app’s process (a debugger, a core dump or a jailbroken device).
Secrets in memory covers what every platform does with secrets.