// A code-hosting token left in this phone's Keychain by an old build, and the// one thing left to do about it.//// Access tokens live in `cotton_secrets` now — sealed under the workspace key,// so the Mac that serves you can read a repository while this phone is asleep// — and nothing reads the slots the old build wrote. This is the// `ByokLegacyKeychain` shape, for the same reason and with the same shape of// argument: what is being cleaned up is a SECRET rather than a feature, so a// forget and nothing else.//// **THE SLOTS CANNOT BE ENUMERATED, so the INDEX is read first.** The old store// kept one slot per host (`cotton.codehost.<host>`) and an index slot naming// which hosts it held, precisely because the Keychain answers no listing. The// index is what makes a complete forget possible; a corrupt one costs// completeness, not safety, so the index slot is deleted whatever happened to// its contents.//// There is no read and no migration into `cotton_secrets`: the value would// have to cross the boundary again, and a person can paste a token once.importCottonKitimportFoundationpublicenumCodeHostingLegacyKeychain {/// The slot the old store listed its hosts in.publicstaticlet indexSlot = "cotton.codehost.index"/// The slot one host's token sat in.publicstaticfunc slot(for host: String) -> String {"cotton.codehost.\(host.lowercased())" }/// The hosts the index names, or none when it cannot be read.staticfunc indexedHosts(in store: any SecretStore) -> [String] {guardlet raw = store.read(indexSlot),let data = raw.data(using: .utf8),let parsed = try? JSONSerialization.jsonObject(with: data) as? [Any]else { return [] }return parsed.compactMap { $0 as? String } }/// Delete every slot the index names, and the index. Idempotent, silent,/// and safe to call on every launch — `SecItemDelete` on a slot that is not/// there is not an error.////// Off the main thread: `SecretStore.swift`'s header refuses a Keychain/// call on it, because a SecurityAgent prompt blocks the whole app.publicstaticfunc forget(in store: any SecretStore = KeychainSecretStore()) async {awaitTask.detached(priority: .utility) {for host in indexedHosts(in: store) { store.forget(slot(for: host)) } store.forget(indexSlot) } .value }}