Just a code cleanup.
Change-Id: Ie887ab2c71de11b4844c4e6fd4e5aca3265ac3aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/583216
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
import (
"crypto/internal/boring/sig"
_ "crypto/internal/boring/syso"
+ "internal/stringslite"
"math/bits"
"unsafe"
)
// provided by runtime to avoid os import.
func runtime_arg0() string
-func hasSuffix(s, t string) bool {
- return len(s) > len(t) && s[len(s)-len(t):] == t
-}
-
// UnreachableExceptTests marks code that should be unreachable
// when BoringCrypto is in use. It panics.
func UnreachableExceptTests() {
name := runtime_arg0()
// If BoringCrypto ran on Windows we'd need to allow _test.exe and .test.exe as well.
- if !hasSuffix(name, "_test") && !hasSuffix(name, ".test") {
+ if !stringslite.HasSuffix(name, "_test") && !stringslite.HasSuffix(name, ".test") {
println("boringcrypto: unexpected code execution in", name)
panic("boringcrypto: invalid code execution")
}
// of the use of BoringCrypto.
package fipstls
-import "sync/atomic"
+import (
+ "internal/stringslite"
+ "sync/atomic"
+)
var required atomic.Bool
// and empty string for Windows (where runtime_arg0 can't easily find the name).
// Since this is an internal package, testing that this isn't used on the
// other operating systems should suffice to catch any mistakes.
- if !hasSuffix(name, "_test") && !hasSuffix(name, ".test") && name != "NaClMain" && name != "" {
+ if !stringslite.HasSuffix(name, "_test") && !stringslite.HasSuffix(name, ".test") && name != "NaClMain" && name != "" {
panic("fipstls: invalid use of Abandon in " + name)
}
required.Store(false)
// provided by runtime
func runtime_arg0() string
-func hasSuffix(s, t string) bool {
- return len(s) > len(t) && s[len(s)-len(t):] == t
-}
-
// Required reports whether FIPS-approved settings are required.
func Required() bool {
return required.Load()
import (
"errors"
+ "internal/stringslite"
"io"
"sync"
"syscall"
}
func isHangup(err error) bool {
- return err != nil && stringsHasSuffix(err.Error(), "Hangup")
+ return err != nil && stringslite.HasSuffix(err.Error(), "Hangup")
}
func isInterrupted(err error) bool {
- return err != nil && stringsHasSuffix(err.Error(), "interrupted")
+ return err != nil && stringslite.HasSuffix(err.Error(), "interrupted")
}
// IsPollDescriptor reports whether fd is the descriptor being used by the poller.
+++ /dev/null
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-//go:build plan9
-
-package poll
-
-// stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
-// suffix.
-func stringsHasSuffix(s, suffix string) bool {
- return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
-}
"errors"
"internal/bytealg"
"internal/godebug"
+ "internal/stringslite"
"io/fs"
"os"
"runtime"
}
// Canonicalize the hostname by removing any trailing dot.
- if stringsHasSuffix(hostname, ".") {
+ if stringslite.HasSuffix(hostname, ".") {
hostname = hostname[:len(hostname)-1]
}
return hostLookupCgo, dnsConf
}
continue
- case hostname != "" && stringsHasPrefix(src.source, "mdns"):
+ case hostname != "" && stringslite.HasPrefix(src.source, "mdns"):
if stringsHasSuffixFold(hostname, ".local") {
// Per RFC 6762, the ".local" TLD is special. And
// because Go's native resolver doesn't do mDNS or
import (
"errors"
"internal/itoa"
+ "internal/stringslite"
"os"
)
ifc.MTU = mtu
// Not a loopback device ("/dev/null") or packet interface (e.g. "pkt2")
- if stringsHasPrefix(device, netdir+"/") {
+ if stringslite.HasPrefix(device, netdir+"/") {
deviceaddrf, err := open(device + "/addr")
if err != nil {
return nil, err
"errors"
"internal/bytealg"
"internal/itoa"
+ "internal/stringslite"
"io"
"os"
)
}
func handlePlan9DNSError(err error, name string) error {
- if stringsHasSuffix(err.Error(), "dns: name does not exist") ||
- stringsHasSuffix(err.Error(), "dns: resource does not exist; negrcode 0") ||
- stringsHasSuffix(err.Error(), "dns: resource does not exist; negrcode") ||
- stringsHasSuffix(err.Error(), "dns failure") {
+ if stringslite.HasSuffix(err.Error(), "dns: name does not exist") ||
+ stringslite.HasSuffix(err.Error(), "dns: resource does not exist; negrcode 0") ||
+ stringslite.HasSuffix(err.Error(), "dns: resource does not exist; negrcode") ||
+ stringslite.HasSuffix(err.Error(), "dns failure") {
err = errNoSuchHost
}
return newDNSError(err, name, "")
func (*Resolver) lookupPortWithNetwork(ctx context.Context, network, errNetwork, service string) (port int, err error) {
lines, err := queryCS(ctx, network, "127.0.0.1", toLower(service))
if err != nil {
- if stringsHasSuffix(err.Error(), "can't translate service") {
+ if stringslite.HasSuffix(err.Error(), "can't translate service") {
return 0, &DNSError{Err: "unknown port", Name: errNetwork + "/" + service, IsNotFound: true}
}
return
lines, err := queryDNS(ctx, name, "cname")
if err != nil {
- if stringsHasSuffix(err.Error(), "dns failure") || stringsHasSuffix(err.Error(), "resource does not exist; negrcode 0") {
+ if stringslite.HasSuffix(err.Error(), "dns failure") || stringslite.HasSuffix(err.Error(), "resource does not exist; negrcode 0") {
return absDomainName(name), nil
}
return "", handlePlan9DNSError(err, cname)
return nil
}
-// stringsHasSuffix is strings.HasSuffix. It reports whether s ends in
-// suffix.
-func stringsHasSuffix(s, suffix string) bool {
- return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
-}
-
// stringsHasSuffixFold reports whether s ends in suffix,
// ASCII-case-insensitively.
func stringsHasSuffixFold(s, suffix string) bool {
return len(s) >= len(suffix) && stringsEqualFold(s[len(s)-len(suffix):], suffix)
}
-// stringsHasPrefix is strings.HasPrefix. It reports whether s begins with prefix.
-func stringsHasPrefix(s, prefix string) bool {
- return len(s) >= len(prefix) && s[:len(prefix)] == prefix
-}
-
// stringsEqualFold is strings.EqualFold, ASCII only. It reports whether s and t
// are equal, ASCII-case-insensitively.
func stringsEqualFold(s, t string) bool {