From 80bfe1321c946192e154dd5d03d28bee88b57622 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sat, 26 Mar 2016 18:04:22 -0700 Subject: [PATCH] Add helpers to get fingerprint/hashes in byte form --- helpers.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/helpers.go b/helpers.go index 6d8e209..d8a6a73 100644 --- a/helpers.go +++ b/helpers.go @@ -71,9 +71,13 @@ func formatSerialNumber (serial *big.Int) string { } } -func sha256hex (data []byte) string { +func sha256sum (data []byte) []byte { sum := sha256.Sum256(data) - return hex.EncodeToString(sum[:]) + return sum[:] +} + +func sha256hex (data []byte) string { + return hex.EncodeToString(sha256sum(data)) } type EntryInfo struct { @@ -173,6 +177,10 @@ func (info *CertInfo) PubkeyHash () string { return sha256hex(info.TBS.GetRawPublicKey()) } +func (info *CertInfo) PubkeyHashBytes () []byte { + return sha256sum(info.TBS.GetRawPublicKey()) +} + func (info *CertInfo) Environ () []string { env := make([]string, 0, 10) @@ -232,6 +240,14 @@ func (info *EntryInfo) Fingerprint () string { } } +func (info *EntryInfo) FingerprintBytes () []byte { + if len(info.FullChain) > 0 { + return sha256sum(info.FullChain[0]) + } else { + return []byte{} + } +} + func (info *EntryInfo) typeString () string { if info.IsPrecert { return "precert"