mirror of
https://github.com/maxgoedjen/secretive.git
synced 2025-09-08 05:20:57 +00:00
Factor out comment writer. (#651)
This commit is contained in:
parent
a0a632f245
commit
935ac32ea2
@ -90,7 +90,7 @@ extension Agent {
|
|||||||
for secret in secrets {
|
for secret in secrets {
|
||||||
let keyBlob = publicKeyWriter.data(secret: secret)
|
let keyBlob = publicKeyWriter.data(secret: secret)
|
||||||
keyData.append(keyBlob.lengthAndData)
|
keyData.append(keyBlob.lengthAndData)
|
||||||
keyData.append(secret.name.lengthAndData)
|
keyData.append(publicKeyWriter.comment(secret: secret).lengthAndData)
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if let (certificateData, name) = try? await certificateHandler.keyBlobAndName(for: secret) {
|
if let (certificateData, name) = try? await certificateHandler.keyBlobAndName(for: secret) {
|
||||||
|
@ -31,18 +31,7 @@ public struct OpenSSHPublicKeyWriter: Sendable {
|
|||||||
/// Generates an OpenSSH string representation of the secret.
|
/// Generates an OpenSSH string representation of the secret.
|
||||||
/// - Returns: OpenSSH string representation of the secret.
|
/// - Returns: OpenSSH string representation of the secret.
|
||||||
public func openSSHString<SecretType: Secret>(secret: SecretType) -> String {
|
public func openSSHString<SecretType: Secret>(secret: SecretType) -> String {
|
||||||
let resolvedComment: String
|
return [openSSHIdentifier(for: secret.keyType), data(secret: secret).base64EncodedString(), comment(secret: secret)]
|
||||||
if let comment = secret.publicKeyAttribution {
|
|
||||||
resolvedComment = comment
|
|
||||||
} else {
|
|
||||||
let dashedKeyName = secret.name.replacingOccurrences(of: " ", with: "-")
|
|
||||||
let dashedHostName = ["secretive", Host.current().localizedName, "local"]
|
|
||||||
.compactMap { $0 }
|
|
||||||
.joined(separator: ".")
|
|
||||||
.replacingOccurrences(of: " ", with: "-")
|
|
||||||
resolvedComment = "\(dashedKeyName)@\(dashedHostName)"
|
|
||||||
}
|
|
||||||
return [openSSHIdentifier(for: secret.keyType), data(secret: secret).base64EncodedString(), resolvedComment]
|
|
||||||
.compactMap { $0 }
|
.compactMap { $0 }
|
||||||
.joined(separator: " ")
|
.joined(separator: " ")
|
||||||
}
|
}
|
||||||
@ -65,6 +54,19 @@ public struct OpenSSHPublicKeyWriter: Sendable {
|
|||||||
.joined(separator: ":")
|
.joined(separator: ":")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func comment<SecretType: Secret>(secret: SecretType) -> String {
|
||||||
|
if let comment = secret.publicKeyAttribution {
|
||||||
|
return comment
|
||||||
|
} else {
|
||||||
|
let dashedKeyName = secret.name.replacingOccurrences(of: " ", with: "-")
|
||||||
|
let dashedHostName = ["secretive", Host.current().localizedName, "local"]
|
||||||
|
.compactMap { $0 }
|
||||||
|
.joined(separator: ".")
|
||||||
|
.replacingOccurrences(of: " ", with: "-")
|
||||||
|
return "\(dashedKeyName)@\(dashedHostName)"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension OpenSSHPublicKeyWriter {
|
extension OpenSSHPublicKeyWriter {
|
||||||
|
Loading…
Reference in New Issue
Block a user