Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
45 lines
1.7 KiB
Swift
45 lines
1.7 KiB
Swift
// Local simulation only. Creates an isolated key file; never touches Keychain.
|
|
import CryptoKit
|
|
import Foundation
|
|
|
|
let arguments = Array(CommandLine.arguments.dropFirst())
|
|
let usage = "Usage: swift sparkle_test_key.swift <test-key-directory>\n"
|
|
if arguments == ["--help"] || arguments == ["-h"] {
|
|
print(usage, terminator: "")
|
|
exit(0)
|
|
}
|
|
guard arguments.count == 1 else {
|
|
fputs(usage, stderr)
|
|
exit(2)
|
|
}
|
|
|
|
do {
|
|
let directory = URL(fileURLWithPath: arguments[0], isDirectory: true)
|
|
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true,
|
|
attributes: [.posixPermissions: 0o700])
|
|
let privateURL = directory.appendingPathComponent("private.key")
|
|
let key: Curve25519.Signing.PrivateKey
|
|
if FileManager.default.fileExists(atPath: privateURL.path) {
|
|
let encoded = try String(contentsOf: privateURL, encoding: .utf8)
|
|
guard let data = Data(base64Encoded: encoded) else {
|
|
fputs("Invalid test key file\n", stderr)
|
|
exit(1)
|
|
}
|
|
key = try Curve25519.Signing.PrivateKey(rawRepresentation: data)
|
|
} else {
|
|
key = Curve25519.Signing.PrivateKey()
|
|
guard FileManager.default.createFile(atPath: privateURL.path,
|
|
contents: key.rawRepresentation.base64EncodedData(),
|
|
attributes: [.posixPermissions: 0o600]) else {
|
|
fputs("Could not write test key file\n", stderr)
|
|
exit(1)
|
|
}
|
|
}
|
|
try key.publicKey.rawRepresentation.base64EncodedString().write(
|
|
to: directory.appendingPathComponent("public.key"), atomically: true, encoding: .utf8)
|
|
} catch {
|
|
// Do not print private key contents in diagnostics.
|
|
fputs("Could not create or read test key files\n", stderr)
|
|
exit(1)
|
|
}
|