updated dependencies
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2023-03-17 13:17:43 +01:00
parent 2967465193
commit 2523b32d19
36 changed files with 693 additions and 403 deletions

10
go.mod
View File

@ -1,20 +1,20 @@
module git.paulbsd.com/paulbsd/coronafana module git.paulbsd.com/paulbsd/coronafana
go 1.19 go 1.20
require ( require (
github.com/cretz/bine v0.2.0 github.com/cretz/bine v0.2.0
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/denisenkom/go-mssqldb v0.12.3 // indirect github.com/denisenkom/go-mssqldb v0.12.3 // indirect
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.7.0
github.com/jinzhu/gorm v1.9.16 github.com/jinzhu/gorm v1.9.16
github.com/jinzhu/now v1.1.5 // indirect github.com/jinzhu/now v1.1.5 // indirect
github.com/jmoiron/sqlx v1.3.5 github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.7 // indirect github.com/lib/pq v1.10.7 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
golang.org/x/crypto v0.1.0 // indirect golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.1.0 // indirect golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.1.0 // indirect golang.org/x/sys v0.6.0 // indirect
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )

8
go.sum
View File

@ -17,6 +17,8 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
@ -53,6 +55,8 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@ -63,6 +67,8 @@ golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0= golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -71,6 +77,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@ -23,6 +23,7 @@ Asta Xie <xiemengjun at gmail.com>
Bulat Gaifullin <gaifullinbf at gmail.com> Bulat Gaifullin <gaifullinbf at gmail.com>
Caine Jette <jette at alum.mit.edu> Caine Jette <jette at alum.mit.edu>
Carlos Nieto <jose.carlos at menteslibres.net> Carlos Nieto <jose.carlos at menteslibres.net>
Chris Kirkland <chriskirkland at github.com>
Chris Moos <chris at tech9computers.com> Chris Moos <chris at tech9computers.com>
Craig Wilson <craiggwilson at gmail.com> Craig Wilson <craiggwilson at gmail.com>
Daniel Montoya <dsmontoyam at gmail.com> Daniel Montoya <dsmontoyam at gmail.com>
@ -45,6 +46,7 @@ Ilia Cimpoes <ichimpoesh at gmail.com>
INADA Naoki <songofacandy at gmail.com> INADA Naoki <songofacandy at gmail.com>
Jacek Szwec <szwec.jacek at gmail.com> Jacek Szwec <szwec.jacek at gmail.com>
James Harr <james.harr at gmail.com> James Harr <james.harr at gmail.com>
Janek Vedock <janekvedock at comcast.net>
Jeff Hodges <jeff at somethingsimilar.com> Jeff Hodges <jeff at somethingsimilar.com>
Jeffrey Charles <jeffreycharles at gmail.com> Jeffrey Charles <jeffreycharles at gmail.com>
Jerome Meyer <jxmeyer at gmail.com> Jerome Meyer <jxmeyer at gmail.com>
@ -59,12 +61,14 @@ Kamil Dziedzic <kamil at klecza.pl>
Kei Kamikawa <x00.x7f.x86 at gmail.com> Kei Kamikawa <x00.x7f.x86 at gmail.com>
Kevin Malachowski <kevin at chowski.com> Kevin Malachowski <kevin at chowski.com>
Kieron Woodhouse <kieron.woodhouse at infosum.com> Kieron Woodhouse <kieron.woodhouse at infosum.com>
Lance Tian <lance6716 at gmail.com>
Lennart Rudolph <lrudolph at hmc.edu> Lennart Rudolph <lrudolph at hmc.edu>
Leonardo YongUk Kim <dalinaum at gmail.com> Leonardo YongUk Kim <dalinaum at gmail.com>
Linh Tran Tuan <linhduonggnu at gmail.com> Linh Tran Tuan <linhduonggnu at gmail.com>
Lion Yang <lion at aosc.xyz> Lion Yang <lion at aosc.xyz>
Luca Looz <luca.looz92 at gmail.com> Luca Looz <luca.looz92 at gmail.com>
Lucas Liu <extrafliu at gmail.com> Lucas Liu <extrafliu at gmail.com>
Lunny Xiao <xiaolunwen at gmail.com>
Luke Scott <luke at webconnex.com> Luke Scott <luke at webconnex.com>
Maciej Zimnoch <maciej.zimnoch at codilime.com> Maciej Zimnoch <maciej.zimnoch at codilime.com>
Michael Woolnough <michael.woolnough at gmail.com> Michael Woolnough <michael.woolnough at gmail.com>
@ -79,6 +83,7 @@ Reed Allman <rdallman10 at gmail.com>
Richard Wilkes <wilkes at me.com> Richard Wilkes <wilkes at me.com>
Robert Russell <robert at rrbrussell.com> Robert Russell <robert at rrbrussell.com>
Runrioter Wung <runrioter at gmail.com> Runrioter Wung <runrioter at gmail.com>
Santhosh Kumar Tekuri <santhosh.tekuri at gmail.com>
Sho Iizuka <sho.i518 at gmail.com> Sho Iizuka <sho.i518 at gmail.com>
Sho Ikeda <suicaicoca at gmail.com> Sho Ikeda <suicaicoca at gmail.com>
Shuode Li <elemount at qq.com> Shuode Li <elemount at qq.com>
@ -99,12 +104,14 @@ Xiuming Chen <cc at cxm.cc>
Xuehong Chan <chanxuehong at gmail.com> Xuehong Chan <chanxuehong at gmail.com>
Zhenye Xie <xiezhenye at gmail.com> Zhenye Xie <xiezhenye at gmail.com>
Zhixin Wen <john.wenzhixin at gmail.com> Zhixin Wen <john.wenzhixin at gmail.com>
Ziheng Lyu <zihenglv at gmail.com>
# Organizations # Organizations
Barracuda Networks, Inc. Barracuda Networks, Inc.
Counting Ltd. Counting Ltd.
DigitalOcean Inc. DigitalOcean Inc.
dyves labs AG
Facebook Inc. Facebook Inc.
GitHub Inc. GitHub Inc.
Google Inc. Google Inc.

View File

@ -1,3 +1,24 @@
## Version 1.7 (2022-11-29)
Changes:
- Drop support of Go 1.12 (#1211)
- Refactoring `(*textRows).readRow` in a more clear way (#1230)
- util: Reduce boundary check in escape functions. (#1316)
- enhancement for mysqlConn handleAuthResult (#1250)
New Features:
- support Is comparison on MySQLError (#1210)
- return unsigned in database type name when necessary (#1238)
- Add API to express like a --ssl-mode=PREFERRED MySQL client (#1370)
- Add SQLState to MySQLError (#1321)
Bugfixes:
- Fix parsing 0 year. (#1257)
## Version 1.6 (2021-04-01) ## Version 1.6 (2021-04-01)
Changes: Changes:

View File

@ -40,7 +40,7 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac
* Optional placeholder interpolation * Optional placeholder interpolation
## Requirements ## Requirements
* Go 1.10 or higher. We aim to support the 3 latest versions of Go. * Go 1.13 or higher. We aim to support the 3 latest versions of Go.
* MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+) * MySQL (4.1+), MariaDB, Percona Server, Google CloudSQL or Sphinx (2.2.3+)
--------------------------------------- ---------------------------------------
@ -85,7 +85,7 @@ db.SetMaxIdleConns(10)
`db.SetMaxOpenConns()` is highly recommended to limit the number of connection used by the application. There is no recommended limit number because it depends on application and MySQL server. `db.SetMaxOpenConns()` is highly recommended to limit the number of connection used by the application. There is no recommended limit number because it depends on application and MySQL server.
`db.SetMaxIdleConns()` is recommended to be set same to (or greater than) `db.SetMaxOpenConns()`. When it is smaller than `SetMaxOpenConns()`, connections can be opened and closed very frequently than you expect. Idle connections can be closed by the `db.SetConnMaxLifetime()`. If you want to close idle connections more rapidly, you can use `db.SetConnMaxIdleTime()` since Go 1.15. `db.SetMaxIdleConns()` is recommended to be set same to `db.SetMaxOpenConns()`. When it is smaller than `SetMaxOpenConns()`, connections can be opened and closed much more frequently than you expect. Idle connections can be closed by the `db.SetConnMaxLifetime()`. If you want to close idle connections more rapidly, you can use `db.SetConnMaxIdleTime()` since Go 1.15.
### DSN (Data Source Name) ### DSN (Data Source Name)
@ -157,6 +157,17 @@ Default: false
`allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network. `allowCleartextPasswords=true` allows using the [cleartext client side plugin](https://dev.mysql.com/doc/en/cleartext-pluggable-authentication.html) if required by an account, such as one defined with the [PAM authentication plugin](http://dev.mysql.com/doc/en/pam-authentication-plugin.html). Sending passwords in clear text may be a security problem in some configurations. To avoid problems if there is any possibility that the password would be intercepted, clients should connect to MySQL Server using a method that protects the password. Possibilities include [TLS / SSL](#tls), IPsec, or a private network.
##### `allowFallbackToPlaintext`
```
Type: bool
Valid Values: true, false
Default: false
```
`allowFallbackToPlaintext=true` acts like a `--ssl-mode=PREFERRED` MySQL client as described in [Command Options for Connecting to the Server](https://dev.mysql.com/doc/refman/5.7/en/connection-options.html#option_general_ssl-mode)
##### `allowNativePasswords` ##### `allowNativePasswords`
``` ```
@ -454,7 +465,7 @@ user:password@/
The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively. The connection pool is managed by Go's database/sql package. For details on how to configure the size of the pool and how long connections stay in the pool see `*DB.SetMaxOpenConns`, `*DB.SetMaxIdleConns`, and `*DB.SetConnMaxLifetime` in the [database/sql documentation](https://golang.org/pkg/database/sql/). The read, write, and dial timeouts for each individual connection are configured with the DSN parameters [`readTimeout`](#readtimeout), [`writeTimeout`](#writetimeout), and [`timeout`](#timeout), respectively.
## `ColumnType` Support ## `ColumnType` Support
This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. This driver supports the [`ColumnType` interface](https://golang.org/pkg/database/sql/#ColumnType) introduced in Go 1.8, with the exception of [`ColumnType.Length()`](https://golang.org/pkg/database/sql/#ColumnType.Length), which is currently not supported. All Unsigned database type names will be returned `UNSIGNED ` with `INT`, `TINYINT`, `SMALLINT`, `BIGINT`.
## `context.Context` Support ## `context.Context` Support
Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts. Go 1.8 added `database/sql` support for `context.Context`. This driver supports query timeouts and cancellation via contexts.

19
vendor/github.com/go-sql-driver/mysql/atomic_bool.go generated vendored Normal file
View File

@ -0,0 +1,19 @@
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
//
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build go1.19
// +build go1.19
package mysql
import "sync/atomic"
/******************************************************************************
* Sync utils *
******************************************************************************/
type atomicBool = atomic.Bool

View File

@ -0,0 +1,47 @@
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package.
//
// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build !go1.19
// +build !go1.19
package mysql
import "sync/atomic"
/******************************************************************************
* Sync utils *
******************************************************************************/
// atomicBool is an implementation of atomic.Bool for older version of Go.
// it is a wrapper around uint32 for usage as a boolean value with
// atomic access.
type atomicBool struct {
_ noCopy
value uint32
}
// Load returns whether the current boolean value is true
func (ab *atomicBool) Load() bool {
return atomic.LoadUint32(&ab.value) > 0
}
// Store sets the value of the bool regardless of the previous value
func (ab *atomicBool) Store(value bool) {
if value {
atomic.StoreUint32(&ab.value, 1)
} else {
atomic.StoreUint32(&ab.value, 0)
}
}
// Swap sets the value of the bool and returns the old value.
func (ab *atomicBool) Swap(value bool) bool {
if value {
return atomic.SwapUint32(&ab.value, 1) > 0
}
return atomic.SwapUint32(&ab.value, 0) > 0
}

View File

@ -53,7 +53,6 @@ var (
// } else { // } else {
// log.Fatal("not a RSA public key") // log.Fatal("not a RSA public key")
// } // }
//
func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) { func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) {
serverPubKeyLock.Lock() serverPubKeyLock.Lock()
if serverPubKeyRegistry == nil { if serverPubKeyRegistry == nil {
@ -274,7 +273,9 @@ func (mc *mysqlConn) auth(authData []byte, plugin string) ([]byte, error) {
if len(mc.cfg.Passwd) == 0 { if len(mc.cfg.Passwd) == 0 {
return []byte{0}, nil return []byte{0}, nil
} }
if mc.cfg.tls != nil || mc.cfg.Net == "unix" { // unlike caching_sha2_password, sha256_password does not accept
// cleartext password on unix transport.
if mc.cfg.TLS != nil {
// write cleartext auth packet // write cleartext auth packet
return append([]byte(mc.cfg.Passwd), 0), nil return append([]byte(mc.cfg.Passwd), 0), nil
} }
@ -350,7 +351,7 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
} }
case cachingSha2PasswordPerformFullAuthentication: case cachingSha2PasswordPerformFullAuthentication:
if mc.cfg.tls != nil || mc.cfg.Net == "unix" { if mc.cfg.TLS != nil || mc.cfg.Net == "unix" {
// write cleartext auth packet // write cleartext auth packet
err = mc.writeAuthSwitchPacket(append([]byte(mc.cfg.Passwd), 0)) err = mc.writeAuthSwitchPacket(append([]byte(mc.cfg.Passwd), 0))
if err != nil { if err != nil {
@ -365,13 +366,20 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
return err return err
} }
data[4] = cachingSha2PasswordRequestPublicKey data[4] = cachingSha2PasswordRequestPublicKey
mc.writePacket(data) err = mc.writePacket(data)
if err != nil {
return err
}
// parse public key
if data, err = mc.readPacket(); err != nil { if data, err = mc.readPacket(); err != nil {
return err return err
} }
if data[0] != iAuthMoreData {
return fmt.Errorf("unexpect resp from server for caching_sha2_password perform full authentication")
}
// parse public key
block, rest := pem.Decode(data[1:]) block, rest := pem.Decode(data[1:])
if block == nil { if block == nil {
return fmt.Errorf("No Pem data found, data: %s", rest) return fmt.Errorf("No Pem data found, data: %s", rest)
@ -404,6 +412,10 @@ func (mc *mysqlConn) handleAuthResult(oldAuthData []byte, plugin string) error {
return nil // auth successful return nil // auth successful
default: default:
block, _ := pem.Decode(authData) block, _ := pem.Decode(authData)
if block == nil {
return fmt.Errorf("no Pem data found, data: %s", authData)
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes) pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil { if err != nil {
return err return err

View File

@ -13,6 +13,7 @@ const binaryCollation = "binary"
// A list of available collations mapped to the internal ID. // A list of available collations mapped to the internal ID.
// To update this map use the following MySQL query: // To update this map use the following MySQL query:
//
// SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID // SELECT COLLATION_NAME, ID FROM information_schema.COLLATIONS WHERE ID<256 ORDER BY ID
// //
// Handshake packet have only 1 byte for collation_id. So we can't use collations with ID > 255. // Handshake packet have only 1 byte for collation_id. So we can't use collations with ID > 255.

View File

@ -6,6 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/. // You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos // +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
package mysql package mysql

View File

@ -6,6 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/. // You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build !linux && !darwin && !dragonfly && !freebsd && !netbsd && !openbsd && !solaris && !illumos
// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos // +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd,!solaris,!illumos
package mysql package mysql

View File

@ -104,7 +104,7 @@ func (mc *mysqlConn) Begin() (driver.Tx, error) {
} }
func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) { func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
if mc.closed.IsSet() { if mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -123,7 +123,7 @@ func (mc *mysqlConn) begin(readOnly bool) (driver.Tx, error) {
func (mc *mysqlConn) Close() (err error) { func (mc *mysqlConn) Close() (err error) {
// Makes Close idempotent // Makes Close idempotent
if !mc.closed.IsSet() { if !mc.closed.Load() {
err = mc.writeCommandPacket(comQuit) err = mc.writeCommandPacket(comQuit)
} }
@ -137,7 +137,7 @@ func (mc *mysqlConn) Close() (err error) {
// is called before auth or on auth failure because MySQL will have already // is called before auth or on auth failure because MySQL will have already
// closed the network connection. // closed the network connection.
func (mc *mysqlConn) cleanup() { func (mc *mysqlConn) cleanup() {
if !mc.closed.TrySet(true) { if mc.closed.Swap(true) {
return return
} }
@ -152,7 +152,7 @@ func (mc *mysqlConn) cleanup() {
} }
func (mc *mysqlConn) error() error { func (mc *mysqlConn) error() error {
if mc.closed.IsSet() { if mc.closed.Load() {
if err := mc.canceled.Value(); err != nil { if err := mc.canceled.Value(); err != nil {
return err return err
} }
@ -162,7 +162,7 @@ func (mc *mysqlConn) error() error {
} }
func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) { func (mc *mysqlConn) Prepare(query string) (driver.Stmt, error) {
if mc.closed.IsSet() { if mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -295,7 +295,7 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
} }
func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) { func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {
if mc.closed.IsSet() { if mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -356,7 +356,7 @@ func (mc *mysqlConn) Query(query string, args []driver.Value) (driver.Rows, erro
} }
func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) { func (mc *mysqlConn) query(query string, args []driver.Value) (*textRows, error) {
if mc.closed.IsSet() { if mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -450,7 +450,7 @@ func (mc *mysqlConn) finish() {
// Ping implements driver.Pinger interface // Ping implements driver.Pinger interface
func (mc *mysqlConn) Ping(ctx context.Context) (err error) { func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
if mc.closed.IsSet() { if mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return driver.ErrBadConn return driver.ErrBadConn
} }
@ -469,7 +469,7 @@ func (mc *mysqlConn) Ping(ctx context.Context) (err error) {
// BeginTx implements driver.ConnBeginTx interface // BeginTx implements driver.ConnBeginTx interface
func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) { func (mc *mysqlConn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
if mc.closed.IsSet() { if mc.closed.Load() {
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -636,7 +636,7 @@ func (mc *mysqlConn) CheckNamedValue(nv *driver.NamedValue) (err error) {
// ResetSession implements driver.SessionResetter. // ResetSession implements driver.SessionResetter.
// (From Go 1.10) // (From Go 1.10)
func (mc *mysqlConn) ResetSession(ctx context.Context) error { func (mc *mysqlConn) ResetSession(ctx context.Context) error {
if mc.closed.IsSet() { if mc.closed.Load() {
return driver.ErrBadConn return driver.ErrBadConn
} }
mc.reset = true mc.reset = true
@ -646,5 +646,5 @@ func (mc *mysqlConn) ResetSession(ctx context.Context) error {
// IsValid implements driver.Validator interface // IsValid implements driver.Validator interface
// (From Go 1.15) // (From Go 1.15)
func (mc *mysqlConn) IsValid() bool { func (mc *mysqlConn) IsValid() bool {
return !mc.closed.IsSet() return !mc.closed.Load()
} }

View File

@ -46,13 +46,14 @@ type Config struct {
ServerPubKey string // Server public key name ServerPubKey string // Server public key name
pubKey *rsa.PublicKey // Server public key pubKey *rsa.PublicKey // Server public key
TLSConfig string // TLS configuration name TLSConfig string // TLS configuration name
tls *tls.Config // TLS configuration TLS *tls.Config // TLS configuration, its priority is higher than TLSConfig
Timeout time.Duration // Dial timeout Timeout time.Duration // Dial timeout
ReadTimeout time.Duration // I/O read timeout ReadTimeout time.Duration // I/O read timeout
WriteTimeout time.Duration // I/O write timeout WriteTimeout time.Duration // I/O write timeout
AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE AllowAllFiles bool // Allow all files to be used with LOAD DATA LOCAL INFILE
AllowCleartextPasswords bool // Allows the cleartext client side plugin AllowCleartextPasswords bool // Allows the cleartext client side plugin
AllowFallbackToPlaintext bool // Allows fallback to unencrypted connection if server does not support TLS
AllowNativePasswords bool // Allows the native password authentication method AllowNativePasswords bool // Allows the native password authentication method
AllowOldPasswords bool // Allows the old insecure password method AllowOldPasswords bool // Allows the old insecure password method
CheckConnLiveness bool // Check connections for liveness before using them CheckConnLiveness bool // Check connections for liveness before using them
@ -77,8 +78,8 @@ func NewConfig() *Config {
func (cfg *Config) Clone() *Config { func (cfg *Config) Clone() *Config {
cp := *cfg cp := *cfg
if cp.tls != nil { if cp.TLS != nil {
cp.tls = cfg.tls.Clone() cp.TLS = cfg.TLS.Clone()
} }
if len(cp.Params) > 0 { if len(cp.Params) > 0 {
cp.Params = make(map[string]string, len(cfg.Params)) cp.Params = make(map[string]string, len(cfg.Params))
@ -119,24 +120,29 @@ func (cfg *Config) normalize() error {
cfg.Addr = ensureHavePort(cfg.Addr) cfg.Addr = ensureHavePort(cfg.Addr)
} }
if cfg.TLS == nil {
switch cfg.TLSConfig { switch cfg.TLSConfig {
case "false", "": case "false", "":
// don't set anything // don't set anything
case "true": case "true":
cfg.tls = &tls.Config{} cfg.TLS = &tls.Config{}
case "skip-verify", "preferred": case "skip-verify":
cfg.tls = &tls.Config{InsecureSkipVerify: true} cfg.TLS = &tls.Config{InsecureSkipVerify: true}
case "preferred":
cfg.TLS = &tls.Config{InsecureSkipVerify: true}
cfg.AllowFallbackToPlaintext = true
default: default:
cfg.tls = getTLSConfigClone(cfg.TLSConfig) cfg.TLS = getTLSConfigClone(cfg.TLSConfig)
if cfg.tls == nil { if cfg.TLS == nil {
return errors.New("invalid value / unknown config name: " + cfg.TLSConfig) return errors.New("invalid value / unknown config name: " + cfg.TLSConfig)
} }
} }
}
if cfg.tls != nil && cfg.tls.ServerName == "" && !cfg.tls.InsecureSkipVerify { if cfg.TLS != nil && cfg.TLS.ServerName == "" && !cfg.TLS.InsecureSkipVerify {
host, _, err := net.SplitHostPort(cfg.Addr) host, _, err := net.SplitHostPort(cfg.Addr)
if err == nil { if err == nil {
cfg.tls.ServerName = host cfg.TLS.ServerName = host
} }
} }
@ -204,6 +210,10 @@ func (cfg *Config) FormatDSN() string {
writeDSNParam(&buf, &hasParam, "allowCleartextPasswords", "true") writeDSNParam(&buf, &hasParam, "allowCleartextPasswords", "true")
} }
if cfg.AllowFallbackToPlaintext {
writeDSNParam(&buf, &hasParam, "allowFallbackToPlaintext", "true")
}
if !cfg.AllowNativePasswords { if !cfg.AllowNativePasswords {
writeDSNParam(&buf, &hasParam, "allowNativePasswords", "false") writeDSNParam(&buf, &hasParam, "allowNativePasswords", "false")
} }
@ -391,6 +401,14 @@ func parseDSNParams(cfg *Config, params string) (err error) {
return errors.New("invalid bool value: " + value) return errors.New("invalid bool value: " + value)
} }
// Allow fallback to unencrypted connection if server does not support TLS
case "allowFallbackToPlaintext":
var isBool bool
cfg.AllowFallbackToPlaintext, isBool = readBool(value)
if !isBool {
return errors.New("invalid bool value: " + value)
}
// Use native password authentication // Use native password authentication
case "allowNativePasswords": case "allowNativePasswords":
var isBool bool var isBool bool
@ -426,7 +444,6 @@ func parseDSNParams(cfg *Config, params string) (err error) {
// Collation // Collation
case "collation": case "collation":
cfg.Collation = value cfg.Collation = value
break
case "columnsWithAlias": case "columnsWithAlias":
var isBool bool var isBool bool

View File

@ -57,9 +57,21 @@ func SetLogger(logger Logger) error {
// MySQLError is an error type which represents a single MySQL error // MySQLError is an error type which represents a single MySQL error
type MySQLError struct { type MySQLError struct {
Number uint16 Number uint16
SQLState [5]byte
Message string Message string
} }
func (me *MySQLError) Error() string { func (me *MySQLError) Error() string {
if me.SQLState != [5]byte{} {
return fmt.Sprintf("Error %d (%s): %s", me.Number, me.SQLState, me.Message)
}
return fmt.Sprintf("Error %d: %s", me.Number, me.Message) return fmt.Sprintf("Error %d: %s", me.Number, me.Message)
} }
func (me *MySQLError) Is(err error) bool {
if merr, ok := err.(*MySQLError); ok {
return merr.Number == me.Number
}
return false
}

View File

@ -41,6 +41,9 @@ func (mf *mysqlField) typeDatabaseName() string {
case fieldTypeJSON: case fieldTypeJSON:
return "JSON" return "JSON"
case fieldTypeLong: case fieldTypeLong:
if mf.flags&flagUnsigned != 0 {
return "UNSIGNED INT"
}
return "INT" return "INT"
case fieldTypeLongBLOB: case fieldTypeLongBLOB:
if mf.charSet != collations[binaryCollation] { if mf.charSet != collations[binaryCollation] {
@ -48,6 +51,9 @@ func (mf *mysqlField) typeDatabaseName() string {
} }
return "LONGBLOB" return "LONGBLOB"
case fieldTypeLongLong: case fieldTypeLongLong:
if mf.flags&flagUnsigned != 0 {
return "UNSIGNED BIGINT"
}
return "BIGINT" return "BIGINT"
case fieldTypeMediumBLOB: case fieldTypeMediumBLOB:
if mf.charSet != collations[binaryCollation] { if mf.charSet != collations[binaryCollation] {
@ -63,6 +69,9 @@ func (mf *mysqlField) typeDatabaseName() string {
case fieldTypeSet: case fieldTypeSet:
return "SET" return "SET"
case fieldTypeShort: case fieldTypeShort:
if mf.flags&flagUnsigned != 0 {
return "UNSIGNED SMALLINT"
}
return "SMALLINT" return "SMALLINT"
case fieldTypeString: case fieldTypeString:
if mf.charSet == collations[binaryCollation] { if mf.charSet == collations[binaryCollation] {
@ -74,6 +83,9 @@ func (mf *mysqlField) typeDatabaseName() string {
case fieldTypeTimestamp: case fieldTypeTimestamp:
return "TIMESTAMP" return "TIMESTAMP"
case fieldTypeTiny: case fieldTypeTiny:
if mf.flags&flagUnsigned != 0 {
return "UNSIGNED TINYINT"
}
return "TINYINT" return "TINYINT"
case fieldTypeTinyBLOB: case fieldTypeTinyBLOB:
if mf.charSet != collations[binaryCollation] { if mf.charSet != collations[binaryCollation] {
@ -106,7 +118,7 @@ var (
scanTypeInt64 = reflect.TypeOf(int64(0)) scanTypeInt64 = reflect.TypeOf(int64(0))
scanTypeNullFloat = reflect.TypeOf(sql.NullFloat64{}) scanTypeNullFloat = reflect.TypeOf(sql.NullFloat64{})
scanTypeNullInt = reflect.TypeOf(sql.NullInt64{}) scanTypeNullInt = reflect.TypeOf(sql.NullInt64{})
scanTypeNullTime = reflect.TypeOf(nullTime{}) scanTypeNullTime = reflect.TypeOf(sql.NullTime{})
scanTypeUint8 = reflect.TypeOf(uint8(0)) scanTypeUint8 = reflect.TypeOf(uint8(0))
scanTypeUint16 = reflect.TypeOf(uint16(0)) scanTypeUint16 = reflect.TypeOf(uint16(0))
scanTypeUint32 = reflect.TypeOf(uint32(0)) scanTypeUint32 = reflect.TypeOf(uint32(0))

View File

@ -6,6 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/. // You can obtain one at http://mozilla.org/MPL/2.0/.
//go:build gofuzz
// +build gofuzz // +build gofuzz
package mysql package mysql

View File

@ -33,7 +33,6 @@ var (
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo") // err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
// if err != nil { // if err != nil {
// ... // ...
//
func RegisterLocalFile(filePath string) { func RegisterLocalFile(filePath string) {
fileRegisterLock.Lock() fileRegisterLock.Lock()
// lazy map init // lazy map init
@ -66,7 +65,6 @@ func DeregisterLocalFile(filePath string) {
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo") // err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
// if err != nil { // if err != nil {
// ... // ...
//
func RegisterReaderHandler(name string, handler func() io.Reader) { func RegisterReaderHandler(name string, handler func() io.Reader) {
readerRegisterLock.Lock() readerRegisterLock.Lock()
// lazy map init // lazy map init
@ -93,10 +91,12 @@ func deferredClose(err *error, closer io.Closer) {
} }
} }
const defaultPacketSize = 16 * 1024 // 16KB is small enough for disk readahead and large enough for TCP
func (mc *mysqlConn) handleInFileRequest(name string) (err error) { func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
var rdr io.Reader var rdr io.Reader
var data []byte var data []byte
packetSize := 16 * 1024 // 16KB is small enough for disk readahead and large enough for TCP packetSize := defaultPacketSize
if mc.maxWriteSize < packetSize { if mc.maxWriteSize < packetSize {
packetSize = mc.maxWriteSize packetSize = mc.maxWriteSize
} }

View File

@ -9,11 +9,32 @@
package mysql package mysql
import ( import (
"database/sql"
"database/sql/driver" "database/sql/driver"
"fmt" "fmt"
"time" "time"
) )
// NullTime represents a time.Time that may be NULL.
// NullTime implements the Scanner interface so
// it can be used as a scan destination:
//
// var nt NullTime
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
// ...
// if nt.Valid {
// // use nt.Time
// } else {
// // NULL value
// }
//
// # This NullTime implementation is not driver-specific
//
// Deprecated: NullTime doesn't honor the loc DSN parameter.
// NullTime.Scan interprets a time as UTC, not the loc DSN parameter.
// Use sql.NullTime instead.
type NullTime sql.NullTime
// Scan implements the Scanner interface. // Scan implements the Scanner interface.
// The value type must be time.Time or string / []byte (formatted time-string), // The value type must be time.Time or string / []byte (formatted time-string),
// otherwise Scan fails. // otherwise Scan fails.

View File

@ -1,40 +0,0 @@
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
// +build go1.13
package mysql
import (
"database/sql"
)
// NullTime represents a time.Time that may be NULL.
// NullTime implements the Scanner interface so
// it can be used as a scan destination:
//
// var nt NullTime
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
// ...
// if nt.Valid {
// // use nt.Time
// } else {
// // NULL value
// }
//
// This NullTime implementation is not driver-specific
//
// Deprecated: NullTime doesn't honor the loc DSN parameter.
// NullTime.Scan interprets a time as UTC, not the loc DSN parameter.
// Use sql.NullTime instead.
type NullTime sql.NullTime
// for internal use.
// the mysql package uses sql.NullTime if it is available.
// if not, the package uses mysql.NullTime.
type nullTime = sql.NullTime // sql.NullTime is available

View File

@ -1,39 +0,0 @@
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
// +build !go1.13
package mysql
import (
"time"
)
// NullTime represents a time.Time that may be NULL.
// NullTime implements the Scanner interface so
// it can be used as a scan destination:
//
// var nt NullTime
// err := db.QueryRow("SELECT time FROM foo WHERE id=?", id).Scan(&nt)
// ...
// if nt.Valid {
// // use nt.Time
// } else {
// // NULL value
// }
//
// This NullTime implementation is not driver-specific
type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}
// for internal use.
// the mysql package uses sql.NullTime if it is available.
// if not, the package uses mysql.NullTime.
type nullTime = NullTime // sql.NullTime is not available

View File

@ -110,15 +110,14 @@ func (mc *mysqlConn) writePacket(data []byte) error {
conn = mc.rawConn conn = mc.rawConn
} }
var err error var err error
// If this connection has a ReadTimeout which we've been setting on if mc.cfg.CheckConnLiveness {
// reads, reset it to its default value before we attempt a non-blocking
// read, otherwise the scheduler will just time us out before we can read
if mc.cfg.ReadTimeout != 0 { if mc.cfg.ReadTimeout != 0 {
err = conn.SetReadDeadline(time.Time{}) err = conn.SetReadDeadline(time.Now().Add(mc.cfg.ReadTimeout))
} }
if err == nil && mc.cfg.CheckConnLiveness { if err == nil {
err = connCheck(conn) err = connCheck(conn)
} }
}
if err != nil { if err != nil {
errLog.Print("closing bad idle connection: ", err) errLog.Print("closing bad idle connection: ", err)
mc.Close() mc.Close()
@ -223,9 +222,9 @@ func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err erro
if mc.flags&clientProtocol41 == 0 { if mc.flags&clientProtocol41 == 0 {
return nil, "", ErrOldProtocol return nil, "", ErrOldProtocol
} }
if mc.flags&clientSSL == 0 && mc.cfg.tls != nil { if mc.flags&clientSSL == 0 && mc.cfg.TLS != nil {
if mc.cfg.TLSConfig == "preferred" { if mc.cfg.AllowFallbackToPlaintext {
mc.cfg.tls = nil mc.cfg.TLS = nil
} else { } else {
return nil, "", ErrNoTLS return nil, "", ErrNoTLS
} }
@ -293,7 +292,7 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
} }
// To enable TLS / SSL // To enable TLS / SSL
if mc.cfg.tls != nil { if mc.cfg.TLS != nil {
clientFlags |= clientSSL clientFlags |= clientSSL
} }
@ -357,14 +356,14 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
// SSL Connection Request Packet // SSL Connection Request Packet
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest // http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::SSLRequest
if mc.cfg.tls != nil { if mc.cfg.TLS != nil {
// Send TLS / SSL request packet // Send TLS / SSL request packet
if err := mc.writePacket(data[:(4+4+1+23)+4]); err != nil { if err := mc.writePacket(data[:(4+4+1+23)+4]); err != nil {
return err return err
} }
// Switch to TLS // Switch to TLS
tlsConn := tls.Client(mc.netConn, mc.cfg.tls) tlsConn := tls.Client(mc.netConn, mc.cfg.TLS)
if err := tlsConn.Handshake(); err != nil { if err := tlsConn.Handshake(); err != nil {
return err return err
} }
@ -588,19 +587,20 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
return driver.ErrBadConn return driver.ErrBadConn
} }
me := &MySQLError{Number: errno}
pos := 3 pos := 3
// SQL State [optional: # + 5bytes string] // SQL State [optional: # + 5bytes string]
if data[3] == 0x23 { if data[3] == 0x23 {
//sqlstate := string(data[4 : 4+5]) copy(me.SQLState[:], data[4:4+5])
pos = 9 pos = 9
} }
// Error Message [string] // Error Message [string]
return &MySQLError{ me.Message = string(data[pos:])
Number: errno,
Message: string(data[pos:]), return me
}
} }
func readStatus(b []byte) statusFlag { func readStatus(b []byte) statusFlag {
@ -761,40 +761,40 @@ func (rows *textRows) readRow(dest []driver.Value) error {
} }
// RowSet Packet // RowSet Packet
var n int var (
var isNull bool n int
pos := 0 isNull bool
pos int = 0
)
for i := range dest { for i := range dest {
// Read bytes and convert to string // Read bytes and convert to string
dest[i], isNull, n, err = readLengthEncodedString(data[pos:]) dest[i], isNull, n, err = readLengthEncodedString(data[pos:])
pos += n pos += n
if err == nil {
if !isNull { if err != nil {
if !mc.parseTime { return err
continue
} else {
switch rows.rs.columns[i].fieldType {
case fieldTypeTimestamp, fieldTypeDateTime,
fieldTypeDate, fieldTypeNewDate:
dest[i], err = parseDateTime(
dest[i].([]byte),
mc.cfg.Loc,
)
if err == nil {
continue
}
default:
continue
}
} }
} else { if isNull {
dest[i] = nil dest[i] = nil
continue continue
} }
if !mc.parseTime {
continue
}
// Parse time field
switch rows.rs.columns[i].fieldType {
case fieldTypeTimestamp,
fieldTypeDateTime,
fieldTypeDate,
fieldTypeNewDate:
if dest[i], err = parseDateTime(dest[i].([]byte), mc.cfg.Loc); err != nil {
return err
}
} }
return err // err != nil
} }
return nil return nil

View File

@ -23,7 +23,7 @@ type mysqlStmt struct {
} }
func (stmt *mysqlStmt) Close() error { func (stmt *mysqlStmt) Close() error {
if stmt.mc == nil || stmt.mc.closed.IsSet() { if stmt.mc == nil || stmt.mc.closed.Load() {
// driver.Stmt.Close can be called more than once, thus this function // driver.Stmt.Close can be called more than once, thus this function
// has to be idempotent. // has to be idempotent.
// See also Issue #450 and golang/go#16019. // See also Issue #450 and golang/go#16019.
@ -50,7 +50,7 @@ func (stmt *mysqlStmt) CheckNamedValue(nv *driver.NamedValue) (err error) {
} }
func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) { func (stmt *mysqlStmt) Exec(args []driver.Value) (driver.Result, error) {
if stmt.mc.closed.IsSet() { if stmt.mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -98,7 +98,7 @@ func (stmt *mysqlStmt) Query(args []driver.Value) (driver.Rows, error) {
} }
func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) { func (stmt *mysqlStmt) query(args []driver.Value) (*binaryRows, error) {
if stmt.mc.closed.IsSet() { if stmt.mc.closed.Load() {
errLog.Print(ErrInvalidConn) errLog.Print(ErrInvalidConn)
return nil, driver.ErrBadConn return nil, driver.ErrBadConn
} }
@ -157,7 +157,7 @@ func (c converter) ConvertValue(v interface{}) (driver.Value, error) {
if driver.IsValue(sv) { if driver.IsValue(sv) {
return sv, nil return sv, nil
} }
// A value returend from the Valuer interface can be "a type handled by // A value returned from the Valuer interface can be "a type handled by
// a database driver's NamedValueChecker interface" so we should accept // a database driver's NamedValueChecker interface" so we should accept
// uint64 here as well. // uint64 here as well.
if u, ok := sv.(uint64); ok { if u, ok := sv.(uint64); ok {

View File

@ -13,7 +13,7 @@ type mysqlTx struct {
} }
func (tx *mysqlTx) Commit() (err error) { func (tx *mysqlTx) Commit() (err error) {
if tx.mc == nil || tx.mc.closed.IsSet() { if tx.mc == nil || tx.mc.closed.Load() {
return ErrInvalidConn return ErrInvalidConn
} }
err = tx.mc.exec("COMMIT") err = tx.mc.exec("COMMIT")
@ -22,7 +22,7 @@ func (tx *mysqlTx) Commit() (err error) {
} }
func (tx *mysqlTx) Rollback() (err error) { func (tx *mysqlTx) Rollback() (err error) {
if tx.mc == nil || tx.mc.closed.IsSet() { if tx.mc == nil || tx.mc.closed.Load() {
return ErrInvalidConn return ErrInvalidConn
} }
err = tx.mc.exec("ROLLBACK") err = tx.mc.exec("ROLLBACK")

View File

@ -54,7 +54,6 @@ var (
// Certificates: clientCert, // Certificates: clientCert,
// }) // })
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom") // db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
//
func RegisterTLSConfig(key string, config *tls.Config) error { func RegisterTLSConfig(key string, config *tls.Config) error {
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" { if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" {
return fmt.Errorf("key '%s' is reserved", key) return fmt.Errorf("key '%s' is reserved", key)
@ -118,10 +117,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
if year <= 0 {
year = 1
}
if b[4] != '-' { if b[4] != '-' {
return time.Time{}, fmt.Errorf("bad value for field: `%c`", b[4]) return time.Time{}, fmt.Errorf("bad value for field: `%c`", b[4])
} }
@ -130,9 +125,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
if m <= 0 {
m = 1
}
month := time.Month(m) month := time.Month(m)
if b[7] != '-' { if b[7] != '-' {
@ -143,9 +135,6 @@ func parseDateTime(b []byte, loc *time.Location) (time.Time, error) {
if err != nil { if err != nil {
return time.Time{}, err return time.Time{}, err
} }
if day <= 0 {
day = 1
}
if len(b) == 10 { if len(b) == 10 {
return time.Date(year, month, day, 0, 0, 0, 0, loc), nil return time.Date(year, month, day, 0, 0, 0, 0, loc), nil
} }
@ -199,7 +188,7 @@ func parseByteYear(b []byte) (int, error) {
return 0, err return 0, err
} }
year += v * n year += v * n
n = n / 10 n /= 10
} }
return year, nil return year, nil
} }
@ -542,7 +531,7 @@ func stringToInt(b []byte) int {
return val return val
} }
// returns the string read as a bytes slice, wheter the value is NULL, // returns the string read as a bytes slice, whether the value is NULL,
// the number of bytes read and an error, in case the string is longer than // the number of bytes read and an error, in case the string is longer than
// the input slice // the input slice
func readLengthEncodedString(b []byte) ([]byte, bool, int, error) { func readLengthEncodedString(b []byte) ([]byte, bool, int, error) {
@ -652,32 +641,32 @@ func escapeBytesBackslash(buf, v []byte) []byte {
for _, c := range v { for _, c := range v {
switch c { switch c {
case '\x00': case '\x00':
buf[pos] = '\\'
buf[pos+1] = '0' buf[pos+1] = '0'
buf[pos] = '\\'
pos += 2 pos += 2
case '\n': case '\n':
buf[pos] = '\\'
buf[pos+1] = 'n' buf[pos+1] = 'n'
buf[pos] = '\\'
pos += 2 pos += 2
case '\r': case '\r':
buf[pos] = '\\'
buf[pos+1] = 'r' buf[pos+1] = 'r'
buf[pos] = '\\'
pos += 2 pos += 2
case '\x1a': case '\x1a':
buf[pos] = '\\'
buf[pos+1] = 'Z' buf[pos+1] = 'Z'
buf[pos] = '\\'
pos += 2 pos += 2
case '\'': case '\'':
buf[pos] = '\\'
buf[pos+1] = '\'' buf[pos+1] = '\''
buf[pos] = '\\'
pos += 2 pos += 2
case '"': case '"':
buf[pos] = '\\'
buf[pos+1] = '"' buf[pos+1] = '"'
buf[pos] = '\\'
pos += 2 pos += 2
case '\\': case '\\':
buf[pos] = '\\'
buf[pos+1] = '\\' buf[pos+1] = '\\'
buf[pos] = '\\'
pos += 2 pos += 2
default: default:
buf[pos] = c buf[pos] = c
@ -697,32 +686,32 @@ func escapeStringBackslash(buf []byte, v string) []byte {
c := v[i] c := v[i]
switch c { switch c {
case '\x00': case '\x00':
buf[pos] = '\\'
buf[pos+1] = '0' buf[pos+1] = '0'
buf[pos] = '\\'
pos += 2 pos += 2
case '\n': case '\n':
buf[pos] = '\\'
buf[pos+1] = 'n' buf[pos+1] = 'n'
buf[pos] = '\\'
pos += 2 pos += 2
case '\r': case '\r':
buf[pos] = '\\'
buf[pos+1] = 'r' buf[pos+1] = 'r'
buf[pos] = '\\'
pos += 2 pos += 2
case '\x1a': case '\x1a':
buf[pos] = '\\'
buf[pos+1] = 'Z' buf[pos+1] = 'Z'
buf[pos] = '\\'
pos += 2 pos += 2
case '\'': case '\'':
buf[pos] = '\\'
buf[pos+1] = '\'' buf[pos+1] = '\''
buf[pos] = '\\'
pos += 2 pos += 2
case '"': case '"':
buf[pos] = '\\'
buf[pos+1] = '"' buf[pos+1] = '"'
buf[pos] = '\\'
pos += 2 pos += 2
case '\\': case '\\':
buf[pos] = '\\'
buf[pos+1] = '\\' buf[pos+1] = '\\'
buf[pos] = '\\'
pos += 2 pos += 2
default: default:
buf[pos] = c buf[pos] = c
@ -744,8 +733,8 @@ func escapeBytesQuotes(buf, v []byte) []byte {
for _, c := range v { for _, c := range v {
if c == '\'' { if c == '\'' {
buf[pos] = '\''
buf[pos+1] = '\'' buf[pos+1] = '\''
buf[pos] = '\''
pos += 2 pos += 2
} else { } else {
buf[pos] = c buf[pos] = c
@ -764,8 +753,8 @@ func escapeStringQuotes(buf []byte, v string) []byte {
for i := 0; i < len(v); i++ { for i := 0; i < len(v); i++ {
c := v[i] c := v[i]
if c == '\'' { if c == '\'' {
buf[pos] = '\''
buf[pos+1] = '\'' buf[pos+1] = '\''
buf[pos] = '\''
pos += 2 pos += 2
} else { } else {
buf[pos] = c buf[pos] = c
@ -790,38 +779,15 @@ type noCopy struct{}
// Lock is a no-op used by -copylocks checker from `go vet`. // Lock is a no-op used by -copylocks checker from `go vet`.
func (*noCopy) Lock() {} func (*noCopy) Lock() {}
// atomicBool is a wrapper around uint32 for usage as a boolean value with // Unlock is a no-op used by -copylocks checker from `go vet`.
// atomic access. // noCopy should implement sync.Locker from Go 1.11
type atomicBool struct { // https://github.com/golang/go/commit/c2eba53e7f80df21d51285879d51ab81bcfbf6bc
_noCopy noCopy // https://github.com/golang/go/issues/26165
value uint32 func (*noCopy) Unlock() {}
}
// IsSet returns whether the current boolean value is true
func (ab *atomicBool) IsSet() bool {
return atomic.LoadUint32(&ab.value) > 0
}
// Set sets the value of the bool regardless of the previous value
func (ab *atomicBool) Set(value bool) {
if value {
atomic.StoreUint32(&ab.value, 1)
} else {
atomic.StoreUint32(&ab.value, 0)
}
}
// TrySet sets the value of the bool and returns whether the value changed
func (ab *atomicBool) TrySet(value bool) bool {
if value {
return atomic.SwapUint32(&ab.value, 1) == 0
}
return atomic.SwapUint32(&ab.value, 0) > 0
}
// atomicError is a wrapper for atomically accessed error values // atomicError is a wrapper for atomically accessed error values
type atomicError struct { type atomicError struct {
_noCopy noCopy _ noCopy
value atomic.Value value atomic.Value
} }

View File

@ -7,6 +7,8 @@
package sha3 package sha3
import "math/bits"
// rc stores the round constants for use in the ι step. // rc stores the round constants for use in the ι step.
var rc = [24]uint64{ var rc = [24]uint64{
0x0000000000000001, 0x0000000000000001,
@ -60,13 +62,13 @@ func keccakF1600(a *[25]uint64) {
bc0 = a[0] ^ d0 bc0 = a[0] ^ d0
t = a[6] ^ d1 t = a[6] ^ d1
bc1 = t<<44 | t>>(64-44) bc1 = bits.RotateLeft64(t, 44)
t = a[12] ^ d2 t = a[12] ^ d2
bc2 = t<<43 | t>>(64-43) bc2 = bits.RotateLeft64(t, 43)
t = a[18] ^ d3 t = a[18] ^ d3
bc3 = t<<21 | t>>(64-21) bc3 = bits.RotateLeft64(t, 21)
t = a[24] ^ d4 t = a[24] ^ d4
bc4 = t<<14 | t>>(64-14) bc4 = bits.RotateLeft64(t, 14)
a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i] a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i]
a[6] = bc1 ^ (bc3 &^ bc2) a[6] = bc1 ^ (bc3 &^ bc2)
a[12] = bc2 ^ (bc4 &^ bc3) a[12] = bc2 ^ (bc4 &^ bc3)
@ -74,15 +76,15 @@ func keccakF1600(a *[25]uint64) {
a[24] = bc4 ^ (bc1 &^ bc0) a[24] = bc4 ^ (bc1 &^ bc0)
t = a[10] ^ d0 t = a[10] ^ d0
bc2 = t<<3 | t>>(64-3) bc2 = bits.RotateLeft64(t, 3)
t = a[16] ^ d1 t = a[16] ^ d1
bc3 = t<<45 | t>>(64-45) bc3 = bits.RotateLeft64(t, 45)
t = a[22] ^ d2 t = a[22] ^ d2
bc4 = t<<61 | t>>(64-61) bc4 = bits.RotateLeft64(t, 61)
t = a[3] ^ d3 t = a[3] ^ d3
bc0 = t<<28 | t>>(64-28) bc0 = bits.RotateLeft64(t, 28)
t = a[9] ^ d4 t = a[9] ^ d4
bc1 = t<<20 | t>>(64-20) bc1 = bits.RotateLeft64(t, 20)
a[10] = bc0 ^ (bc2 &^ bc1) a[10] = bc0 ^ (bc2 &^ bc1)
a[16] = bc1 ^ (bc3 &^ bc2) a[16] = bc1 ^ (bc3 &^ bc2)
a[22] = bc2 ^ (bc4 &^ bc3) a[22] = bc2 ^ (bc4 &^ bc3)
@ -90,15 +92,15 @@ func keccakF1600(a *[25]uint64) {
a[9] = bc4 ^ (bc1 &^ bc0) a[9] = bc4 ^ (bc1 &^ bc0)
t = a[20] ^ d0 t = a[20] ^ d0
bc4 = t<<18 | t>>(64-18) bc4 = bits.RotateLeft64(t, 18)
t = a[1] ^ d1 t = a[1] ^ d1
bc0 = t<<1 | t>>(64-1) bc0 = bits.RotateLeft64(t, 1)
t = a[7] ^ d2 t = a[7] ^ d2
bc1 = t<<6 | t>>(64-6) bc1 = bits.RotateLeft64(t, 6)
t = a[13] ^ d3 t = a[13] ^ d3
bc2 = t<<25 | t>>(64-25) bc2 = bits.RotateLeft64(t, 25)
t = a[19] ^ d4 t = a[19] ^ d4
bc3 = t<<8 | t>>(64-8) bc3 = bits.RotateLeft64(t, 8)
a[20] = bc0 ^ (bc2 &^ bc1) a[20] = bc0 ^ (bc2 &^ bc1)
a[1] = bc1 ^ (bc3 &^ bc2) a[1] = bc1 ^ (bc3 &^ bc2)
a[7] = bc2 ^ (bc4 &^ bc3) a[7] = bc2 ^ (bc4 &^ bc3)
@ -106,15 +108,15 @@ func keccakF1600(a *[25]uint64) {
a[19] = bc4 ^ (bc1 &^ bc0) a[19] = bc4 ^ (bc1 &^ bc0)
t = a[5] ^ d0 t = a[5] ^ d0
bc1 = t<<36 | t>>(64-36) bc1 = bits.RotateLeft64(t, 36)
t = a[11] ^ d1 t = a[11] ^ d1
bc2 = t<<10 | t>>(64-10) bc2 = bits.RotateLeft64(t, 10)
t = a[17] ^ d2 t = a[17] ^ d2
bc3 = t<<15 | t>>(64-15) bc3 = bits.RotateLeft64(t, 15)
t = a[23] ^ d3 t = a[23] ^ d3
bc4 = t<<56 | t>>(64-56) bc4 = bits.RotateLeft64(t, 56)
t = a[4] ^ d4 t = a[4] ^ d4
bc0 = t<<27 | t>>(64-27) bc0 = bits.RotateLeft64(t, 27)
a[5] = bc0 ^ (bc2 &^ bc1) a[5] = bc0 ^ (bc2 &^ bc1)
a[11] = bc1 ^ (bc3 &^ bc2) a[11] = bc1 ^ (bc3 &^ bc2)
a[17] = bc2 ^ (bc4 &^ bc3) a[17] = bc2 ^ (bc4 &^ bc3)
@ -122,15 +124,15 @@ func keccakF1600(a *[25]uint64) {
a[4] = bc4 ^ (bc1 &^ bc0) a[4] = bc4 ^ (bc1 &^ bc0)
t = a[15] ^ d0 t = a[15] ^ d0
bc3 = t<<41 | t>>(64-41) bc3 = bits.RotateLeft64(t, 41)
t = a[21] ^ d1 t = a[21] ^ d1
bc4 = t<<2 | t>>(64-2) bc4 = bits.RotateLeft64(t, 2)
t = a[2] ^ d2 t = a[2] ^ d2
bc0 = t<<62 | t>>(64-62) bc0 = bits.RotateLeft64(t, 62)
t = a[8] ^ d3 t = a[8] ^ d3
bc1 = t<<55 | t>>(64-55) bc1 = bits.RotateLeft64(t, 55)
t = a[14] ^ d4 t = a[14] ^ d4
bc2 = t<<39 | t>>(64-39) bc2 = bits.RotateLeft64(t, 39)
a[15] = bc0 ^ (bc2 &^ bc1) a[15] = bc0 ^ (bc2 &^ bc1)
a[21] = bc1 ^ (bc3 &^ bc2) a[21] = bc1 ^ (bc3 &^ bc2)
a[2] = bc2 ^ (bc4 &^ bc3) a[2] = bc2 ^ (bc4 &^ bc3)
@ -151,13 +153,13 @@ func keccakF1600(a *[25]uint64) {
bc0 = a[0] ^ d0 bc0 = a[0] ^ d0
t = a[16] ^ d1 t = a[16] ^ d1
bc1 = t<<44 | t>>(64-44) bc1 = bits.RotateLeft64(t, 44)
t = a[7] ^ d2 t = a[7] ^ d2
bc2 = t<<43 | t>>(64-43) bc2 = bits.RotateLeft64(t, 43)
t = a[23] ^ d3 t = a[23] ^ d3
bc3 = t<<21 | t>>(64-21) bc3 = bits.RotateLeft64(t, 21)
t = a[14] ^ d4 t = a[14] ^ d4
bc4 = t<<14 | t>>(64-14) bc4 = bits.RotateLeft64(t, 14)
a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+1] a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+1]
a[16] = bc1 ^ (bc3 &^ bc2) a[16] = bc1 ^ (bc3 &^ bc2)
a[7] = bc2 ^ (bc4 &^ bc3) a[7] = bc2 ^ (bc4 &^ bc3)
@ -165,15 +167,15 @@ func keccakF1600(a *[25]uint64) {
a[14] = bc4 ^ (bc1 &^ bc0) a[14] = bc4 ^ (bc1 &^ bc0)
t = a[20] ^ d0 t = a[20] ^ d0
bc2 = t<<3 | t>>(64-3) bc2 = bits.RotateLeft64(t, 3)
t = a[11] ^ d1 t = a[11] ^ d1
bc3 = t<<45 | t>>(64-45) bc3 = bits.RotateLeft64(t, 45)
t = a[2] ^ d2 t = a[2] ^ d2
bc4 = t<<61 | t>>(64-61) bc4 = bits.RotateLeft64(t, 61)
t = a[18] ^ d3 t = a[18] ^ d3
bc0 = t<<28 | t>>(64-28) bc0 = bits.RotateLeft64(t, 28)
t = a[9] ^ d4 t = a[9] ^ d4
bc1 = t<<20 | t>>(64-20) bc1 = bits.RotateLeft64(t, 20)
a[20] = bc0 ^ (bc2 &^ bc1) a[20] = bc0 ^ (bc2 &^ bc1)
a[11] = bc1 ^ (bc3 &^ bc2) a[11] = bc1 ^ (bc3 &^ bc2)
a[2] = bc2 ^ (bc4 &^ bc3) a[2] = bc2 ^ (bc4 &^ bc3)
@ -181,15 +183,15 @@ func keccakF1600(a *[25]uint64) {
a[9] = bc4 ^ (bc1 &^ bc0) a[9] = bc4 ^ (bc1 &^ bc0)
t = a[15] ^ d0 t = a[15] ^ d0
bc4 = t<<18 | t>>(64-18) bc4 = bits.RotateLeft64(t, 18)
t = a[6] ^ d1 t = a[6] ^ d1
bc0 = t<<1 | t>>(64-1) bc0 = bits.RotateLeft64(t, 1)
t = a[22] ^ d2 t = a[22] ^ d2
bc1 = t<<6 | t>>(64-6) bc1 = bits.RotateLeft64(t, 6)
t = a[13] ^ d3 t = a[13] ^ d3
bc2 = t<<25 | t>>(64-25) bc2 = bits.RotateLeft64(t, 25)
t = a[4] ^ d4 t = a[4] ^ d4
bc3 = t<<8 | t>>(64-8) bc3 = bits.RotateLeft64(t, 8)
a[15] = bc0 ^ (bc2 &^ bc1) a[15] = bc0 ^ (bc2 &^ bc1)
a[6] = bc1 ^ (bc3 &^ bc2) a[6] = bc1 ^ (bc3 &^ bc2)
a[22] = bc2 ^ (bc4 &^ bc3) a[22] = bc2 ^ (bc4 &^ bc3)
@ -197,15 +199,15 @@ func keccakF1600(a *[25]uint64) {
a[4] = bc4 ^ (bc1 &^ bc0) a[4] = bc4 ^ (bc1 &^ bc0)
t = a[10] ^ d0 t = a[10] ^ d0
bc1 = t<<36 | t>>(64-36) bc1 = bits.RotateLeft64(t, 36)
t = a[1] ^ d1 t = a[1] ^ d1
bc2 = t<<10 | t>>(64-10) bc2 = bits.RotateLeft64(t, 10)
t = a[17] ^ d2 t = a[17] ^ d2
bc3 = t<<15 | t>>(64-15) bc3 = bits.RotateLeft64(t, 15)
t = a[8] ^ d3 t = a[8] ^ d3
bc4 = t<<56 | t>>(64-56) bc4 = bits.RotateLeft64(t, 56)
t = a[24] ^ d4 t = a[24] ^ d4
bc0 = t<<27 | t>>(64-27) bc0 = bits.RotateLeft64(t, 27)
a[10] = bc0 ^ (bc2 &^ bc1) a[10] = bc0 ^ (bc2 &^ bc1)
a[1] = bc1 ^ (bc3 &^ bc2) a[1] = bc1 ^ (bc3 &^ bc2)
a[17] = bc2 ^ (bc4 &^ bc3) a[17] = bc2 ^ (bc4 &^ bc3)
@ -213,15 +215,15 @@ func keccakF1600(a *[25]uint64) {
a[24] = bc4 ^ (bc1 &^ bc0) a[24] = bc4 ^ (bc1 &^ bc0)
t = a[5] ^ d0 t = a[5] ^ d0
bc3 = t<<41 | t>>(64-41) bc3 = bits.RotateLeft64(t, 41)
t = a[21] ^ d1 t = a[21] ^ d1
bc4 = t<<2 | t>>(64-2) bc4 = bits.RotateLeft64(t, 2)
t = a[12] ^ d2 t = a[12] ^ d2
bc0 = t<<62 | t>>(64-62) bc0 = bits.RotateLeft64(t, 62)
t = a[3] ^ d3 t = a[3] ^ d3
bc1 = t<<55 | t>>(64-55) bc1 = bits.RotateLeft64(t, 55)
t = a[19] ^ d4 t = a[19] ^ d4
bc2 = t<<39 | t>>(64-39) bc2 = bits.RotateLeft64(t, 39)
a[5] = bc0 ^ (bc2 &^ bc1) a[5] = bc0 ^ (bc2 &^ bc1)
a[21] = bc1 ^ (bc3 &^ bc2) a[21] = bc1 ^ (bc3 &^ bc2)
a[12] = bc2 ^ (bc4 &^ bc3) a[12] = bc2 ^ (bc4 &^ bc3)
@ -242,13 +244,13 @@ func keccakF1600(a *[25]uint64) {
bc0 = a[0] ^ d0 bc0 = a[0] ^ d0
t = a[11] ^ d1 t = a[11] ^ d1
bc1 = t<<44 | t>>(64-44) bc1 = bits.RotateLeft64(t, 44)
t = a[22] ^ d2 t = a[22] ^ d2
bc2 = t<<43 | t>>(64-43) bc2 = bits.RotateLeft64(t, 43)
t = a[8] ^ d3 t = a[8] ^ d3
bc3 = t<<21 | t>>(64-21) bc3 = bits.RotateLeft64(t, 21)
t = a[19] ^ d4 t = a[19] ^ d4
bc4 = t<<14 | t>>(64-14) bc4 = bits.RotateLeft64(t, 14)
a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+2] a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+2]
a[11] = bc1 ^ (bc3 &^ bc2) a[11] = bc1 ^ (bc3 &^ bc2)
a[22] = bc2 ^ (bc4 &^ bc3) a[22] = bc2 ^ (bc4 &^ bc3)
@ -256,15 +258,15 @@ func keccakF1600(a *[25]uint64) {
a[19] = bc4 ^ (bc1 &^ bc0) a[19] = bc4 ^ (bc1 &^ bc0)
t = a[15] ^ d0 t = a[15] ^ d0
bc2 = t<<3 | t>>(64-3) bc2 = bits.RotateLeft64(t, 3)
t = a[1] ^ d1 t = a[1] ^ d1
bc3 = t<<45 | t>>(64-45) bc3 = bits.RotateLeft64(t, 45)
t = a[12] ^ d2 t = a[12] ^ d2
bc4 = t<<61 | t>>(64-61) bc4 = bits.RotateLeft64(t, 61)
t = a[23] ^ d3 t = a[23] ^ d3
bc0 = t<<28 | t>>(64-28) bc0 = bits.RotateLeft64(t, 28)
t = a[9] ^ d4 t = a[9] ^ d4
bc1 = t<<20 | t>>(64-20) bc1 = bits.RotateLeft64(t, 20)
a[15] = bc0 ^ (bc2 &^ bc1) a[15] = bc0 ^ (bc2 &^ bc1)
a[1] = bc1 ^ (bc3 &^ bc2) a[1] = bc1 ^ (bc3 &^ bc2)
a[12] = bc2 ^ (bc4 &^ bc3) a[12] = bc2 ^ (bc4 &^ bc3)
@ -272,15 +274,15 @@ func keccakF1600(a *[25]uint64) {
a[9] = bc4 ^ (bc1 &^ bc0) a[9] = bc4 ^ (bc1 &^ bc0)
t = a[5] ^ d0 t = a[5] ^ d0
bc4 = t<<18 | t>>(64-18) bc4 = bits.RotateLeft64(t, 18)
t = a[16] ^ d1 t = a[16] ^ d1
bc0 = t<<1 | t>>(64-1) bc0 = bits.RotateLeft64(t, 1)
t = a[2] ^ d2 t = a[2] ^ d2
bc1 = t<<6 | t>>(64-6) bc1 = bits.RotateLeft64(t, 6)
t = a[13] ^ d3 t = a[13] ^ d3
bc2 = t<<25 | t>>(64-25) bc2 = bits.RotateLeft64(t, 25)
t = a[24] ^ d4 t = a[24] ^ d4
bc3 = t<<8 | t>>(64-8) bc3 = bits.RotateLeft64(t, 8)
a[5] = bc0 ^ (bc2 &^ bc1) a[5] = bc0 ^ (bc2 &^ bc1)
a[16] = bc1 ^ (bc3 &^ bc2) a[16] = bc1 ^ (bc3 &^ bc2)
a[2] = bc2 ^ (bc4 &^ bc3) a[2] = bc2 ^ (bc4 &^ bc3)
@ -288,15 +290,15 @@ func keccakF1600(a *[25]uint64) {
a[24] = bc4 ^ (bc1 &^ bc0) a[24] = bc4 ^ (bc1 &^ bc0)
t = a[20] ^ d0 t = a[20] ^ d0
bc1 = t<<36 | t>>(64-36) bc1 = bits.RotateLeft64(t, 36)
t = a[6] ^ d1 t = a[6] ^ d1
bc2 = t<<10 | t>>(64-10) bc2 = bits.RotateLeft64(t, 10)
t = a[17] ^ d2 t = a[17] ^ d2
bc3 = t<<15 | t>>(64-15) bc3 = bits.RotateLeft64(t, 15)
t = a[3] ^ d3 t = a[3] ^ d3
bc4 = t<<56 | t>>(64-56) bc4 = bits.RotateLeft64(t, 56)
t = a[14] ^ d4 t = a[14] ^ d4
bc0 = t<<27 | t>>(64-27) bc0 = bits.RotateLeft64(t, 27)
a[20] = bc0 ^ (bc2 &^ bc1) a[20] = bc0 ^ (bc2 &^ bc1)
a[6] = bc1 ^ (bc3 &^ bc2) a[6] = bc1 ^ (bc3 &^ bc2)
a[17] = bc2 ^ (bc4 &^ bc3) a[17] = bc2 ^ (bc4 &^ bc3)
@ -304,15 +306,15 @@ func keccakF1600(a *[25]uint64) {
a[14] = bc4 ^ (bc1 &^ bc0) a[14] = bc4 ^ (bc1 &^ bc0)
t = a[10] ^ d0 t = a[10] ^ d0
bc3 = t<<41 | t>>(64-41) bc3 = bits.RotateLeft64(t, 41)
t = a[21] ^ d1 t = a[21] ^ d1
bc4 = t<<2 | t>>(64-2) bc4 = bits.RotateLeft64(t, 2)
t = a[7] ^ d2 t = a[7] ^ d2
bc0 = t<<62 | t>>(64-62) bc0 = bits.RotateLeft64(t, 62)
t = a[18] ^ d3 t = a[18] ^ d3
bc1 = t<<55 | t>>(64-55) bc1 = bits.RotateLeft64(t, 55)
t = a[4] ^ d4 t = a[4] ^ d4
bc2 = t<<39 | t>>(64-39) bc2 = bits.RotateLeft64(t, 39)
a[10] = bc0 ^ (bc2 &^ bc1) a[10] = bc0 ^ (bc2 &^ bc1)
a[21] = bc1 ^ (bc3 &^ bc2) a[21] = bc1 ^ (bc3 &^ bc2)
a[7] = bc2 ^ (bc4 &^ bc3) a[7] = bc2 ^ (bc4 &^ bc3)
@ -333,13 +335,13 @@ func keccakF1600(a *[25]uint64) {
bc0 = a[0] ^ d0 bc0 = a[0] ^ d0
t = a[1] ^ d1 t = a[1] ^ d1
bc1 = t<<44 | t>>(64-44) bc1 = bits.RotateLeft64(t, 44)
t = a[2] ^ d2 t = a[2] ^ d2
bc2 = t<<43 | t>>(64-43) bc2 = bits.RotateLeft64(t, 43)
t = a[3] ^ d3 t = a[3] ^ d3
bc3 = t<<21 | t>>(64-21) bc3 = bits.RotateLeft64(t, 21)
t = a[4] ^ d4 t = a[4] ^ d4
bc4 = t<<14 | t>>(64-14) bc4 = bits.RotateLeft64(t, 14)
a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+3] a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+3]
a[1] = bc1 ^ (bc3 &^ bc2) a[1] = bc1 ^ (bc3 &^ bc2)
a[2] = bc2 ^ (bc4 &^ bc3) a[2] = bc2 ^ (bc4 &^ bc3)
@ -347,15 +349,15 @@ func keccakF1600(a *[25]uint64) {
a[4] = bc4 ^ (bc1 &^ bc0) a[4] = bc4 ^ (bc1 &^ bc0)
t = a[5] ^ d0 t = a[5] ^ d0
bc2 = t<<3 | t>>(64-3) bc2 = bits.RotateLeft64(t, 3)
t = a[6] ^ d1 t = a[6] ^ d1
bc3 = t<<45 | t>>(64-45) bc3 = bits.RotateLeft64(t, 45)
t = a[7] ^ d2 t = a[7] ^ d2
bc4 = t<<61 | t>>(64-61) bc4 = bits.RotateLeft64(t, 61)
t = a[8] ^ d3 t = a[8] ^ d3
bc0 = t<<28 | t>>(64-28) bc0 = bits.RotateLeft64(t, 28)
t = a[9] ^ d4 t = a[9] ^ d4
bc1 = t<<20 | t>>(64-20) bc1 = bits.RotateLeft64(t, 20)
a[5] = bc0 ^ (bc2 &^ bc1) a[5] = bc0 ^ (bc2 &^ bc1)
a[6] = bc1 ^ (bc3 &^ bc2) a[6] = bc1 ^ (bc3 &^ bc2)
a[7] = bc2 ^ (bc4 &^ bc3) a[7] = bc2 ^ (bc4 &^ bc3)
@ -363,15 +365,15 @@ func keccakF1600(a *[25]uint64) {
a[9] = bc4 ^ (bc1 &^ bc0) a[9] = bc4 ^ (bc1 &^ bc0)
t = a[10] ^ d0 t = a[10] ^ d0
bc4 = t<<18 | t>>(64-18) bc4 = bits.RotateLeft64(t, 18)
t = a[11] ^ d1 t = a[11] ^ d1
bc0 = t<<1 | t>>(64-1) bc0 = bits.RotateLeft64(t, 1)
t = a[12] ^ d2 t = a[12] ^ d2
bc1 = t<<6 | t>>(64-6) bc1 = bits.RotateLeft64(t, 6)
t = a[13] ^ d3 t = a[13] ^ d3
bc2 = t<<25 | t>>(64-25) bc2 = bits.RotateLeft64(t, 25)
t = a[14] ^ d4 t = a[14] ^ d4
bc3 = t<<8 | t>>(64-8) bc3 = bits.RotateLeft64(t, 8)
a[10] = bc0 ^ (bc2 &^ bc1) a[10] = bc0 ^ (bc2 &^ bc1)
a[11] = bc1 ^ (bc3 &^ bc2) a[11] = bc1 ^ (bc3 &^ bc2)
a[12] = bc2 ^ (bc4 &^ bc3) a[12] = bc2 ^ (bc4 &^ bc3)
@ -379,15 +381,15 @@ func keccakF1600(a *[25]uint64) {
a[14] = bc4 ^ (bc1 &^ bc0) a[14] = bc4 ^ (bc1 &^ bc0)
t = a[15] ^ d0 t = a[15] ^ d0
bc1 = t<<36 | t>>(64-36) bc1 = bits.RotateLeft64(t, 36)
t = a[16] ^ d1 t = a[16] ^ d1
bc2 = t<<10 | t>>(64-10) bc2 = bits.RotateLeft64(t, 10)
t = a[17] ^ d2 t = a[17] ^ d2
bc3 = t<<15 | t>>(64-15) bc3 = bits.RotateLeft64(t, 15)
t = a[18] ^ d3 t = a[18] ^ d3
bc4 = t<<56 | t>>(64-56) bc4 = bits.RotateLeft64(t, 56)
t = a[19] ^ d4 t = a[19] ^ d4
bc0 = t<<27 | t>>(64-27) bc0 = bits.RotateLeft64(t, 27)
a[15] = bc0 ^ (bc2 &^ bc1) a[15] = bc0 ^ (bc2 &^ bc1)
a[16] = bc1 ^ (bc3 &^ bc2) a[16] = bc1 ^ (bc3 &^ bc2)
a[17] = bc2 ^ (bc4 &^ bc3) a[17] = bc2 ^ (bc4 &^ bc3)
@ -395,15 +397,15 @@ func keccakF1600(a *[25]uint64) {
a[19] = bc4 ^ (bc1 &^ bc0) a[19] = bc4 ^ (bc1 &^ bc0)
t = a[20] ^ d0 t = a[20] ^ d0
bc3 = t<<41 | t>>(64-41) bc3 = bits.RotateLeft64(t, 41)
t = a[21] ^ d1 t = a[21] ^ d1
bc4 = t<<2 | t>>(64-2) bc4 = bits.RotateLeft64(t, 2)
t = a[22] ^ d2 t = a[22] ^ d2
bc0 = t<<62 | t>>(64-62) bc0 = bits.RotateLeft64(t, 62)
t = a[23] ^ d3 t = a[23] ^ d3
bc1 = t<<55 | t>>(64-55) bc1 = bits.RotateLeft64(t, 55)
t = a[24] ^ d4 t = a[24] ^ d4
bc2 = t<<39 | t>>(64-39) bc2 = bits.RotateLeft64(t, 39)
a[20] = bc0 ^ (bc2 &^ bc1) a[20] = bc0 ^ (bc2 &^ bc1)
a[21] = bc1 ^ (bc3 &^ bc2) a[21] = bc1 ^ (bc3 &^ bc2)
a[22] = bc2 ^ (bc4 &^ bc3) a[22] = bc2 ^ (bc4 &^ bc3)

View File

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build (386 || amd64 || amd64p32) && gccgo
// +build 386 amd64 amd64p32 // +build 386 amd64 amd64p32
// +build gccgo // +build gccgo

View File

@ -4,6 +4,11 @@
package cpu package cpu
import (
"strings"
"syscall"
)
// HWCAP/HWCAP2 bits. These are exposed by Linux. // HWCAP/HWCAP2 bits. These are exposed by Linux.
const ( const (
hwcap_FP = 1 << 0 hwcap_FP = 1 << 0
@ -32,10 +37,45 @@ const (
hwcap_ASIMDFHM = 1 << 23 hwcap_ASIMDFHM = 1 << 23
) )
// linuxKernelCanEmulateCPUID reports whether we're running
// on Linux 4.11+. Ideally we'd like to ask the question about
// whether the current kernel contains
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=77c97b4ee21290f5f083173d957843b615abbff2
// but the version number will have to do.
func linuxKernelCanEmulateCPUID() bool {
var un syscall.Utsname
syscall.Uname(&un)
var sb strings.Builder
for _, b := range un.Release[:] {
if b == 0 {
break
}
sb.WriteByte(byte(b))
}
major, minor, _, ok := parseRelease(sb.String())
return ok && (major > 4 || major == 4 && minor >= 11)
}
func doinit() { func doinit() {
if err := readHWCAP(); err != nil { if err := readHWCAP(); err != nil {
// failed to read /proc/self/auxv, try reading registers directly // We failed to read /proc/self/auxv. This can happen if the binary has
// been given extra capabilities(7) with /bin/setcap.
//
// When this happens, we have two options. If the Linux kernel is new
// enough (4.11+), we can read the arm64 registers directly which'll
// trap into the kernel and then return back to userspace.
//
// But on older kernels, such as Linux 4.4.180 as used on many Synology
// devices, calling readARM64Registers (specifically getisar0) will
// cause a SIGILL and we'll die. So for older kernels, parse /proc/cpuinfo
// instead.
//
// See golang/go#57336.
if linuxKernelCanEmulateCPUID() {
readARM64Registers() readARM64Registers()
} else {
readLinuxProcCPUInfo()
}
return return
} }

11
vendor/golang.org/x/sys/cpu/endian_big.go generated vendored Normal file
View File

@ -0,0 +1,11 @@
// Copyright 2023 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 armbe || arm64be || m68k || mips || mips64 || mips64p32 || ppc || ppc64 || s390 || s390x || shbe || sparc || sparc64
// +build armbe arm64be m68k mips mips64 mips64p32 ppc ppc64 s390 s390x shbe sparc sparc64
package cpu
// IsBigEndian records whether the GOARCH's byte order is big endian.
const IsBigEndian = true

11
vendor/golang.org/x/sys/cpu/endian_little.go generated vendored Normal file
View File

@ -0,0 +1,11 @@
// Copyright 2023 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 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh
// +build 386 amd64 amd64p32 alpha arm arm64 loong64 mipsle mips64le mips64p32le nios2 ppc64le riscv riscv64 sh
package cpu
// IsBigEndian records whether the GOARCH's byte order is big endian.
const IsBigEndian = false

View File

@ -24,6 +24,21 @@ var hwCap uint
var hwCap2 uint var hwCap2 uint
func readHWCAP() error { func readHWCAP() error {
// For Go 1.21+, get auxv from the Go runtime.
if a := getAuxv(); len(a) > 0 {
for len(a) >= 2 {
tag, val := a[0], uint(a[1])
a = a[2:]
switch tag {
case _AT_HWCAP:
hwCap = val
case _AT_HWCAP2:
hwCap2 = val
}
}
return nil
}
buf, err := ioutil.ReadFile(procAuxv) buf, err := ioutil.ReadFile(procAuxv)
if err != nil { if err != nil {
// e.g. on android /proc/self/auxv is not accessible, so silently // e.g. on android /proc/self/auxv is not accessible, so silently

43
vendor/golang.org/x/sys/cpu/parse.go generated vendored Normal file
View File

@ -0,0 +1,43 @@
// Copyright 2022 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.
package cpu
import "strconv"
// parseRelease parses a dot-separated version number. It follows the semver
// syntax, but allows the minor and patch versions to be elided.
//
// This is a copy of the Go runtime's parseRelease from
// https://golang.org/cl/209597.
func parseRelease(rel string) (major, minor, patch int, ok bool) {
// Strip anything after a dash or plus.
for i := 0; i < len(rel); i++ {
if rel[i] == '-' || rel[i] == '+' {
rel = rel[:i]
break
}
}
next := func() (int, bool) {
for i := 0; i < len(rel); i++ {
if rel[i] == '.' {
ver, err := strconv.Atoi(rel[:i])
rel = rel[i+1:]
return ver, err == nil
}
}
ver, err := strconv.Atoi(rel)
rel = ""
return ver, err == nil
}
if major, ok = next(); !ok || rel == "" {
return
}
if minor, ok = next(); !ok || rel == "" {
return
}
patch, ok = next()
return
}

54
vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go generated vendored Normal file
View File

@ -0,0 +1,54 @@
// Copyright 2022 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 linux && arm64
// +build linux,arm64
package cpu
import (
"errors"
"io"
"os"
"strings"
)
func readLinuxProcCPUInfo() error {
f, err := os.Open("/proc/cpuinfo")
if err != nil {
return err
}
defer f.Close()
var buf [1 << 10]byte // enough for first CPU
n, err := io.ReadFull(f, buf[:])
if err != nil && err != io.ErrUnexpectedEOF {
return err
}
in := string(buf[:n])
const features = "\nFeatures : "
i := strings.Index(in, features)
if i == -1 {
return errors.New("no CPU features found")
}
in = in[i+len(features):]
if i := strings.Index(in, "\n"); i != -1 {
in = in[:i]
}
m := map[string]*bool{}
initOptions() // need it early here; it's harmless to call twice
for _, o := range options {
m[o.Name] = o.Feature
}
// The EVTSTRM field has alias "evstrm" in Go, but Linux calls it "evtstrm".
m["evtstrm"] = &ARM64.HasEVTSTRM
for _, f := range strings.Fields(in) {
if p, ok := m[f]; ok {
*p = true
}
}
return nil
}

16
vendor/golang.org/x/sys/cpu/runtime_auxv.go generated vendored Normal file
View File

@ -0,0 +1,16 @@
// Copyright 2023 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.
package cpu
// getAuxvFn is non-nil on Go 1.21+ (via runtime_auxv_go121.go init)
// on platforms that use auxv.
var getAuxvFn func() []uintptr
func getAuxv() []uintptr {
if getAuxvFn == nil {
return nil
}
return getAuxvFn()
}

19
vendor/golang.org/x/sys/cpu/runtime_auxv_go121.go generated vendored Normal file
View File

@ -0,0 +1,19 @@
// Copyright 2023 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 go1.21
// +build go1.21
package cpu
import (
_ "unsafe" // for linkname
)
//go:linkname runtime_getAuxv runtime.getAuxv
func runtime_getAuxv() []uintptr
func init() {
getAuxvFn = runtime_getAuxv
}

10
vendor/modules.txt vendored
View File

@ -10,8 +10,8 @@ github.com/cretz/bine/torutil/ed25519/internal/edwards25519
## explicit ## explicit
# github.com/denisenkom/go-mssqldb v0.12.3 # github.com/denisenkom/go-mssqldb v0.12.3
## explicit; go 1.13 ## explicit; go 1.13
# github.com/go-sql-driver/mysql v1.6.0 # github.com/go-sql-driver/mysql v1.7.0
## explicit; go 1.10 ## explicit; go 1.13
github.com/go-sql-driver/mysql github.com/go-sql-driver/mysql
# github.com/jinzhu/gorm v1.9.16 # github.com/jinzhu/gorm v1.9.16
## explicit; go 1.12 ## explicit; go 1.12
@ -29,15 +29,15 @@ github.com/jmoiron/sqlx/reflectx
## explicit; go 1.13 ## explicit; go 1.13
# github.com/mattn/go-sqlite3 v2.0.3+incompatible # github.com/mattn/go-sqlite3 v2.0.3+incompatible
## explicit ## explicit
# golang.org/x/crypto v0.1.0 # golang.org/x/crypto v0.7.0
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519
golang.org/x/crypto/sha3 golang.org/x/crypto/sha3
# golang.org/x/net v0.1.0 # golang.org/x/net v0.8.0
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/net/internal/socks golang.org/x/net/internal/socks
golang.org/x/net/proxy golang.org/x/net/proxy
# golang.org/x/sys v0.1.0 # golang.org/x/sys v0.6.0
## explicit; go 1.17 ## explicit; go 1.17
golang.org/x/sys/cpu golang.org/x/sys/cpu
# gopkg.in/ini.v1 v1.67.0 # gopkg.in/ini.v1 v1.67.0