aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/tls
diff options
context:
space:
mode:
authorJulien Cretel <jub0bsinthecloud@gmail.com>2025-10-01 20:08:18 +0000
committerGopher Robot <gobot@golang.org>2025-10-13 10:12:48 -0700
commit6bcd97d9f4386528aa85eb3cc27da0ed902de870 (patch)
tree54acec806440b95e7afc493d42b0b095fdaee1a5 /src/crypto/tls
parent1cd71689f2ed8f07031a0cc58fc3586ca501839f (diff)
downloadgo-6bcd97d9f4386528aa85eb3cc27da0ed902de870.tar.xz
all: replace calls to errors.As with errors.AsType
This change replaces most occurrences (in code as well as in comments) of errors.As with errors.AsType. It leaves the errors package and vendored code untouched. Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a GitHub-Last-Rev: 8aaaa36a5a12d2a6a90c6d51680464e1a3115139 GitHub-Pull-Request: golang/go#75698 Reviewed-on: https://go-review.googlesource.com/c/go/+/708495 Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/crypto/tls')
-rw-r--r--src/crypto/tls/conn.go4
-rw-r--r--src/crypto/tls/handshake_server.go5
-rw-r--r--src/crypto/tls/handshake_server_test.go3
-rw-r--r--src/crypto/tls/quic.go7
-rw-r--r--src/crypto/tls/quic_test.go3
5 files changed, 9 insertions, 13 deletions
diff --git a/src/crypto/tls/conn.go b/src/crypto/tls/conn.go
index 09dc9ea94c..2de120a132 100644
--- a/src/crypto/tls/conn.go
+++ b/src/crypto/tls/conn.go
@@ -1578,9 +1578,9 @@ func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
// the handshake (RFC 9001, Section 5.7).
c.quicSetReadSecret(QUICEncryptionLevelApplication, c.cipherSuite, c.in.trafficSecret)
} else {
- var a alert
c.out.Lock()
- if !errors.As(c.out.err, &a) {
+ a, ok := errors.AsType[alert](c.out.err)
+ if !ok {
a = alertInternalError
}
c.out.Unlock()
diff --git a/src/crypto/tls/handshake_server.go b/src/crypto/tls/handshake_server.go
index 088c66fadb..a2cf176a86 100644
--- a/src/crypto/tls/handshake_server.go
+++ b/src/crypto/tls/handshake_server.go
@@ -965,10 +965,9 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
chains, err := certs[0].Verify(opts)
if err != nil {
- var errCertificateInvalid x509.CertificateInvalidError
- if errors.As(err, &x509.UnknownAuthorityError{}) {
+ if _, ok := errors.AsType[x509.UnknownAuthorityError](err); ok {
c.sendAlert(alertUnknownCA)
- } else if errors.As(err, &errCertificateInvalid) && errCertificateInvalid.Reason == x509.Expired {
+ } else if errCertificateInvalid, ok := errors.AsType[x509.CertificateInvalidError](err); ok && errCertificateInvalid.Reason == x509.Expired {
c.sendAlert(alertCertificateExpired)
} else {
c.sendAlert(alertBadCertificate)
diff --git a/src/crypto/tls/handshake_server_test.go b/src/crypto/tls/handshake_server_test.go
index 941f2a3373..43183db2a1 100644
--- a/src/crypto/tls/handshake_server_test.go
+++ b/src/crypto/tls/handshake_server_test.go
@@ -403,8 +403,7 @@ func TestAlertForwarding(t *testing.T) {
err := Server(s, testConfig).Handshake()
s.Close()
- var opErr *net.OpError
- if !errors.As(err, &opErr) || opErr.Err != error(alertUnknownCA) {
+ if opErr, ok := errors.AsType[*net.OpError](err); !ok || opErr.Err != error(alertUnknownCA) {
t.Errorf("Got error: %s; expected: %s", err, error(alertUnknownCA))
}
}
diff --git a/src/crypto/tls/quic.go b/src/crypto/tls/quic.go
index 3be479eb12..2ba2242b2d 100644
--- a/src/crypto/tls/quic.go
+++ b/src/crypto/tls/quic.go
@@ -362,12 +362,11 @@ func quicError(err error) error {
if err == nil {
return nil
}
- var ae AlertError
- if errors.As(err, &ae) {
+ if _, ok := errors.AsType[AlertError](err); ok {
return err
}
- var a alert
- if !errors.As(err, &a) {
+ a, ok := errors.AsType[alert](err)
+ if !ok {
a = alertInternalError
}
// Return an error wrapping the original error and an AlertError.
diff --git a/src/crypto/tls/quic_test.go b/src/crypto/tls/quic_test.go
index f6e8c55d9d..5f4b2b7707 100644
--- a/src/crypto/tls/quic_test.go
+++ b/src/crypto/tls/quic_test.go
@@ -368,8 +368,7 @@ func TestQUICHandshakeError(t *testing.T) {
if !errors.Is(err, AlertError(alertBadCertificate)) {
t.Errorf("connection handshake terminated with error %q, want alertBadCertificate", err)
}
- var e *CertificateVerificationError
- if !errors.As(err, &e) {
+ if _, ok := errors.AsType[*CertificateVerificationError](err); !ok {
t.Errorf("connection handshake terminated with error %q, want CertificateVerificationError", err)
}
}