From b89135777be7c2f123dbf2eea3c92a5402e4c63c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 3 Nov 2016 09:39:32 -0400 Subject: [PATCH] crypto/x509: expose UnknownAuthorityError.Cert This matches exposing CertificateInvalidError.Cert. and (exposing but not the spelling of) HostnameError.Certificate. Fixes #13519. Change-Id: Ifae9a09e063d642c09de3cdee8a728ff06d3a5df Reviewed-on: https://go-review.googlesource.com/32644 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/crypto/x509/verify.go | 2 +- src/crypto/x509/verify_test.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go index 6988ad7871..0d3de30bec 100644 --- a/src/crypto/x509/verify.go +++ b/src/crypto/x509/verify.go @@ -102,7 +102,7 @@ func (h HostnameError) Error() string { // UnknownAuthorityError results when the certificate issuer is unknown type UnknownAuthorityError struct { - cert *Certificate + Cert *Certificate // hintErr contains an error that may be helpful in determining why an // authority wasn't found. hintErr error diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go index 5a7481fea1..15c4091444 100644 --- a/src/crypto/x509/verify_test.go +++ b/src/crypto/x509/verify_test.go @@ -290,10 +290,15 @@ func expectUsageError(t *testing.T, i int, err error) (ok bool) { } func expectAuthorityUnknown(t *testing.T, i int, err error) (ok bool) { - if _, ok := err.(UnknownAuthorityError); !ok { + e, ok := err.(UnknownAuthorityError) + if !ok { t.Errorf("#%d: error was not UnknownAuthorityError: %s", i, err) return false } + if e.Cert == nil { + t.Errorf("#%d: error was UnknownAuthorityError, but missing Cert: %s", i, err) + return false + } return true } @@ -1284,7 +1289,7 @@ func TestUnknownAuthorityError(t *testing.T) { t.Errorf("#%d: Unable to parse certificate -> %s", i, err) } uae := &UnknownAuthorityError{ - cert: c, + Cert: c, hintErr: fmt.Errorf("empty"), hintCert: c, }