2020-03-04 07:14:38 +00:00
|
|
|
import SwiftUI
|
|
|
|
import SecretKit
|
|
|
|
|
|
|
|
struct SecretDetailView<SecretType: Secret>: View {
|
2020-09-22 06:12:50 +00:00
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
@State var secret: SecretType
|
2024-02-29 18:56:23 +00:00
|
|
|
@AppStorage("com.maxgoedjen.Secretive.commentStyle") var style: CommentStyle = .keyAndHost
|
2020-03-04 07:14:38 +00:00
|
|
|
|
2020-09-22 06:12:50 +00:00
|
|
|
private let keyWriter = OpenSSHKeyWriter()
|
2022-01-03 07:25:40 +00:00
|
|
|
private let publicKeyFileStoreController = PublicKeyFileStoreController(homeDirectory: NSHomeDirectory().replacingOccurrences(of: Bundle.main.hostBundleID, with: Bundle.main.agentBundleID))
|
2020-09-22 06:12:50 +00:00
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
var body: some View {
|
2021-09-25 22:12:35 +00:00
|
|
|
ScrollView {
|
|
|
|
Form {
|
|
|
|
Section {
|
2024-01-05 02:45:55 +00:00
|
|
|
CopyableView(title: "secret_detail_sha256_fingerprint_label", image: Image(systemName: "touchid"), text: keyWriter.openSSHSHA256Fingerprint(secret: secret))
|
2021-09-25 22:12:35 +00:00
|
|
|
Spacer()
|
|
|
|
.frame(height: 20)
|
2024-01-05 02:45:55 +00:00
|
|
|
CopyableView(title: "secret_detail_md5_fingerprint_label", image: Image(systemName: "touchid"), text: keyWriter.openSSHMD5Fingerprint(secret: secret))
|
2021-09-25 22:12:35 +00:00
|
|
|
Spacer()
|
|
|
|
.frame(height: 20)
|
2024-01-05 02:45:55 +00:00
|
|
|
CopyableView(title: "secret_detail_public_key_label", image: Image(systemName: "key"), text: keyString)
|
2022-01-03 07:25:40 +00:00
|
|
|
Spacer()
|
|
|
|
.frame(height: 20)
|
2024-01-05 02:45:55 +00:00
|
|
|
CopyableView(title: "secret_detail_public_key_path_label", image: Image(systemName: "lock.doc"), text: publicKeyFileStoreController.publicKeyPath(for: secret))
|
2021-09-25 22:12:35 +00:00
|
|
|
Spacer()
|
|
|
|
}
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2021-09-25 22:12:35 +00:00
|
|
|
.padding()
|
2020-09-22 06:12:50 +00:00
|
|
|
}
|
|
|
|
.frame(minHeight: 200, maxHeight: .infinity)
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2020-11-29 21:15:14 +00:00
|
|
|
|
|
|
|
var dashedKeyName: String {
|
2021-01-19 04:08:52 +00:00
|
|
|
secret.name.replacingOccurrences(of: " ", with: "-")
|
2020-11-29 21:15:14 +00:00
|
|
|
}
|
2021-01-19 04:08:52 +00:00
|
|
|
|
2020-11-29 21:15:14 +00:00
|
|
|
var dashedHostName: String {
|
|
|
|
["secretive", Host.current().localizedName, "local"]
|
|
|
|
.compactMap { $0 }
|
|
|
|
.joined(separator: ".")
|
|
|
|
.replacingOccurrences(of: " ", with: "-")
|
|
|
|
}
|
2020-09-22 06:12:50 +00:00
|
|
|
|
2020-03-04 07:14:38 +00:00
|
|
|
var keyString: String {
|
2024-02-29 18:56:23 +00:00
|
|
|
switch style {
|
|
|
|
case CommentStyle.none:
|
|
|
|
keyWriter.openSSHString(secret: secret, comment: "")
|
|
|
|
default:
|
|
|
|
keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)")
|
|
|
|
}
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-12 04:58:32 +00:00
|
|
|
|
2020-03-12 06:07:22 +00:00
|
|
|
#if DEBUG
|
|
|
|
|
2020-03-12 04:58:32 +00:00
|
|
|
struct SecretDetailView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
SecretDetailView(secret: Preview.Store(numberOfRandomSecrets: 1).secrets[0])
|
|
|
|
}
|
|
|
|
}
|
2020-03-12 06:07:22 +00:00
|
|
|
|
|
|
|
#endif
|