Add helpers to get fingerprint/hashes in byte form

This commit is contained in:
Andrew Ayer 2016-03-26 18:04:22 -07:00
parent ef395b8e60
commit 80bfe1321c
1 changed files with 18 additions and 2 deletions

View File

@ -71,9 +71,13 @@ func formatSerialNumber (serial *big.Int) string {
} }
} }
func sha256hex (data []byte) string { func sha256sum (data []byte) []byte {
sum := sha256.Sum256(data) sum := sha256.Sum256(data)
return hex.EncodeToString(sum[:]) return sum[:]
}
func sha256hex (data []byte) string {
return hex.EncodeToString(sha256sum(data))
} }
type EntryInfo struct { type EntryInfo struct {
@ -173,6 +177,10 @@ func (info *CertInfo) PubkeyHash () string {
return sha256hex(info.TBS.GetRawPublicKey()) return sha256hex(info.TBS.GetRawPublicKey())
} }
func (info *CertInfo) PubkeyHashBytes () []byte {
return sha256sum(info.TBS.GetRawPublicKey())
}
func (info *CertInfo) Environ () []string { func (info *CertInfo) Environ () []string {
env := make([]string, 0, 10) 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 { func (info *EntryInfo) typeString () string {
if info.IsPrecert { if info.IsPrecert {
return "precert" return "precert"