diff --git a/src/crypto/internal/fips140cache/cache_test.go b/src/crypto/internal/fips140cache/cache_test.go
index 5f91397..103247e 100644
--- a/src/crypto/internal/fips140cache/cache_test.go
+++ b/src/crypto/internal/fips140cache/cache_test.go
@@ -8,6 +8,7 @@
"context"
"errors"
"runtime"
+ "slices"
"sync"
"testing"
"time"
@@ -127,10 +128,8 @@
if err != nil {
t.Fatal(err)
}
- for _, w := range want {
- if v == w {
- return
- }
+ if slices.Contains(want, v) {
+ return
}
t.Errorf("got %p, want %p", v, want)
}
diff --git a/src/crypto/rsa/pkcs1v15_test.go b/src/crypto/rsa/pkcs1v15_test.go
index c65552c..07f553b 100644
--- a/src/crypto/rsa/pkcs1v15_test.go
+++ b/src/crypto/rsa/pkcs1v15_test.go
@@ -16,6 +16,7 @@
"encoding/hex"
"encoding/pem"
"io"
+ "slices"
"testing"
"testing/quick"
)
@@ -180,11 +181,9 @@
if err != nil {
t.Errorf("returned error: %s", err)
}
- for _, b := range b {
- if b == 0 {
- t.Errorf("Zero octet found")
- return
- }
+ if slices.Contains(b, 0) {
+ t.Errorf("Zero octet found")
+ return
}
}
diff --git a/src/crypto/tls/cipher_suites.go b/src/crypto/tls/cipher_suites.go
index 6ed63cc..3434f51 100644
--- a/src/crypto/tls/cipher_suites.go
+++ b/src/crypto/tls/cipher_suites.go
@@ -20,6 +20,7 @@
"hash"
"internal/cpu"
"runtime"
+ "slices"
_ "unsafe" // for linkname
"golang.org/x/crypto/chacha20poly1305"
@@ -182,10 +183,8 @@
continue
}
- for _, suppID := range supportedIDs {
- if id == suppID {
- return candidate
- }
+ if slices.Contains(supportedIDs, id) {
+ return candidate
}
}
return nil
diff --git a/src/crypto/tls/handshake_client.go b/src/crypto/tls/handshake_client.go
index c2b1b70..5282138 100644
--- a/src/crypto/tls/handshake_client.go
+++ b/src/crypto/tls/handshake_client.go
@@ -386,13 +386,7 @@
session = cs.session
// Check that version used for the previous session is still valid.
- versOk := false
- for _, v := range hello.supportedVersions {
- if v == session.version {
- versOk = true
- break
- }
- }
+ versOk := slices.Contains(hello.supportedVersions, session.version)
if !versOk {
return nil, nil, nil, nil
}
@@ -463,11 +457,8 @@
// For 0-RTT, the cipher suite has to match exactly, and we need to be
// offering the same ALPN.
if session.EarlyData && mutualCipherSuiteTLS13(hello.cipherSuites, session.cipherSuite) != nil {
- for _, alpn := range hello.alpnProtocols {
- if alpn == session.alpnProtocol {
- hello.earlyData = true
- break
- }
+ if slices.Contains(hello.alpnProtocols, session.alpnProtocol) {
+ hello.earlyData = true
}
}
}
@@ -963,10 +954,8 @@
if len(clientProtos) == 0 {
return errors.New("tls: server advertised unrequested ALPN extension")
}
- for _, proto := range clientProtos {
- if proto == serverProto {
- return nil
- }
+ if slices.Contains(clientProtos, serverProto) {
+ return nil
}
return errors.New("tls: server selected unadvertised ALPN protocol")
}
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
index fcc9149..7c3f706 100644
--- a/src/crypto/tls/handshake_client_test.go
+++ b/src/crypto/tls/handshake_client_test.go
@@ -28,6 +28,7 @@
"path/filepath"
"reflect"
"runtime"
+ "slices"
"strconv"
"strings"
"testing"
@@ -218,13 +219,7 @@
}
if test.numRenegotiations > 0 || test.sendKeyUpdate {
- found := false
- for _, flag := range command[1:] {
- if flag == "-state" {
- found = true
- break
- }
- }
+ found := slices.Contains(command[1:], "-state")
if !found {
panic("-state flag missing to OpenSSL, you need this if testing renegotiation or KeyUpdate")
diff --git a/src/crypto/tls/handshake_server.go b/src/crypto/tls/handshake_server.go
index efdaeae..3488a81 100644
--- a/src/crypto/tls/handshake_server.go
+++ b/src/crypto/tls/handshake_server.go
@@ -17,6 +17,7 @@
"fmt"
"hash"
"io"
+ "slices"
"time"
)
@@ -222,14 +223,7 @@
hs.hello = new(serverHelloMsg)
hs.hello.vers = c.vers
- foundCompression := false
- // We only support null compression, so check that the client offered it.
- for _, compression := range hs.clientHello.compressionMethods {
- if compression == compressionNone {
- foundCompression = true
- break
- }
- }
+ foundCompression := slices.Contains(hs.clientHello.compressionMethods, compressionNone)
if !foundCompression {
c.sendAlert(alertIllegalParameter)
@@ -493,14 +487,7 @@
return nil
}
- cipherSuiteOk := false
- // Check that the client is still offering the ciphersuite in the session.
- for _, id := range hs.clientHello.cipherSuites {
- if id == sessionState.cipherSuite {
- cipherSuiteOk = true
- break
- }
- }
+ cipherSuiteOk := slices.Contains(hs.clientHello.cipherSuites, sessionState.cipherSuite)
if !cipherSuiteOk {
return nil
}
diff --git a/src/crypto/tls/handshake_server_tls13.go b/src/crypto/tls/handshake_server_tls13.go
index b066924..a224db9 100644
--- a/src/crypto/tls/handshake_server_tls13.go
+++ b/src/crypto/tls/handshake_server_tls13.go
@@ -295,13 +295,7 @@
return nil
}
- modeOK := false
- for _, mode := range hs.clientHello.pskModes {
- if mode == pskModeDHE {
- modeOK = true
- break
- }
- }
+ modeOK := slices.Contains(hs.clientHello.pskModes, pskModeDHE)
if !modeOK {
return nil
}
diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go
index 1301390..175ab05 100644
--- a/src/crypto/x509/verify.go
+++ b/src/crypto/x509/verify.go
@@ -599,14 +599,7 @@
}
}
- anyKeyUsage := false
- for _, eku := range opts.KeyUsages {
- if eku == ExtKeyUsageAny {
- // The presence of anyExtendedKeyUsage overrides any other key usage.
- anyKeyUsage = true
- break
- }
- }
+ anyKeyUsage := slices.Contains(opts.KeyUsages, ExtKeyUsageAny)
if len(opts.KeyUsages) == 0 {
opts.KeyUsages = []ExtKeyUsage{ExtKeyUsageServerAuth}
@@ -929,10 +922,8 @@
if ip := net.ParseIP(candidateIP); ip != nil {
// We only match IP addresses against IP SANs.
// See RFC 6125, Appendix B.2.
- for _, candidate := range c.IPAddresses {
- if ip.Equal(candidate) {
- return nil
- }
+ if slices.ContainsFunc(c.IPAddresses, ip.Equal) {
+ return nil
}
return HostnameError{c, candidateIP}
}
diff --git a/src/debug/buildinfo/buildinfo_test.go b/src/debug/buildinfo/buildinfo_test.go
index ceab14e..7932529 100644
--- a/src/debug/buildinfo/buildinfo_test.go
+++ b/src/debug/buildinfo/buildinfo_test.go
@@ -19,6 +19,7 @@
"path/filepath"
"regexp"
"runtime"
+ "slices"
"strings"
"testing"
)
@@ -46,13 +47,7 @@
{"windows", "amd64"},
}
runtimePlatform := platform{runtime.GOOS, runtime.GOARCH}
- haveRuntimePlatform := false
- for _, p := range platforms {
- if p == runtimePlatform {
- haveRuntimePlatform = true
- break
- }
- }
+ haveRuntimePlatform := slices.Contains(platforms, runtimePlatform)
if !haveRuntimePlatform {
platforms = append(platforms, runtimePlatform)
}
diff --git a/src/internal/fuzz/fuzz.go b/src/internal/fuzz/fuzz.go
index e406c8c..092bf5b 100644
--- a/src/internal/fuzz/fuzz.go
+++ b/src/internal/fuzz/fuzz.go
@@ -20,6 +20,7 @@
"path/filepath"
"reflect"
"runtime"
+ "slices"
"strings"
"time"
)
@@ -672,11 +673,8 @@
return nil, err
}
if opts.MinimizeLimit > 0 || opts.MinimizeTimeout > 0 {
- for _, t := range opts.Types {
- if isMinimizable(t) {
- c.minimizationAllowed = true
- break
- }
+ if slices.ContainsFunc(opts.Types, isMinimizable) {
+ c.minimizationAllowed = true
}
}
diff --git a/src/internal/profile/merge.go b/src/internal/profile/merge.go
index 3ea7d4c..36114d5 100644
--- a/src/internal/profile/merge.go
+++ b/src/internal/profile/merge.go
@@ -6,6 +6,7 @@
import (
"fmt"
+ "slices"
"sort"
"strconv"
"strings"
@@ -56,12 +57,10 @@
}
}
- for _, s := range p.Sample {
- if isZeroSample(s) {
- // If there are any zero samples, re-merge the profile to GC
- // them.
- return Merge([]*Profile{p})
- }
+ if slices.ContainsFunc(p.Sample, isZeroSample) {
+ // If there are any zero samples, re-merge the profile to GC
+ // them.
+ return Merge([]*Profile{p})
}
return p, nil
diff --git a/src/log/slog/handler_test.go b/src/log/slog/handler_test.go
index 265bbd6..00befa0 100644
--- a/src/log/slog/handler_test.go
+++ b/src/log/slog/handler_test.go
@@ -588,10 +588,8 @@
// that removes all Attrs with the given keys.
func removeKeys(keys ...string) func([]string, Attr) Attr {
return func(_ []string, a Attr) Attr {
- for _, k := range keys {
- if a.Key == k {
- return Attr{}
- }
+ if slices.Contains(keys, a.Key) {
+ return Attr{}
}
return a
}
diff --git a/src/mime/type.go b/src/mime/type.go
index 58cc22f..f45bf4f 100644
--- a/src/mime/type.go
+++ b/src/mime/type.go
@@ -258,10 +258,8 @@
if ei, ok := extensions.Load(justType); ok {
exts = ei.([]string)
}
- for _, v := range exts {
- if v == extLower {
- return nil
- }
+ if slices.Contains(exts, extLower) {
+ return nil
}
extensions.Store(justType, append(exts, extLower))
return nil
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
index b74dfb7..a90ccfb 100644
--- a/src/text/template/parse/parse.go
+++ b/src/text/template/parse/parse.go
@@ -12,6 +12,7 @@
"bytes"
"fmt"
"runtime"
+ "slices"
"strconv"
"strings"
)
@@ -839,10 +840,8 @@
// variable is not defined.
func (t *Tree) useVar(pos Pos, name string) Node {
v := t.newVariable(pos, name)
- for _, varName := range t.vars {
- if varName == v.Ident[0] {
- return v
- }
+ if slices.Contains(t.vars, v.Ident[0]) {
+ return v
}
t.errorf("undefined variable %q", v.Ident[0])
return nil