secretive/Secretive/Views/SecretDetailView.swift

60 lines
1.8 KiB
Swift
Raw Normal View History

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
2020-09-22 06:12:50 +00:00
private let keyWriter = OpenSSHKeyWriter()
2020-03-04 07:14:38 +00:00
var body: some View {
2021-09-25 22:12:35 +00:00
ScrollView {
Form {
Section {
CopyableView(title: "SHA256 Fingerprint", image: Image(systemName: "touchid"), text: keyWriter.openSSHSHA256Fingerprint(secret: secret))
Spacer()
.frame(height: 20)
CopyableView(title: "MD5 Fingerprint", image: Image(systemName: "touchid"), text: keyWriter.openSSHMD5Fingerprint(secret: secret))
Spacer()
.frame(height: 20)
CopyableView(title: "Public Key", image: Image(systemName: "key"), text: keyString)
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 {
secret.name.replacingOccurrences(of: " ", with: "-")
2020-11-29 21:15:14 +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 {
2020-11-29 21:15:14 +00:00
keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)")
2020-03-04 07:14:38 +00:00
}
2020-09-22 06:12:50 +00:00
2020-03-04 07:14:38 +00:00
func copy() {
NSPasteboard.general.declareTypes([.string], owner: nil)
NSPasteboard.general.setString(keyString, forType: .string)
}
2020-09-22 06:12:50 +00:00
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