Files
ShadowsocksX-NG/ShadowsocksX-NG2/Domain/Catalog/ServerLibraryStorage.swift
T
Qiu Yuzhou f9e95474e5 refactor: adopt age configuration storage
Replace the custom encrypted container with AgeSwift 0.1.0 so standard
age tools can inspect sensitive configuration independently of the app.

Use independent Keychain X25519 identities for catalog.age and
proxy-listening.age. Preserve atomic commits and confirmed recovery;
reject historical NG2 formats without migration or cleanup.
2026-10-21 14:31:32 +08:00

28 lines
951 B
Swift

import Foundation
typealias ServerLibraryError = EncryptedFileError
/// 服务器库专用载荷与密钥空间;使用标准 age 文件。
final class ServerLibraryStorage {
private let encrypted: EncryptedFileStorage<CatalogDocument>
init(keys: MasterKeyStoring = KeychainMasterKeyStore(namespace: "server-library.age")) {
encrypted = EncryptedFileStorage(
keys: keys, maximumSize: 64 * 1024 * 1024,
legacyFileNames: ["catalog.enc", "catalog.json"], makeDefault: { CatalogDocument() },
encode: CatalogFileStore.encode, decode: CatalogFileStore.decode)
}
func load(at url: URL, allowingInteraction: Bool) throws -> CatalogDocument {
try encrypted.load(at: url, allowingInteraction: allowingInteraction)
}
func save(_ document: CatalogDocument, at url: URL) throws {
try encrypted.save(document, at: url)
}
func reset(at url: URL) throws -> CatalogDocument {
try encrypted.reset(at: url)
}
}