aboutsummaryrefslogtreecommitdiff
path: root/tofu.go
diff options
context:
space:
mode:
Diffstat (limited to 'tofu.go')
-rw-r--r--tofu.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/tofu.go b/tofu.go
index df0bec9..30ec6a2 100644
--- a/tofu.go
+++ b/tofu.go
@@ -71,9 +71,18 @@ type KnownHost struct {
Expires int64 // unix time of certificate notAfter date
}
+func NewKnownHost(cert *x509.Certificate) KnownHost {
+ return KnownHost{
+ Hostname: cert.Subject.CommonName,
+ Algorithm: "SHA-512",
+ Fingerprint: Fingerprint(cert),
+ Expires: cert.NotAfter.Unix(),
+ }
+}
+
// Write writes the known host to the provided io.Writer.
func (k KnownHost) Write(w io.Writer) (int, error) {
- s := fmt.Sprintf("\n%s %s %s %d", k.Hostname, k.Algorithm, k.Fingerprint, k.Expires)
+ s := fmt.Sprintf("%s %s %s %d\n", k.Hostname, k.Algorithm, k.Fingerprint, k.Expires)
return w.Write([]byte(s))
}