From 9a95bc66019d25f02a0a5f92a87e9405a52802e4 Mon Sep 17 00:00:00 2001 From: Pantelis Sampaziotis Date: Wed, 14 Oct 2020 21:28:01 +0200 Subject: [PATCH] Add Unwrap to SystemRootsError --- src/crypto/x509/verify.go | 2 ++ src/crypto/x509/verify_test.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go index cb8d8f872dd4d..5fdd4cb9fe1bb 100644 --- a/src/crypto/x509/verify.go +++ b/src/crypto/x509/verify.go @@ -187,6 +187,8 @@ func (se SystemRootsError) Error() string { return msg } +func (se SystemRootsError) Unwrap() error { return se.Err } + // errNotParsed is returned when a certificate without ASN.1 contents is // verified. Platform-specific verification needs the ASN.1 contents. var errNotParsed = errors.New("x509: missing ASN.1 contents; use ParseCertificate") diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go index c7a715bbcbb02..9cc17c7b3d89b 100644 --- a/src/crypto/x509/verify_test.go +++ b/src/crypto/x509/verify_test.go @@ -2005,3 +2005,11 @@ func TestSystemRootsError(t *testing.T) { t.Errorf("error was not SystemRootsError: %v", err) } } + +func TestSystemRootsErrorUnwrap(t *testing.T) { + var err1 = errors.New("err1") + err := SystemRootsError{Err: err1} + if !errors.Is(err, err1) { + t.Error("errors.Is failed, wanted success") + } +}