Files
keychain-kit/Sources/KeychainKit/Protocols/KeychainAccountProtocol.swift
2025-11-12 19:40:08 +02:00

54 lines
1.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// A type that describes a keychain account configuration for secure item storage and access.
///
/// Conforming types define metadata that determines how the keychain protects, authenticates, and
/// optionally synchronizes specific items.
///
/// ## Topics
///
/// ### Properties
///
/// - ``identifier``
/// - ``protection``
/// - ``accessFlags``
/// - ``synchronizable``
public protocol KeychainAccountProtocol: Sendable {
/// A unique string that identifies the keychain account.
var identifier: String { get }
/// The keychain data protection level assigned to the account.
///
/// Defaults to `kSecAttrAccessibleAfterFirstUnlock`. You can override this to use another
/// accessibility option, such as `kSecAttrAccessibleWhenUnlocked` or
/// `kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly`.
var protection: CFString { get }
/// The access control flags defining additional authentication requirements.
///
/// Defaults to an empty set (`[]`). Override this to enforce constraints like `.userPresence`,
/// `.biometryAny`, or `.devicePasscode`.
var accessFlags: SecAccessControlCreateFlags { get }
/// Indicates whether the item is synchronized through iCloud Keychain.
///
/// Defaults to `false`. Set this to `true` if the item should be available across all devices
/// associated with the same iCloud account.
var synchronizable: Bool { get }
}
public extension KeychainAccountProtocol {
var protection: CFString { kSecAttrAccessibleAfterFirstUnlock }
var accessFlags: SecAccessControlCreateFlags { [] }
var synchronizable: Bool { false }
}
public extension KeychainAccountProtocol where Self: RawRepresentable, Self.RawValue == String {
/// A unique string that identifies the keychain account.
///
/// Derived from the instances raw string value.
var identifier: String { rawValue }
}