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)
|
2022-01-03 00:07:33 +00:00
|
|
|
CopyableView(title: "Public Key Contents", image: Image(systemName: "key"), text: keyString)
|
|
|
|
Spacer()
|
|
|
|
.frame(height: 20)
|
|
|
|
CopyableView(title: "Public Key Path", image: Image(systemName: "lock.doc"), text: "/Users/max/whatever")
|
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 {
|
2020-11-29 21:15:14 +00:00
|
|
|
keyWriter.openSSHString(secret: secret, comment: "\(dashedKeyName)@\(dashedHostName)")
|
2020-03-04 07:14:38 +00:00
|
|
|
}
|
2022-01-03 00:07:33 +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
|