Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6236debaf | ||
|
|
13bb950ee3 | ||
|
|
29b620a4fb | ||
|
|
17ae8fbac0 |
No files matched your search
@@ -16,7 +16,7 @@ on:
|
||||
env:
|
||||
NODE_VERSION: '24'
|
||||
PNPM_VERSION: '10.28.1'
|
||||
GOLANG_BUILD_IMAGE: 'golang:1.25.12-alpine3.23@sha256:cc985ef6f9c3bf9ece7488129c9abe0a150388ccdfa428d886fc709dca0b230a'
|
||||
GOLANG_BUILD_IMAGE: 'golang:1.25.13-alpine3.23@sha256:42fc3368d1c50170a452f2bf4a1dfd292a065870c3f258d799aad4316671cb69'
|
||||
|
||||
jobs:
|
||||
determine-release-type:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Table of Contents
|
||||
|
||||
* [Changelog for 8.0.8](#changelog-for-808-2026-08-20)
|
||||
* [Changelog for 8.0.7](#changelog-for-807-2026-07-31)
|
||||
* [Changelog for 8.0.6](#changelog-for-806-2026-07-15)
|
||||
* [Changelog for 8.0.5](#changelog-for-805-2026-06-18)
|
||||
@@ -66,6 +67,67 @@
|
||||
* [Changelog for 1.1.0](#changelog-for-110-2021-01-22)
|
||||
* [Changelog for 1.0.0](#changelog-for-100-2020-12-17)
|
||||
|
||||
# Changelog for [8.0.8] (2026-08-20)
|
||||
|
||||
The following sections list the changes for 8.0.8.
|
||||
|
||||
[8.0.8]: https://github.com/owncloud/ocis/compare/v8.0.7...v8.0.8
|
||||
|
||||
## Summary
|
||||
|
||||
* Security - Bump golang.org/x/image to v0.45.0: [#12808](https://github.com/owncloud/ocis/pull/12808)
|
||||
* Security - Bump Go to 1.25.13: [#12832](https://github.com/owncloud/ocis/pull/12832)
|
||||
* Bugfix - Cache LDAP instance mapper lookups: [#12823](https://github.com/owncloud/ocis/pull/12823)
|
||||
* Bugfix - Fix share metadata corruption during concurrent share operations: [#12621](https://github.com/owncloud/ocis/pull/12621)
|
||||
* Enhancement - Add TLS support for NATS store and registry connections: [#12765](https://github.com/owncloud/ocis/pull/12765)
|
||||
|
||||
## Details
|
||||
|
||||
* Security - Bump golang.org/x/image to v0.45.0: [#12808](https://github.com/owncloud/ocis/pull/12808)
|
||||
|
||||
Upgraded golang.org/x/image from v0.44.0 to v0.45.0 to address
|
||||
GO-2026-6222: excessive memory allocation during VP8L decoding.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12808
|
||||
|
||||
* Security - Bump Go to 1.25.13: [#12832](https://github.com/owncloud/ocis/pull/12832)
|
||||
|
||||
Fixes a stdlib CVE vulnerability flagged by the release image scan.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12832
|
||||
|
||||
* Bugfix - Cache LDAP instance mapper lookups: [#12823](https://github.com/owncloud/ocis/pull/12823)
|
||||
|
||||
In multi-instance deployments, resolving a user's instance name/ID during
|
||||
`GET /graph/v1.0/users` (and group member expansion) issued a fresh, uncached
|
||||
LDAP search per instance/guest attribute value on every request. Under load
|
||||
this multiplied into large numbers of redundant LDAP round-trips per page of
|
||||
users, saturating the LDAP connection pool and causing request timeouts. The
|
||||
LDAP identity backend now caches instance mapper lookups, including negative
|
||||
(not-found) results, for a configurable TTL
|
||||
(`OCIS_LDAP_INSTANCE_MAPPER_CACHE_TTL`, default 60s).
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12823
|
||||
|
||||
* Bugfix - Fix share metadata corruption during concurrent share operations: [#12621](https://github.com/owncloud/ocis/pull/12621)
|
||||
|
||||
When multiple sharing service replicas processed share operations concurrently
|
||||
for the same user, the share metadata could become corrupted with references to
|
||||
missing data, making all shares inaccessible to that user. The received share
|
||||
cache now uses compare-and-swap (etag) validation to detect concurrent writes
|
||||
and retries gracefully, preventing metadata corruption.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12621
|
||||
|
||||
* Enhancement - Add TLS support for NATS store and registry connections: [#12765](https://github.com/owncloud/ocis/pull/12765)
|
||||
|
||||
All `nats-js-kv` store, cache, and service registry connections now support
|
||||
TLS. Configure via `OCIS_CACHE_ENABLE_TLS`, `OCIS_PERSISTENT_STORE_ENABLE_TLS`,
|
||||
and `MICRO_REGISTRY_ENABLE_TLS`, with corresponding `*_TLS_INSECURE` and
|
||||
`*_TLS_ROOT_CA_CERTIFICATE` variants per connection type.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12765
|
||||
|
||||
# Changelog for [8.0.7] (2026-07-31)
|
||||
|
||||
The following sections list the changes for 8.0.7.
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ RUN make ci-go-generate build ENABLE_VIPS=true
|
||||
FROM alpine:3.23.3
|
||||
|
||||
RUN apk add --no-cache attr ca-certificates curl mailcap tree \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.4-r1" \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.5-r0" \
|
||||
&& echo 'hosts: files dns' >| /etc/nsswitch.conf
|
||||
|
||||
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
|
||||
|
||||
+2
@@ -8,3 +8,5 @@ users, saturating the LDAP connection pool and causing request timeouts. The
|
||||
LDAP identity backend now caches instance mapper lookups, including negative
|
||||
(not-found) results, for a configurable TTL
|
||||
(`OCIS_LDAP_INSTANCE_MAPPER_CACHE_TTL`, default 60s).
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12823
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,5 @@
|
||||
Security: Bump Go to 1.25.13
|
||||
|
||||
Fixes a stdlib CVE vulnerability flagged by the release image scan.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12832
|
||||
File renamed without changes.
@@ -1,6 +1,6 @@
|
||||
module github.com/owncloud/ocis/v2
|
||||
|
||||
go 1.25.12
|
||||
go 1.25.13
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.2
|
||||
@@ -95,17 +95,17 @@ require (
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0
|
||||
go.opentelemetry.io/otel/sdk v1.45.0
|
||||
go.opentelemetry.io/otel/trace v1.45.0
|
||||
golang.org/x/crypto v0.54.0
|
||||
golang.org/x/crypto v0.55.0
|
||||
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f
|
||||
golang.org/x/image v0.45.0
|
||||
golang.org/x/net v0.57.0
|
||||
golang.org/x/net v0.58.0
|
||||
golang.org/x/oauth2 v0.36.0
|
||||
golang.org/x/sync v0.22.0
|
||||
golang.org/x/term v0.45.0
|
||||
golang.org/x/text v0.41.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d
|
||||
google.golang.org/grpc v1.83.0
|
||||
google.golang.org/protobuf v1.36.11
|
||||
google.golang.org/grpc v1.83.1
|
||||
google.golang.org/protobuf v1.36.12
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
gotest.tools/v3 v3.5.2
|
||||
stash.kopano.io/kgol/rndm v1.1.2
|
||||
@@ -120,7 +120,7 @@ require (
|
||||
github.com/Masterminds/semver/v3 v3.5.0 // indirect
|
||||
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.1.6 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.4.1 // indirect
|
||||
github.com/RoaringBitmap/roaring/v2 v2.14.5 // indirect
|
||||
github.com/agnivade/levenshtein v1.2.1 // indirect
|
||||
github.com/ajg/form v1.5.1 // indirect
|
||||
@@ -158,14 +158,14 @@ require (
|
||||
github.com/cevaris/ordered_map v0.0.0-20190319150403-3adeae072e73 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.11.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/cloudflare/circl v1.6.3 // indirect
|
||||
github.com/cloudflare/circl v1.6.5 // indirect
|
||||
github.com/coreos/go-semver v0.3.1 // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.7.0 // indirect
|
||||
github.com/cornelk/hashmap v1.0.8 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
|
||||
github.com/crewjam/httperr v0.2.0 // indirect
|
||||
github.com/crewjam/saml v0.4.14 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.7.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/deckarep/golang-set v1.8.0 // indirect
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect
|
||||
@@ -186,7 +186,7 @@ require (
|
||||
github.com/go-acme/lego/v4 v4.34.0 // indirect
|
||||
github.com/go-asn1-ber/asn1-ber v1.5.8 // indirect
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.9.0 // indirect
|
||||
github.com/go-git/go-billy/v5 v5.9.1 // indirect
|
||||
github.com/go-git/go-git/v5 v5.19.2 // indirect
|
||||
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
|
||||
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
|
||||
@@ -238,9 +238,9 @@ require (
|
||||
github.com/jonboulle/clockwork v0.5.0 // indirect
|
||||
github.com/json-iterator/go v1.1.13-0.20220915233716-71ac16282d12 // indirect
|
||||
github.com/juliangruber/go-intersect v1.1.0 // indirect
|
||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||
github.com/kevinburke/ssh_config v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.19.1 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 // indirect
|
||||
github.com/klauspost/crc32 v1.3.0 // indirect
|
||||
github.com/kovidgoyal/go-parallel v1.1.1 // indirect
|
||||
github.com/kovidgoyal/go-shm v1.0.0 // indirect
|
||||
@@ -308,7 +308,7 @@ require (
|
||||
github.com/sercand/kuberesolver/v5 v5.1.1 // indirect
|
||||
github.com/sergi/go-diff v1.4.0 // indirect
|
||||
github.com/sethvargo/go-password v0.4.0 // indirect
|
||||
github.com/skeema/knownhosts v1.3.1 // indirect
|
||||
github.com/skeema/knownhosts v1.3.2 // indirect
|
||||
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784 // indirect
|
||||
github.com/spf13/pflag v1.0.10 // indirect
|
||||
github.com/stretchr/objx v0.5.3 // indirect
|
||||
@@ -340,12 +340,12 @@ require (
|
||||
go.uber.org/zap v1.27.1 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.4 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.5 // indirect
|
||||
golang.org/x/mod v0.38.0 // indirect
|
||||
golang.org/x/mod v0.40.0 // indirect
|
||||
golang.org/x/sys v0.47.0 // indirect
|
||||
golang.org/x/time v0.15.0 // indirect
|
||||
golang.org/x/tools v0.48.0 // indirect
|
||||
golang.org/x/tools v0.49.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 // indirect
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.3 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
|
||||
@@ -68,8 +68,8 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
|
||||
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
||||
github.com/Nerzal/gocloak/v13 v13.9.0 h1:YWsJsdM5b0yhM2Ba3MLydiOlujkBry4TtdzfIzSVZhw=
|
||||
github.com/Nerzal/gocloak/v13 v13.9.0/go.mod h1:YYuDcXZ7K2zKECyVP7pPqjKxx2AzYSpKDj8d6GuyM10=
|
||||
github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw=
|
||||
github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
|
||||
github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM=
|
||||
github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo=
|
||||
github.com/RoaringBitmap/roaring/v2 v2.14.5 h1:ckd0o545JqDPeVJDgeFoaM21eBixUnlWfYgjE5VnyWw=
|
||||
github.com/RoaringBitmap/roaring/v2 v2.14.5/go.mod h1:eq4wdNXxtJIS/oikeCzdX1rBzek7ANzbth041hrU8Q4=
|
||||
github.com/agnivade/levenshtein v1.2.1 h1:EHBY3UOn1gwdy/VbFwgo4cxecRznFk7fKWN1KOX7eoM=
|
||||
@@ -183,8 +183,8 @@ github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSE
|
||||
github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
|
||||
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/cloudflare/circl v1.6.5 h1:O64F26HEqNhznd/hrC5KZXVKYuKM2rx4deZDTc4ihQA=
|
||||
github.com/cloudflare/circl v1.6.5/go.mod h1:h5LNyxAc5nTue9DS5jT+48en2PSDYt3zdGnz5OstK6c=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/coreos/go-oidc/v3 v3.20.0 h1:EtE0WIBHk03N+DqGkY4+UONzzZHk7amKt6IyNd7OsZE=
|
||||
github.com/coreos/go-oidc/v3 v3.20.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4=
|
||||
@@ -203,8 +203,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
|
||||
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1 h1:RU6LT6mkD16xZs011+8foU7T3LrPvTTSWeTQ9OgfhkA=
|
||||
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1/go.mod h1:DedpcqXl193qF/08Y04IO0PpxyyMu8+GrkD6kWK2MEQ=
|
||||
github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE=
|
||||
github.com/cyphar/filepath-securejoin v0.6.1/go.mod h1:A8hd4EnAeyujCJRrICiOWqjS1AX0a9kM5XL+NwKoYSc=
|
||||
github.com/cyphar/filepath-securejoin v0.7.0 h1:s0Y3ITPy6sQn5xt54DuYvTF8hu134ooYLUb58DX/HjE=
|
||||
github.com/cyphar/filepath-securejoin v0.7.0/go.mod h1:ymLGms/u3BYaviIiuKFnUx8EkQEZeK6cInNoAPJA3o4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
@@ -292,8 +292,8 @@ github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
|
||||
github.com/go-chi/render v1.0.3/go.mod h1:/gr3hVkmYR0YlEy3LxCuVRFzEu9Ruok+gFqbIofjao0=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI=
|
||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic=
|
||||
github.com/go-git/go-billy/v5 v5.9.0 h1:jItGXszUDRtR/AlferWPTMN4j38BQ88XnXKbilmmBPA=
|
||||
github.com/go-git/go-billy/v5 v5.9.0/go.mod h1:jCnQMLj9eUgGU7+ludSTYoZL/GGmii14RxKFj7ROgHw=
|
||||
github.com/go-git/go-billy/v5 v5.9.1 h1:8U73XiOTfINdItHVa6z4Gv7ToObcZ6grkqQbLryLCdA=
|
||||
github.com/go-git/go-billy/v5 v5.9.1/go.mod h1:ExsU+jcGwXTBOnyilvAnEM1wug1IxHr4yP2ZXsNRtV0=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
|
||||
github.com/go-git/go-git/v5 v5.19.2 h1:wkfn7vOlUBu8ivAWKBWisTiwJK4jYHzTF8Ndv1LyGqY=
|
||||
@@ -568,15 +568,15 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/justinas/alice v1.2.0 h1:+MHSA/vccVCF4Uq37S42jwlkvI2Xzl7zTPCN5BnZNVo=
|
||||
github.com/justinas/alice v1.2.0/go.mod h1:fN5HRH/reO/zrUflLfTN43t3vXvKzvZIENsNEe7i7qA=
|
||||
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
|
||||
github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.19.1 h1:VsB4HPswih7mmZ8WleSFQ75c/Ui1M4trX5oAsJnhSlk=
|
||||
github.com/klauspost/compress v1.19.1/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/klauspost/cpuid/v2 v2.4.0 h1:S6Hrbc7+ywsr0r+RLapfGBHfyefhCTwEh3A0tV913Dw=
|
||||
github.com/klauspost/cpuid/v2 v2.4.0/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU=
|
||||
github.com/klauspost/crc32 v1.3.0 h1:sSmTt3gUt81RP655XGZPElI0PelVTZ6YwCRnPSupoFM=
|
||||
github.com/klauspost/crc32 v1.3.0/go.mod h1:D7kQaZhnkX/Y0tstFGf8VUzv2UofNGqCjnC3zdHB0Hw=
|
||||
github.com/kobergj/go-micro/v4 v4.0.0-20250610135441-d0b187215699 h1:3TOdtI6WPyvBB+uCykapjRtQX8vTHMlyhINzR+58B4k=
|
||||
@@ -847,8 +847,8 @@ github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrf
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
|
||||
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
|
||||
github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8=
|
||||
github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY=
|
||||
github.com/skeema/knownhosts v1.3.2 h1:EDL9mgf4NzwMXCTfaxSD/o/a5fxDw/xL9nkU28JjdBg=
|
||||
github.com/skeema/knownhosts v1.3.2/go.mod h1:bEg3iQAuw+jyiw+484wwFJoKSLwcfd7fqRy+N0QTiow=
|
||||
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784 h1:0jjO3HdJfOn6gYHD/ZNZh0LLMxEAqkYX7xoDPQReEgs=
|
||||
github.com/spacewander/go-suffix-tree v0.0.0-20191010040751-0865e368c784/go.mod h1:ff/5myEGgtsAwf26goQCO905GrEm5ugEZSd6OWTsrhM=
|
||||
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
|
||||
@@ -1014,8 +1014,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/crypto v0.54.0 h1:YLIA59K4fiNzHzjnZt2tUJQjQtUWfWbeHBqKtk3eScw=
|
||||
golang.org/x/crypto v0.54.0/go.mod h1:KWL8ny2AZdGR2cWmzeHrp2azQPGogOv+HeQaVEXC2dk=
|
||||
golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M=
|
||||
golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
@@ -1053,8 +1053,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk=
|
||||
golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40=
|
||||
golang.org/x/mod v0.40.0 h1:hUv+3cXcdRHz08UmSiOob7sadHig73uo5bkXxQ/tvUs=
|
||||
golang.org/x/mod v0.40.0/go.mod h1:0/weTWkPWGBikyTWAX3dkjVztMmBA5hM0DH6BElSupE=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
@@ -1098,8 +1098,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
||||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/net v0.57.0 h1:K5+3DljvIuDG9/Jv9rvyMywYNFCQ9RSUY6OOTTkT+tE=
|
||||
golang.org/x/net v0.57.0/go.mod h1:KpXc8iv+r3XplLAG/f7Jsf9RPszJzdR0f58q9vGOuEU=
|
||||
golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To=
|
||||
golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -1263,8 +1263,8 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f
|
||||
golang.org/x/tools v0.0.0-20210112230658-8b4aab62c064/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE=
|
||||
golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk=
|
||||
golang.org/x/tools v0.49.0 h1:3NI7VXzL9+1WZD52Dx2ttoPwD5DWrFGpl9mFZDlmisI=
|
||||
golang.org/x/tools v0.49.0/go.mod h1:SJNXV9DBKT0UbdttsQjbfJlAE/q+y36++zo3uL3N0Oo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -1327,8 +1327,8 @@ google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 h1:XzmzkmB14QhVhgn
|
||||
google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:L43LFes82YgSonw6iTXTxXUX1OlULt4AQtkik4ULL/I=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d h1:FarXi840EJWSHYTN3ERkADbPWjl307+FGrA22KAVjjc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260803160001-6ac0973c030d/go.mod h1:K/+WGbmBY7aNW1HDw1fJnKYo10i0DkAX6pows00dLig=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d h1:IL4hdHzcUv2l/gcg98/Rj3FbtE6axwqslOW8SW0C+S0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260803160001-6ac0973c030d/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 h1:cYNAzI2sUwhmCcoj9TxvihSrqsxt6uIkj3rDRhSDmW4=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
@@ -1342,8 +1342,8 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji
|
||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.83.0 h1:JeNZEKJFbQxArAMl+hiytHauacDNqJUllNfmIMmpqnQ=
|
||||
google.golang.org/grpc v1.83.0/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
|
||||
google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y=
|
||||
google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ=
|
||||
google.golang.org/grpc/examples v0.0.0-20211102180624-670c133e568e h1:m7aQHHqd0q89mRwhwS9Bx2rjyl/hsFAeta+uGrHsQaU=
|
||||
google.golang.org/grpc/examples v0.0.0-20211102180624-670c133e568e/go.mod h1:gID3PKrg7pWKntu9Ss6zTLJ0ttC0X9IHgREOCZwbCVU=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
@@ -1360,8 +1360,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
|
||||
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y=
|
||||
gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI=
|
||||
|
||||
@@ -16,7 +16,7 @@ var (
|
||||
// LatestTag is the latest released version plus the dev meta version.
|
||||
// Will be overwritten by the release pipeline
|
||||
// Needs a manual change for every tagged release
|
||||
LatestTag = "8.0.7"
|
||||
LatestTag = "8.0.8"
|
||||
|
||||
// Date indicates the build date.
|
||||
// This has been removed, it looks like you can only replace static strings with recent go versions
|
||||
|
||||
@@ -5,7 +5,7 @@ ARG REVISION=""
|
||||
|
||||
RUN apk upgrade --no-cache \
|
||||
&& apk add --no-cache attr bash ca-certificates curl inotify-tools libc6-compat mailcap tree patch \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.4-r1" \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.5-r0" \
|
||||
&& echo 'hosts: files dns' >| /etc/nsswitch.conf
|
||||
|
||||
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
|
||||
|
||||
@@ -5,7 +5,7 @@ ARG REVISION=""
|
||||
|
||||
RUN apk upgrade --no-cache \
|
||||
&& apk add --no-cache attr bash ca-certificates curl inotify-tools libc6-compat mailcap tree patch \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.4-r1" \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.5-r0" \
|
||||
&& echo 'hosts: files dns' >| /etc/nsswitch.conf
|
||||
|
||||
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
|
||||
|
||||
@@ -5,7 +5,7 @@ ARG REVISION=""
|
||||
|
||||
RUN apk upgrade --no-cache \
|
||||
&& apk add --no-cache attr bash ca-certificates curl delve inotify-tools libc6-compat mailcap tree patch \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.4-r1" \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.5-r0" \
|
||||
&& echo 'hosts: files dns' >| /etc/nsswitch.conf
|
||||
|
||||
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
|
||||
|
||||
@@ -5,7 +5,7 @@ ARG REVISION=""
|
||||
|
||||
RUN apk upgrade --no-cache \
|
||||
&& apk add --no-cache attr bash ca-certificates curl delve inotify-tools libc6-compat mailcap tree patch \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.4-r1" \
|
||||
&& apk add --no-cache --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community "vips=8.18.5-r0" \
|
||||
&& echo 'hosts: files dns' >| /etc/nsswitch.conf
|
||||
|
||||
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
sonar.projectKey=owncloud_ocis
|
||||
sonar.organization=owncloud-1
|
||||
sonar.projectName=ocis
|
||||
sonar.projectVersion=8.0.7
|
||||
sonar.projectVersion=8.0.8
|
||||
sonar.host.url=https://sonarcloud.io
|
||||
|
||||
# =====================================================
|
||||
|
||||
+2
@@ -69,6 +69,8 @@ func (l *lineReader) Read(p []byte) (n int, err error) {
|
||||
if isPrefix {
|
||||
return 0, ArmorCorrupt
|
||||
}
|
||||
// Trim the line to remove any whitespace
|
||||
line = bytes.TrimSpace(line)
|
||||
|
||||
if bytes.HasPrefix(line, armorEnd) {
|
||||
l.eof = true
|
||||
|
||||
+10
@@ -180,6 +180,16 @@ func (dke ErrMalformedMessage) Error() string {
|
||||
return "openpgp: malformed message " + string(dke)
|
||||
}
|
||||
|
||||
type messageTooLargeError int
|
||||
|
||||
func (e messageTooLargeError) Error() string {
|
||||
return "openpgp: decompressed message size exceeds provided limit"
|
||||
}
|
||||
|
||||
// ErrMessageTooLarge is returned if the read data from
|
||||
// a compressed packet exceeds the provided limit.
|
||||
var ErrMessageTooLarge error = messageTooLargeError(0)
|
||||
|
||||
// ErrEncryptionKeySelection is returned if encryption key selection fails (v2 API).
|
||||
type ErrEncryptionKeySelection struct {
|
||||
PrimaryKeyId string
|
||||
|
||||
+8
-2
@@ -125,7 +125,10 @@ func (c *curve25519) Encaps(rand io.Reader, point []byte) (ephemeral, sharedSecr
|
||||
// "VB = convert point V to the octet string"
|
||||
// sharedPoint corresponds to `VB`.
|
||||
var sharedPoint x25519lib.Key
|
||||
x25519lib.Shared(&sharedPoint, &ephemeralPrivate, &pubKey)
|
||||
ok := x25519lib.Shared(&sharedPoint, &ephemeralPrivate, &pubKey)
|
||||
if !ok {
|
||||
return nil, nil, errors.KeyInvalidError("ecc: the public key is a low order point")
|
||||
}
|
||||
|
||||
return ephemeralPublic[:], sharedPoint[:], nil
|
||||
}
|
||||
@@ -146,7 +149,10 @@ func (c *curve25519) Decaps(vsG, secret []byte) (sharedSecret []byte, err error)
|
||||
// RFC6637 §8: "Note that the recipient obtains the shared secret by calculating
|
||||
// S = rV = rvG, where (r,R) is the recipient's key pair."
|
||||
// sharedPoint corresponds to `S`.
|
||||
x25519lib.Shared(&sharedPoint, &decodedPrivate, &ephemeralPublic)
|
||||
ok := x25519lib.Shared(&sharedPoint, &decodedPrivate, &ephemeralPublic)
|
||||
if !ok {
|
||||
return nil, errors.KeyInvalidError("ecc: the public key is a low order point")
|
||||
}
|
||||
|
||||
return sharedPoint[:], nil
|
||||
}
|
||||
|
||||
+4
-1
@@ -78,7 +78,7 @@ func (c *genericCurve) GenerateECDSA(rand io.Reader) (x, y, secret *big.Int, err
|
||||
func (c *genericCurve) Encaps(rand io.Reader, point []byte) (ephemeral, sharedSecret []byte, err error) {
|
||||
xP, yP := elliptic.Unmarshal(c.Curve, point)
|
||||
if xP == nil {
|
||||
panic("invalid point")
|
||||
return nil, nil, errors.KeyInvalidError(fmt.Sprintf("ecc (%s): invalid point", c.Curve.Params().Name))
|
||||
}
|
||||
|
||||
d, x, y, err := elliptic.GenerateKey(c.Curve, rand)
|
||||
@@ -99,6 +99,9 @@ func (c *genericCurve) Encaps(rand io.Reader, point []byte) (ephemeral, sharedSe
|
||||
|
||||
func (c *genericCurve) Decaps(ephemeral, secret []byte) (sharedSecret []byte, err error) {
|
||||
x, y := elliptic.Unmarshal(c.Curve, ephemeral)
|
||||
if x == nil {
|
||||
return nil, errors.KeyInvalidError(fmt.Sprintf("ecc (%s): invalid point", c.Curve.Params().Name))
|
||||
}
|
||||
zbBig, _ := c.Curve.ScalarMult(x, y, secret)
|
||||
byteLen := (c.Curve.Params().BitSize + 7) >> 3
|
||||
zb := make([]byte, byteLen)
|
||||
|
||||
+3
-3
@@ -37,7 +37,7 @@ func (conf *AEADConfig) Mode() AEADMode {
|
||||
|
||||
// ChunkSizeByte returns the byte indicating the chunk size. The effective
|
||||
// chunk size is computed with the formula uint64(1) << (chunkSizeByte + 6)
|
||||
// limit to 16 = 4 MiB
|
||||
// limit chunkSizeByte to 16 which equals to 2^22 = 4 MiB
|
||||
// https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-07.html#section-5.13.2
|
||||
func (conf *AEADConfig) ChunkSizeByte() byte {
|
||||
if conf == nil || conf.ChunkSize == 0 {
|
||||
@@ -49,8 +49,8 @@ func (conf *AEADConfig) ChunkSizeByte() byte {
|
||||
switch {
|
||||
case exponent < 6:
|
||||
exponent = 6
|
||||
case exponent > 16:
|
||||
exponent = 16
|
||||
case exponent > 22:
|
||||
exponent = 22
|
||||
}
|
||||
|
||||
return byte(exponent - 6)
|
||||
|
||||
+31
@@ -98,6 +98,16 @@ func (c *Compressed) parse(r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// LimitedBodyReader wraps the provided body reader with a limiter that restricts
|
||||
// the number of bytes read to the specified limit.
|
||||
// If limit is nil, the reader is unbounded.
|
||||
func (c *Compressed) LimitedBodyReader(limit *int64) io.Reader {
|
||||
if limit == nil {
|
||||
return c.Body
|
||||
}
|
||||
return &LimitReader{R: c.Body, N: *limit}
|
||||
}
|
||||
|
||||
// compressedWriterCloser represents the serialized compression stream
|
||||
// header and the compressor. Its Close() method ensures that both the
|
||||
// compressor and serialized stream header are closed. Its Write()
|
||||
@@ -159,3 +169,24 @@ func SerializeCompressed(w io.WriteCloser, algo CompressionAlgo, cc *Compression
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// LimitReader is an io.Reader that fails with MessageToLarge if read bytes exceed N.
|
||||
type LimitReader struct {
|
||||
R io.Reader // underlying reader
|
||||
N int64 // max bytes allowed
|
||||
}
|
||||
|
||||
func (l *LimitReader) Read(p []byte) (int, error) {
|
||||
if l.N <= 0 {
|
||||
return 0, errors.ErrMessageTooLarge
|
||||
}
|
||||
|
||||
n, err := l.R.Read(p)
|
||||
l.N -= int64(n)
|
||||
|
||||
if err == nil && l.N <= 0 {
|
||||
err = errors.ErrMessageTooLarge
|
||||
}
|
||||
|
||||
return n, err
|
||||
}
|
||||
+38
@@ -178,6 +178,23 @@ type Config struct {
|
||||
// When set to true, a key without flags is treated as if all flags are enabled.
|
||||
// This behavior is consistent with GPG.
|
||||
InsecureAllowAllKeyFlagsWhenMissing bool
|
||||
// InsecureGenerateNonCriticalKeyFlags causes the "Key Flags" signature subpacket
|
||||
// to be non-critical in newly generated signatures.
|
||||
// This may be needed for keys to be accepted by older clients who do not recognize
|
||||
// the subpacket.
|
||||
// For example, rpm 4.14.3-150400.59.3.1 in OpenSUSE Leap 15.4 does not recognize it.
|
||||
InsecureGenerateNonCriticalKeyFlags bool
|
||||
// InsecureGenerateNonCriticalSignatureCreationTime causes the "Signature Creation Time" signature subpacket
|
||||
// to be non-critical in newly generated signatures.
|
||||
// This may be needed for keys to be accepted by older clients who do not recognize
|
||||
// the subpacket.
|
||||
// For example, yum 3.4.3-168 in CentOS 7 and yum 3.4.3-158 in Amazon Linux 2 do not recognize it.
|
||||
InsecureGenerateNonCriticalSignatureCreationTime bool
|
||||
|
||||
// MaxDecompressedMessageSize specifies the maximum number of bytes that can be
|
||||
// read from a compressed packet. This serves as an upper limit to prevent
|
||||
// excessively large decompressed messages.
|
||||
MaxDecompressedMessageSize *int64
|
||||
}
|
||||
|
||||
func (c *Config) Random() io.Reader {
|
||||
@@ -415,6 +432,27 @@ func (c *Config) AllowAllKeyFlagsWhenMissing() bool {
|
||||
return c.InsecureAllowAllKeyFlagsWhenMissing
|
||||
}
|
||||
|
||||
func (c *Config) GenerateNonCriticalKeyFlags() bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
return c.InsecureGenerateNonCriticalKeyFlags
|
||||
}
|
||||
|
||||
func (c *Config) GenerateNonCriticalSignatureCreationTime() bool {
|
||||
if c == nil {
|
||||
return false
|
||||
}
|
||||
return c.InsecureGenerateNonCriticalSignatureCreationTime
|
||||
}
|
||||
|
||||
func (c *Config) DecompressedMessageSizeLimit() *int64 {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.MaxDecompressedMessageSize
|
||||
}
|
||||
|
||||
// BoolPointer is a helper function to set a boolean pointer in the Config.
|
||||
// e.g., config.CheckPacketSequence = BoolPointer(true)
|
||||
func BoolPointer(value bool) *bool {
|
||||
|
||||
+4
-4
@@ -933,7 +933,7 @@ func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey, config *Config) (err e
|
||||
}
|
||||
sig.Notations = append(sig.Notations, ¬ation)
|
||||
}
|
||||
sig.outSubpackets, err = sig.buildSubpackets(priv.PublicKey)
|
||||
sig.outSubpackets, err = sig.buildSubpackets(priv.PublicKey, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1254,11 +1254,11 @@ type outputSubpacket struct {
|
||||
contents []byte
|
||||
}
|
||||
|
||||
func (sig *Signature) buildSubpackets(issuer PublicKey) (subpackets []outputSubpacket, err error) {
|
||||
func (sig *Signature) buildSubpackets(issuer PublicKey, config *Config) (subpackets []outputSubpacket, err error) {
|
||||
creationTime := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(creationTime, uint32(sig.CreationTime.Unix()))
|
||||
// Signature Creation Time
|
||||
subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpacket, true, creationTime})
|
||||
subpackets = append(subpackets, outputSubpacket{true, creationTimeSubpacket, !config.GenerateNonCriticalSignatureCreationTime(), creationTime})
|
||||
// Signature Expiration Time
|
||||
if sig.SigLifetimeSecs != nil && *sig.SigLifetimeSecs != 0 {
|
||||
sigLifetime := make([]byte, 4)
|
||||
@@ -1357,7 +1357,7 @@ func (sig *Signature) buildSubpackets(issuer PublicKey) (subpackets []outputSubp
|
||||
if sig.FlagGroupKey {
|
||||
flags |= KeyFlagGroupKey
|
||||
}
|
||||
subpackets = append(subpackets, outputSubpacket{true, keyFlagsSubpacket, true, []byte{flags}})
|
||||
subpackets = append(subpackets, outputSubpacket{true, keyFlagsSubpacket, !config.GenerateNonCriticalKeyFlags(), []byte{flags}})
|
||||
}
|
||||
// Signer's User ID
|
||||
if sig.SignerUserId != nil {
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ FindLiteralData:
|
||||
}
|
||||
switch p := p.(type) {
|
||||
case *packet.Compressed:
|
||||
if err := packets.Push(p.Body); err != nil {
|
||||
if err := packets.Push(p.LimitedBodyReader(config.DecompressedMessageSizeLimit())); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *packet.OnePassSignature:
|
||||
|
||||
+97
-27
@@ -253,34 +253,12 @@ func writeAndSign(payload io.WriteCloser, candidateHashes []uint8, signed *Entit
|
||||
}
|
||||
|
||||
var hash crypto.Hash
|
||||
for _, hashId := range candidateHashes {
|
||||
if h, ok := algorithm.HashIdToHash(hashId); ok && h.Available() {
|
||||
hash = h
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the hash specified by config is a candidate, we'll use that.
|
||||
if configuredHash := config.Hash(); configuredHash.Available() {
|
||||
for _, hashId := range candidateHashes {
|
||||
if h, ok := algorithm.HashIdToHash(hashId); ok && h == configuredHash {
|
||||
hash = h
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if hash == 0 {
|
||||
hashId := candidateHashes[0]
|
||||
name, ok := algorithm.HashIdToString(hashId)
|
||||
if !ok {
|
||||
name = "#" + strconv.Itoa(int(hashId))
|
||||
}
|
||||
return nil, errors.InvalidArgumentError("cannot encrypt because no candidate hash functions are compiled in. (Wanted " + name + " in this case.)")
|
||||
}
|
||||
|
||||
var salt []byte
|
||||
if signer != nil {
|
||||
if hash, err = selectHash(candidateHashes, config.Hash(), signer); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var opsVersion = 3
|
||||
if signer.Version == 6 {
|
||||
opsVersion = signer.Version
|
||||
@@ -558,13 +536,34 @@ func (s signatureWriter) Close() error {
|
||||
return s.encryptedData.Close()
|
||||
}
|
||||
|
||||
func selectHashForSigningKey(config *packet.Config, signer *packet.PublicKey) crypto.Hash {
|
||||
acceptableHashes := acceptableHashesToWrite(signer)
|
||||
hash, ok := algorithm.HashToHashId(config.Hash())
|
||||
if !ok {
|
||||
return config.Hash()
|
||||
}
|
||||
for _, acceptableHashes := range acceptableHashes {
|
||||
if acceptableHashes == hash {
|
||||
return config.Hash()
|
||||
}
|
||||
}
|
||||
if len(acceptableHashes) > 0 {
|
||||
defaultAcceptedHash, ok := algorithm.HashIdToHash(acceptableHashes[0])
|
||||
if ok {
|
||||
return defaultAcceptedHash
|
||||
}
|
||||
}
|
||||
return config.Hash()
|
||||
}
|
||||
|
||||
func createSignaturePacket(signer *packet.PublicKey, sigType packet.SignatureType, config *packet.Config) *packet.Signature {
|
||||
sigLifetimeSecs := config.SigLifetime()
|
||||
hash := selectHashForSigningKey(config, signer)
|
||||
return &packet.Signature{
|
||||
Version: signer.Version,
|
||||
SigType: sigType,
|
||||
PubKeyAlgo: signer.PubKeyAlgo,
|
||||
Hash: config.Hash(),
|
||||
Hash: hash,
|
||||
CreationTime: config.Now(),
|
||||
IssuerKeyId: &signer.KeyId,
|
||||
IssuerFingerprint: signer.Fingerprint,
|
||||
@@ -618,3 +617,74 @@ func handleCompression(compressed io.WriteCloser, candidateCompression []uint8,
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
// selectHash selects the preferred hash given the candidateHashes and the configuredHash
|
||||
func selectHash(candidateHashes []byte, configuredHash crypto.Hash, signer *packet.PrivateKey) (hash crypto.Hash, err error) {
|
||||
acceptableHashes := acceptableHashesToWrite(&signer.PublicKey)
|
||||
candidateHashes = intersectPreferences(acceptableHashes, candidateHashes)
|
||||
|
||||
for _, hashId := range candidateHashes {
|
||||
if h, ok := algorithm.HashIdToHash(hashId); ok && h.Available() {
|
||||
hash = h
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// If the hash specified by config is a candidate, we'll use that.
|
||||
if configuredHash.Available() {
|
||||
for _, hashId := range candidateHashes {
|
||||
if h, ok := algorithm.HashIdToHash(hashId); ok && h == configuredHash {
|
||||
hash = h
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if hash == 0 {
|
||||
if len(acceptableHashes) > 0 {
|
||||
if h, ok := algorithm.HashIdToHash(acceptableHashes[0]); ok {
|
||||
hash = h
|
||||
} else {
|
||||
return 0, errors.UnsupportedError("no candidate hash functions are compiled in.")
|
||||
}
|
||||
} else {
|
||||
return 0, errors.UnsupportedError("no candidate hash functions are compiled in.")
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func acceptableHashesToWrite(singingKey *packet.PublicKey) []uint8 {
|
||||
switch singingKey.PubKeyAlgo {
|
||||
case packet.PubKeyAlgoEd448:
|
||||
return []uint8{
|
||||
hashToHashId(crypto.SHA512),
|
||||
hashToHashId(crypto.SHA3_512),
|
||||
}
|
||||
case packet.PubKeyAlgoECDSA, packet.PubKeyAlgoEdDSA:
|
||||
if curve, err := singingKey.Curve(); err == nil {
|
||||
if curve == packet.Curve448 ||
|
||||
curve == packet.CurveNistP521 ||
|
||||
curve == packet.CurveBrainpoolP512 {
|
||||
return []uint8{
|
||||
hashToHashId(crypto.SHA512),
|
||||
hashToHashId(crypto.SHA3_512),
|
||||
}
|
||||
} else if curve == packet.CurveBrainpoolP384 ||
|
||||
curve == packet.CurveNistP384 {
|
||||
return []uint8{
|
||||
hashToHashId(crypto.SHA384),
|
||||
hashToHashId(crypto.SHA512),
|
||||
hashToHashId(crypto.SHA3_512),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return []uint8{
|
||||
hashToHashId(crypto.SHA256),
|
||||
hashToHashId(crypto.SHA384),
|
||||
hashToHashId(crypto.SHA512),
|
||||
hashToHashId(crypto.SHA3_256),
|
||||
hashToHashId(crypto.SHA3_512),
|
||||
}
|
||||
}
|
||||
+6
@@ -61,6 +61,9 @@ func (Curve) Double(P *Point) *Point { R := *P; R.Double(); return &R }
|
||||
func (Curve) Add(P, Q *Point) *Point { R := *P; R.Add(Q); return &R }
|
||||
|
||||
// ScalarMult returns kP. This function runs in constant time.
|
||||
//
|
||||
// The result equals [k]P only when P is in the prime-order subgroup; any
|
||||
// torsion component of P is dropped.
|
||||
func (e Curve) ScalarMult(k *Scalar, P *Point) *Point {
|
||||
k4 := &Scalar{}
|
||||
k4.divBy4(k)
|
||||
@@ -75,6 +78,9 @@ func (e Curve) ScalarBaseMult(k *Scalar) *Point {
|
||||
}
|
||||
|
||||
// CombinedMult returns mG+nP, where G is the generator point. This function is non-constant time.
|
||||
//
|
||||
// Like ScalarMult, the result equals [m]G+[n]P only when P is in the
|
||||
// prime-order subgroup; any torsion component of P is dropped.
|
||||
func (e Curve) CombinedMult(m, n *Scalar, P *Point) *Point {
|
||||
m4 := &Scalar{}
|
||||
n4 := &Scalar{}
|
||||
|
||||
+11
-1
@@ -46,6 +46,9 @@ func FromBytes(in []byte) (*Point, error) {
|
||||
}
|
||||
err := errors.New("invalid decoding")
|
||||
P := &Point{}
|
||||
if in[fp.Size]&0x7F != 0 {
|
||||
return nil, err
|
||||
}
|
||||
signX := in[fp.Size] >> 7
|
||||
copy(P.y[:], in[:fp.Size])
|
||||
p := fp.P()
|
||||
@@ -135,7 +138,14 @@ func (P *Point) MarshalBinary() (data []byte, err error) {
|
||||
}
|
||||
|
||||
// UnmarshalBinary must be able to decode the form generated by MarshalBinary.
|
||||
func (P *Point) UnmarshalBinary(data []byte) error { Q, err := FromBytes(data); *P = *Q; return err }
|
||||
func (P *Point) UnmarshalBinary(data []byte) error {
|
||||
Q, err := FromBytes(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*P = *Q
|
||||
return nil
|
||||
}
|
||||
|
||||
// Double sets P = 2Q.
|
||||
func (P *Point) Double() { P.Add(P) }
|
||||
|
||||
+35
-12
@@ -9,9 +9,6 @@ package mlsbset
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/cloudflare/circl/internal/conv"
|
||||
)
|
||||
|
||||
// EltG is a group element.
|
||||
@@ -69,17 +66,43 @@ func (m Encoder) Encode(k []byte) (*Power, error) {
|
||||
k = append(k, make([]byte, ap)...)
|
||||
s := m.signs(k)
|
||||
b := make([]int32, m.p.L-m.p.D)
|
||||
c := conv.BytesLe2BigInt(k)
|
||||
c.Rsh(c, m.p.D)
|
||||
var bi big.Int
|
||||
|
||||
// Original algorithm starts with c := k >> D, then computes
|
||||
//
|
||||
// b_(i-D) = s_(i%D) * lsb(c)
|
||||
// c = [ (c>>1)+1 if b_(i-D) = -1
|
||||
// [ c>>1 otherwise
|
||||
//
|
||||
// To prevent keeping a large k around, we note that at any step i we have
|
||||
//
|
||||
// c = (k >> i) + t for t in {0,1}
|
||||
//
|
||||
// Base case is obvious. For induction, write kbit for the i-th bit of k.
|
||||
// Note lsb(c) = kbit ^ t. From that we can compute b_(i-D). Now we need
|
||||
// to compute the next t.
|
||||
//
|
||||
// Consider c >> 1 = (k >> i) + t) >> 1. This equals k >> (i+1)
|
||||
// unless t = 1 = kbit.
|
||||
//
|
||||
// If b_(i-D) is negative, then we must have had 1=lsb(c)=kbit^t, and so
|
||||
// c >> 1 = k >> (i+1), as desired with new t equal to 1.
|
||||
// For the other case assume b_(i-D) isn't negative. Now it is possible
|
||||
// that t = 1 = kbit, and only in that case the new t is equal to 1.
|
||||
var t uint64
|
||||
for i := m.p.D; i < m.p.L; i++ {
|
||||
c0 := int32(c.Bit(0))
|
||||
b[i-m.p.D] = s[i%m.p.D] * c0
|
||||
bi.SetInt64(int64(b[i-m.p.D] >> 1))
|
||||
c.Rsh(c, 1)
|
||||
c.Sub(c, &bi)
|
||||
si := s[i%m.p.D]
|
||||
kbit := uint64(k[i>>3]>>(i&7)) & 1
|
||||
lsbc := kbit ^ t
|
||||
neg := uint64(si>>31) & 1 // 1 iff si == -1
|
||||
b[i-m.p.D] = si * int32(lsbc)
|
||||
t = (kbit & t) | (lsbc & neg)
|
||||
}
|
||||
// carry = (k >> L) + t: any bits of k at positions >= L (present when L is
|
||||
// not a multiple of 8) plus the final carry, matching the original.
|
||||
carry := int(t)
|
||||
for pos := m.p.L; int(pos>>3) < len(k); pos++ {
|
||||
carry += int((k[pos>>3]>>(pos&7))&1) << (pos - m.p.L)
|
||||
}
|
||||
carry := int(c.Int64())
|
||||
return &Power{m, s, b, carry}, nil
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -1,7 +1,7 @@
|
||||
// Package ed25519 implements Ed25519 signature scheme as described in RFC-8032.
|
||||
//
|
||||
// This package provides optimized implementations of the three signature
|
||||
// variants and maintaining closer compatibility with crypto/ed25519.
|
||||
// variants and maintaining almost full compatibility with crypto/ed25519.
|
||||
//
|
||||
// | Scheme Name | Sign Function | Verification | Context |
|
||||
// |-------------|-------------------|---------------|-------------------|
|
||||
@@ -28,6 +28,13 @@
|
||||
// operations with the same key more efficient. This package refers to the
|
||||
// RFC-8032 private key as the “seed”.
|
||||
//
|
||||
// Public keys are decoded following RFC 8032 strictly: an encoding whose
|
||||
// y-coordinate is not reduced modulo 2^255-19, or whose x-coordinate is zero
|
||||
// with the sign bit set, is rejected. crypto/ed25519 accepts those
|
||||
// non-canonical encodings instead, so for a small, fixed set of malformed
|
||||
// public keys the verification functions here return false where
|
||||
// crypto/ed25519 returns true.
|
||||
//
|
||||
// References
|
||||
//
|
||||
// - RFC-8032: https://rfc-editor.org/rfc/rfc8032.txt
|
||||
|
||||
+4
-2
@@ -69,7 +69,8 @@ func (*scheme) DeriveKey(seed []byte) (sign.PublicKey, sign.PrivateKey) {
|
||||
}
|
||||
|
||||
func (*scheme) UnmarshalBinaryPublicKey(buf []byte) (sign.PublicKey, error) {
|
||||
if len(buf) < PublicKeySize {
|
||||
// NOTE Old version of CIRCL accepted trailing data.
|
||||
if len(buf) != PublicKeySize {
|
||||
return nil, sign.ErrPubKeySize
|
||||
}
|
||||
pub := make(PublicKey, PublicKeySize)
|
||||
@@ -78,7 +79,8 @@ func (*scheme) UnmarshalBinaryPublicKey(buf []byte) (sign.PublicKey, error) {
|
||||
}
|
||||
|
||||
func (*scheme) UnmarshalBinaryPrivateKey(buf []byte) (sign.PrivateKey, error) {
|
||||
if len(buf) < PrivateKeySize {
|
||||
// NOTE Old version of CIRCL accepted trailing data.
|
||||
if len(buf) != PrivateKeySize {
|
||||
return nil, sign.ErrPrivKeySize
|
||||
}
|
||||
priv := make(PrivateKey, PrivateKeySize)
|
||||
|
||||
+6
@@ -345,6 +345,8 @@ func verify(public PublicKey, message, signature, ctx []byte, preHash bool) bool
|
||||
// The opts.HashFunc() must return zero, this can be achieved by passing
|
||||
// crypto.Hash(0) as the value for opts.
|
||||
// Use a SignerOptions struct to pass a context string for signing.
|
||||
//
|
||||
// Uses the default RFC 8032 cofactor-clearing verification.
|
||||
func VerifyAny(public PublicKey, message, signature []byte, opts crypto.SignerOpts) bool {
|
||||
var ctx string
|
||||
var scheme SchemeID
|
||||
@@ -367,6 +369,8 @@ func VerifyAny(public PublicKey, message, signature []byte, opts crypto.SignerOp
|
||||
// signature, or when the public key cannot be decoded.
|
||||
// This function supports the signature variant defined in RFC-8032: Ed448,
|
||||
// also known as the pure version of EdDSA.
|
||||
//
|
||||
// Uses the default RFC 8032 cofactor-clearing verification.
|
||||
func Verify(public PublicKey, message, signature []byte, ctx string) bool {
|
||||
return verify(public, message, signature, []byte(ctx), false)
|
||||
}
|
||||
@@ -377,6 +381,8 @@ func Verify(public PublicKey, message, signature []byte, ctx string) bool {
|
||||
// meaning it internally hashes the message using SHAKE-256.
|
||||
// Context could be passed to this function, which length should be no more than
|
||||
// 255. It can be empty.
|
||||
//
|
||||
// Uses the default RFC 8032 cofactor-clearing verification.
|
||||
func VerifyPh(public PublicKey, message, signature []byte, ctx string) bool {
|
||||
return verify(public, message, signature, []byte(ctx), true)
|
||||
}
|
||||
|
||||
+4
-2
@@ -69,7 +69,8 @@ func (*scheme) DeriveKey(seed []byte) (sign.PublicKey, sign.PrivateKey) {
|
||||
}
|
||||
|
||||
func (*scheme) UnmarshalBinaryPublicKey(buf []byte) (sign.PublicKey, error) {
|
||||
if len(buf) < PublicKeySize {
|
||||
// NOTE Old version of CIRCL accepted trailing data.
|
||||
if len(buf) != PublicKeySize {
|
||||
return nil, sign.ErrPubKeySize
|
||||
}
|
||||
pub := make(PublicKey, PublicKeySize)
|
||||
@@ -78,7 +79,8 @@ func (*scheme) UnmarshalBinaryPublicKey(buf []byte) (sign.PublicKey, error) {
|
||||
}
|
||||
|
||||
func (*scheme) UnmarshalBinaryPrivateKey(buf []byte) (sign.PrivateKey, error) {
|
||||
if len(buf) < PrivateKeySize {
|
||||
// NOTE Old version of CIRCL accepted trailing data.
|
||||
if len(buf) != PrivateKeySize {
|
||||
return nil, sign.ErrPrivKeySize
|
||||
}
|
||||
priv := make(PrivateKey, PrivateKeySize)
|
||||
|
||||
+11
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased] ##
|
||||
|
||||
## [0.7.0] - 2025-06-17 ##
|
||||
|
||||
> You talk of times of peace for all, and then prepare for war.
|
||||
|
||||
### Changed ###
|
||||
- Update to `cyphar.com/go-pathrs@0.2.5`, which included a build-time API
|
||||
breakage that we needed to work around. The API of this library is unchanged
|
||||
by this, but users should make sure to update to `v0.7.0` of
|
||||
`filepath-securejoin` if they use the `libpathrs` built tag and have update
|
||||
to `libpathrs` `v0.2.5`.
|
||||
|
||||
## [0.6.1] - 2025-11-19 ##
|
||||
|
||||
> At last up jumped the cunning spider, and fiercely held her fast.
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
0.6.1
|
||||
0.7.0
|
||||
@@ -1 +0,0 @@
|
||||
testdata/dos-lines eol=crlf
|
||||
@@ -0,0 +1 @@
|
||||
/coverage.out
|
||||
+4
@@ -1,9 +1,13 @@
|
||||
Carlos A Becker <caarlos0@gmail.com>
|
||||
Claude Opus 4.6 <noreply@anthropic.com>
|
||||
Dustin Spicuzza <dustin@virtualroadside.com>
|
||||
Eugene Terentev <eugene@terentev.net>
|
||||
Kevin Burke <kevin@burke.dev>
|
||||
Mark Nevill <nev@improbable.io>
|
||||
Neil Williams <neil@reddit.com>
|
||||
Scott Lessans <slessans@gmail.com>
|
||||
Sergey Lukjanov <me@slukjanov.name>
|
||||
Simon Josefsson <simon@josefsson.org>
|
||||
Wayne Ashley Berry <wayneashleyberry@gmail.com>
|
||||
santosh653 <70637961+santosh653@users.noreply.github.com>
|
||||
sio2boss <sio2boss@users.noreply.github.com>
|
||||
+47
-1
@@ -1,7 +1,51 @@
|
||||
# Changes
|
||||
|
||||
## Version 1.2
|
||||
## Version 1.6 (released February 16, 2026)
|
||||
|
||||
- Support `~` as the user's home directory in `Include` directives, matching
|
||||
the behavior described in ssh_config(5). Thanks to Neil Williams for the report
|
||||
(#31).
|
||||
|
||||
- Strip surrounding double quotes from parsed values. OpenSSH allows values
|
||||
like `IdentityFile "/path/to/file"`, but Get/GetAll previously returned the
|
||||
quotes as literal characters. Quotes are now stripped from the returned value
|
||||
while preserving the original text for faithful roundtripping via String() and
|
||||
MarshalText(). Thanks to Furkan Türkal for the report (#61).
|
||||
|
||||
- Default to a space before `#` in end-of-line comments. When a Host or KV is
|
||||
created programmatically with an EOLComment, the output previously had no space
|
||||
before the `#` (e.g. `Host foo#comment`). A single space is now inserted by
|
||||
default. Thanks to Yonghui Cheng for the report (#50).
|
||||
|
||||
## Version 1.5 (released February 14, 2026)
|
||||
|
||||
- Implement Match support. Most of the Match spec is implemented, including
|
||||
`Match host`, `Match originalhost`, `Match user`, `Match localuser`, and `Match
|
||||
all`. `Match exec` is not yet implemented.
|
||||
|
||||
- Add SECURITY.md
|
||||
|
||||
- Add Dependabot configuration
|
||||
|
||||
## Version 1.4 (released August 19, 2025)
|
||||
|
||||
- Remove .gitattributes file (which was used to test different line endings, and
|
||||
caused issues in some build environments). Store tests/dos-lines as CRLF in git
|
||||
directly instead.
|
||||
|
||||
## Version 1.3 (released February 20, 2025)
|
||||
|
||||
- Add go.mod file (although this project has no dependencies).
|
||||
|
||||
- config: add UserSettings.ConfigFinder
|
||||
|
||||
- Various updates to CI and build environment
|
||||
|
||||
## Version 1.2 (released March 31, 2022)
|
||||
|
||||
- config: add DecodeBytes to directly read a byte array.
|
||||
|
||||
- Strip trailing whitespace from Host declarations and key/value pairs.
|
||||
Previously, if a Host declaration or a value had trailing whitespace, that
|
||||
whitespace would have been included as part of the value. This led to unexpected
|
||||
consequences. For example:
|
||||
@@ -17,3 +61,5 @@ unintuitive.
|
||||
|
||||
Instead, we strip the trailing whitespace in the configuration, which leads to
|
||||
more intuitive behavior.
|
||||
|
||||
- Add fuzz tests.
|
||||
+9
-8
@@ -1,21 +1,22 @@
|
||||
BUMP_VERSION := $(GOPATH)/bin/bump_version
|
||||
STATICCHECK := $(GOPATH)/bin/staticcheck
|
||||
WRITE_MAILMAP := $(GOPATH)/bin/write_mailmap
|
||||
|
||||
$(STATICCHECK):
|
||||
go get honnef.co/go/tools/cmd/staticcheck
|
||||
|
||||
lint: $(STATICCHECK)
|
||||
lint:
|
||||
go vet ./...
|
||||
$(STATICCHECK)
|
||||
go run honnef.co/go/tools/cmd/staticcheck@latest ./...
|
||||
go run github.com/kevinburke/differ@latest gofmt -s -w .
|
||||
|
||||
test: lint
|
||||
test:
|
||||
@# the timeout helps guard against infinite recursion
|
||||
go test -timeout=250ms ./...
|
||||
|
||||
race-test: lint
|
||||
race-test:
|
||||
go test -timeout=500ms -race ./...
|
||||
|
||||
coverage:
|
||||
go test -trimpath -timeout=250ms -coverprofile=coverage.out -covermode=atomic ./...
|
||||
go tool cover -func=coverage.out
|
||||
|
||||
$(BUMP_VERSION):
|
||||
go get -u github.com/kevinburke/bump_version
|
||||
|
||||
|
||||
+5
-5
@@ -82,11 +82,11 @@ file format.
|
||||
[blog]: https://kev.inburke.com/kevin/more-comment-preserving-configuration-parsers/
|
||||
[hostsfile]: https://github.com/kevinburke/hostsfile
|
||||
|
||||
## Donating
|
||||
## Sponsorships
|
||||
|
||||
I don't get paid to maintain this project. Donations free up time to make
|
||||
improvements to the library, and respond to bug reports. You can send donations
|
||||
via Paypal's "Send Money" feature to kev@inburke.com. Donations are not tax
|
||||
deductible in the USA.
|
||||
Thank you very much to Tailscale and Indeed for sponsoring development of this
|
||||
library. [Sponsors][sponsors] will get their names featured in the README.
|
||||
|
||||
You can also reach out about a consulting engagement: https://burke.services
|
||||
|
||||
[sponsors]: https://github.com/sponsors/kevinburke
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
# ssh_config security policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
As of September 2025, we're not aware of any security problems with ssh_config,
|
||||
past or present. That said, we recommend always using the latest version of
|
||||
ssh_config, and of the Go programming language, to ensure you have the most
|
||||
recent security fixes.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
We take security vulnerabilities seriously. If you discover a security vulnerability in ssh_config, please report it responsibly by following these steps:
|
||||
|
||||
### How to Report
|
||||
|
||||
Please follow the instructions outlined here to report a vulnerability
|
||||
privately: https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability
|
||||
|
||||
If these are insufficient - it is not hard to find Kevin's contact information
|
||||
on the Internet.
|
||||
|
||||
### What to Include
|
||||
|
||||
When reporting a vulnerability, please include a clear description of the vulnerability, steps to reproduce the issue, the potential impact, as well as any fixes you might have.
|
||||
|
||||
### Response Timeline
|
||||
|
||||
I'll try to acknowledge and patch the issue as quickly as possible.
|
||||
|
||||
Security advisories for this project will be published through:
|
||||
- GitHub Security Advisories on this repository
|
||||
- an Issue on this repository
|
||||
- The project's release notes
|
||||
- Go vulnerability databases
|
||||
|
||||
If you are using `ssh_config` and would like to be on a "pre-release"
|
||||
distribution list for coordinating releases, please contact Kevin directly.
|
||||
|
||||
### Security Considerations
|
||||
|
||||
When using ssh_config, please be aware of these security considerations.
|
||||
|
||||
#### File System Access
|
||||
|
||||
This library reads SSH configuration files from the file system. Try to ensure
|
||||
proper file permissions on SSH config files (typically 600 or 644), and be
|
||||
cautious when parsing config files from untrusted sources.
|
||||
|
||||
#### Input Validation
|
||||
|
||||
The parser handles user-provided SSH configuration data. While we try our best
|
||||
to parse the data appropriately, malformed configuration files could potentially
|
||||
cause issues. Please try to validate and sanitize any configuration data from
|
||||
external sources.
|
||||
|
||||
#### Dependencies
|
||||
|
||||
This project does not have any third party dependencies. Please try to keep your
|
||||
Go version up to date.
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
We appreciate security researchers and users who responsibly disclose vulnerabilities. Contributors who report valid security issues will be acknowledged in our security advisories (unless they prefer to remain anonymous).
|
||||
+101
-26
@@ -8,7 +8,7 @@
|
||||
// the host name to match on ("example.com"), and the second argument is the key
|
||||
// you want to retrieve ("Port"). The keywords are case insensitive.
|
||||
//
|
||||
// port := ssh_config.Get("myhost", "Port")
|
||||
// port := ssh_config.Get("myhost", "Port")
|
||||
//
|
||||
// You can also manipulate an SSH config file and then print it or write it back
|
||||
// to disk.
|
||||
@@ -24,9 +24,6 @@
|
||||
//
|
||||
// // Write the cfg back to disk:
|
||||
// fmt.Println(cfg.String())
|
||||
//
|
||||
// BUG: the Match directive is currently unsupported; parsing a config with
|
||||
// a Match directive will trigger an error.
|
||||
package ssh_config
|
||||
|
||||
import (
|
||||
@@ -43,7 +40,7 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
const version = "1.2"
|
||||
const version = "1.6.0"
|
||||
|
||||
var _ = version
|
||||
|
||||
@@ -53,6 +50,8 @@ type configFinder func() string
|
||||
// files are parsed and cached the first time Get() or GetStrict() is called.
|
||||
type UserSettings struct {
|
||||
IgnoreErrors bool
|
||||
customConfig *Config
|
||||
customConfigFinder configFinder
|
||||
systemConfig *Config
|
||||
systemConfigFinder configFinder
|
||||
userConfig *Config
|
||||
@@ -203,6 +202,13 @@ func (u *UserSettings) GetStrict(alias, key string) (string, error) {
|
||||
if u.onceErr != nil && u.IgnoreErrors == false {
|
||||
return "", u.onceErr
|
||||
}
|
||||
// TODO this is getting repetitive
|
||||
if u.customConfig != nil {
|
||||
val, err := findVal(u.customConfig, alias, key)
|
||||
if err != nil || val != "" {
|
||||
return val, err
|
||||
}
|
||||
}
|
||||
val, err := findVal(u.userConfig, alias, key)
|
||||
if err != nil || val != "" {
|
||||
return val, err
|
||||
@@ -228,6 +234,12 @@ func (u *UserSettings) GetAllStrict(alias, key string) ([]string, error) {
|
||||
if u.onceErr != nil && u.IgnoreErrors == false {
|
||||
return nil, u.onceErr
|
||||
}
|
||||
if u.customConfig != nil {
|
||||
val, err := findAll(u.customConfig, alias, key)
|
||||
if err != nil || val != nil {
|
||||
return val, err
|
||||
}
|
||||
}
|
||||
val, err := findAll(u.userConfig, alias, key)
|
||||
if err != nil || val != nil {
|
||||
return val, err
|
||||
@@ -243,16 +255,38 @@ func (u *UserSettings) GetAllStrict(alias, key string) ([]string, error) {
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
// ConfigFinder will invoke f to try to find a ssh config file in a custom
|
||||
// location on disk, instead of in /etc/ssh or $HOME/.ssh. f should return the
|
||||
// name of a file containing SSH configuration.
|
||||
//
|
||||
// ConfigFinder must be invoked before any calls to Get or GetStrict and panics
|
||||
// if f is nil. Most users should not need to use this function.
|
||||
func (u *UserSettings) ConfigFinder(f func() string) {
|
||||
if f == nil {
|
||||
panic("cannot call ConfigFinder with nil function")
|
||||
}
|
||||
u.customConfigFinder = f
|
||||
}
|
||||
|
||||
func (u *UserSettings) doLoadConfigs() {
|
||||
u.loadConfigs.Do(func() {
|
||||
// can't parse user file, that's ok.
|
||||
var filename string
|
||||
var err error
|
||||
if u.customConfigFinder != nil {
|
||||
filename = u.customConfigFinder()
|
||||
u.customConfig, err = parseFile(filename)
|
||||
// IsNotExist should be returned because a user specified this
|
||||
// function - not existing likely means they made an error
|
||||
if err != nil {
|
||||
u.onceErr = err
|
||||
}
|
||||
return
|
||||
}
|
||||
if u.userConfigFinder == nil {
|
||||
filename = userConfigFinder()
|
||||
} else {
|
||||
filename = u.userConfigFinder()
|
||||
}
|
||||
var err error
|
||||
u.userConfig, err = parseFile(filename)
|
||||
//lint:ignore S1002 I prefer it this way
|
||||
if err != nil && os.IsNotExist(err) == false {
|
||||
@@ -351,9 +385,6 @@ func (c *Config) Get(alias, key string) (string, error) {
|
||||
case *KV:
|
||||
// "keys are case insensitive" per the spec
|
||||
lkey := strings.ToLower(t.Key)
|
||||
if lkey == "match" {
|
||||
panic("can't handle Match directives")
|
||||
}
|
||||
if lkey == lowerKey {
|
||||
return t.Value, nil
|
||||
}
|
||||
@@ -386,9 +417,6 @@ func (c *Config) GetAll(alias, key string) ([]string, error) {
|
||||
case *KV:
|
||||
// "keys are case insensitive" per the spec
|
||||
lkey := strings.ToLower(t.Key)
|
||||
if lkey == "match" {
|
||||
panic("can't handle Match directives")
|
||||
}
|
||||
if lkey == lowerKey {
|
||||
all = append(all, t.Value)
|
||||
}
|
||||
@@ -433,6 +461,9 @@ type Pattern struct {
|
||||
|
||||
// String prints the string representation of the pattern.
|
||||
func (p Pattern) String() string {
|
||||
if p.not {
|
||||
return "!" + p.str
|
||||
}
|
||||
return p.str
|
||||
}
|
||||
|
||||
@@ -491,7 +522,7 @@ func NewPattern(s string) (*Pattern, error) {
|
||||
return &Pattern{str: s, regex: r, not: negated}, nil
|
||||
}
|
||||
|
||||
// Host describes a Host directive and the keywords that follow it.
|
||||
// Host describes a Host or Match directive and the keywords that follow it.
|
||||
type Host struct {
|
||||
// A list of host patterns that should match this host.
|
||||
Patterns []*Pattern
|
||||
@@ -506,6 +537,11 @@ type Host struct {
|
||||
leadingSpace int // TODO: handle spaces vs tabs here.
|
||||
// The file starts with an implicit "Host *" declaration.
|
||||
implicit bool
|
||||
// isMatch is true if this block was created by a Match directive.
|
||||
isMatch bool
|
||||
// matchKeyword stores the original text after "Match" (e.g. "Host" or
|
||||
// "all") so we can round-trip correctly.
|
||||
matchKeyword string
|
||||
}
|
||||
|
||||
// Matches returns true if the Host matches for the given alias. For
|
||||
@@ -537,20 +573,43 @@ func (h *Host) String() string {
|
||||
//lint:ignore S1002 I prefer to write it this way
|
||||
if h.implicit == false {
|
||||
buf.WriteString(strings.Repeat(" ", int(h.leadingSpace)))
|
||||
buf.WriteString("Host")
|
||||
if h.hasEquals {
|
||||
buf.WriteString(" = ")
|
||||
} else {
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
for i, pat := range h.Patterns {
|
||||
buf.WriteString(pat.String())
|
||||
if i < len(h.Patterns)-1 {
|
||||
if h.isMatch {
|
||||
buf.WriteString("Match")
|
||||
if h.hasEquals {
|
||||
buf.WriteString(" = ")
|
||||
} else {
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
buf.WriteString(h.matchKeyword)
|
||||
if !strings.EqualFold(h.matchKeyword, "all") {
|
||||
buf.WriteString(" ")
|
||||
for i, pat := range h.Patterns {
|
||||
buf.WriteString(pat.String())
|
||||
if i < len(h.Patterns)-1 {
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buf.WriteString("Host")
|
||||
if h.hasEquals {
|
||||
buf.WriteString(" = ")
|
||||
} else {
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
for i, pat := range h.Patterns {
|
||||
buf.WriteString(pat.String())
|
||||
if i < len(h.Patterns)-1 {
|
||||
buf.WriteString(" ")
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.WriteString(h.spaceBeforeComment)
|
||||
if h.EOLComment != "" {
|
||||
if h.spaceBeforeComment != "" {
|
||||
buf.WriteString(h.spaceBeforeComment)
|
||||
} else {
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
buf.WriteByte('#')
|
||||
buf.WriteString(h.EOLComment)
|
||||
}
|
||||
@@ -580,6 +639,9 @@ type KV struct {
|
||||
hasEquals bool
|
||||
leadingSpace int // Space before the key. TODO handle spaces vs tabs.
|
||||
position Position
|
||||
// rawValue preserves the original value text (including surrounding double
|
||||
// quotes, if any) so that String() can roundtrip the config file faithfully.
|
||||
rawValue string
|
||||
}
|
||||
|
||||
// Pos returns k's Position.
|
||||
@@ -596,9 +658,20 @@ func (k *KV) String() string {
|
||||
if k.hasEquals {
|
||||
equals = " = "
|
||||
}
|
||||
line := strings.Repeat(" ", int(k.leadingSpace)) + k.Key + equals + k.Value + k.spaceAfterValue
|
||||
val := k.Value
|
||||
if k.rawValue != "" {
|
||||
val = k.rawValue
|
||||
}
|
||||
line := strings.Repeat(" ", int(k.leadingSpace)) + k.Key + equals + val
|
||||
if k.Comment != "" {
|
||||
if k.spaceAfterValue != "" {
|
||||
line += k.spaceAfterValue
|
||||
} else {
|
||||
line += " "
|
||||
}
|
||||
line += "#" + k.Comment
|
||||
} else {
|
||||
line += k.spaceAfterValue
|
||||
}
|
||||
return line
|
||||
}
|
||||
@@ -695,6 +768,8 @@ func NewInclude(directives []string, hasEquals bool, pos Position, comment strin
|
||||
path = directives[i]
|
||||
} else if system {
|
||||
path = filepath.Join("/etc/ssh", directives[i])
|
||||
} else if strings.HasPrefix(directives[i], "~/") {
|
||||
path = filepath.Join(homedir(), directives[i][2:])
|
||||
} else {
|
||||
path = filepath.Join(homedir(), ".ssh", directives[i])
|
||||
}
|
||||
@@ -792,7 +867,7 @@ func init() {
|
||||
func newConfig() *Config {
|
||||
return &Config{
|
||||
Hosts: []*Host{
|
||||
&Host{
|
||||
{
|
||||
implicit: true,
|
||||
Patterns: []*Pattern{matchAll},
|
||||
Nodes: make([]Node, 0),
|
||||
|
||||
+78
-8
@@ -21,9 +21,9 @@ type sshParser struct {
|
||||
type sshParserStateFn func() sshParserStateFn
|
||||
|
||||
// Formats and panics an error message based on a token
|
||||
func (p *sshParser) raiseErrorf(tok *token, msg string, args ...interface{}) {
|
||||
func (p *sshParser) raiseErrorf(tok *token, msg string) {
|
||||
// TODO this format is ugly
|
||||
panic(tok.Position.String() + ": " + fmt.Sprintf(msg, args...))
|
||||
panic(tok.Position.String() + ": " + msg)
|
||||
}
|
||||
|
||||
func (p *sshParser) raiseError(tok *token, err error) {
|
||||
@@ -105,9 +105,7 @@ func (p *sshParser) parseKV() sshParserStateFn {
|
||||
comment = tok.val
|
||||
}
|
||||
if strings.ToLower(key.val) == "match" {
|
||||
// https://github.com/kevinburke/ssh_config/issues/6
|
||||
p.raiseErrorf(val, "ssh_config: Match directive parsing is unsupported")
|
||||
return nil
|
||||
return p.parseMatch(val, hasEquals, comment)
|
||||
}
|
||||
if strings.ToLower(key.val) == "host" {
|
||||
strPatterns := strings.Split(val.val, " ")
|
||||
@@ -118,7 +116,7 @@ func (p *sshParser) parseKV() sshParserStateFn {
|
||||
}
|
||||
pat, err := NewPattern(strPatterns[i])
|
||||
if err != nil {
|
||||
p.raiseErrorf(val, "Invalid host pattern: %v", err)
|
||||
p.raiseErrorf(val, fmt.Sprintf("Invalid host pattern: %v", err))
|
||||
return nil
|
||||
}
|
||||
patterns = append(patterns, pat)
|
||||
@@ -144,7 +142,7 @@ func (p *sshParser) parseKV() sshParserStateFn {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
p.raiseErrorf(val, "Error parsing Include directive: %v", err)
|
||||
p.raiseErrorf(val, fmt.Sprintf("Error parsing Include directive: %v", err))
|
||||
return nil
|
||||
}
|
||||
lastHost.Nodes = append(lastHost.Nodes, inc)
|
||||
@@ -152,9 +150,14 @@ func (p *sshParser) parseKV() sshParserStateFn {
|
||||
}
|
||||
shortval := strings.TrimRightFunc(val.val, unicode.IsSpace)
|
||||
spaceAfterValue := val.val[len(shortval):]
|
||||
unquoted := shortval
|
||||
if len(shortval) >= 2 && shortval[0] == '"' && shortval[len(shortval)-1] == '"' {
|
||||
unquoted = shortval[1 : len(shortval)-1]
|
||||
}
|
||||
kv := &KV{
|
||||
Key: key.val,
|
||||
Value: shortval,
|
||||
Value: unquoted,
|
||||
rawValue: shortval,
|
||||
spaceAfterValue: spaceAfterValue,
|
||||
Comment: comment,
|
||||
hasEquals: hasEquals,
|
||||
@@ -165,6 +168,73 @@ func (p *sshParser) parseKV() sshParserStateFn {
|
||||
return p.parseStart
|
||||
}
|
||||
|
||||
func (p *sshParser) parseMatch(val *token, hasEquals bool, comment string) sshParserStateFn {
|
||||
// val.val contains everything after "Match ", e.g. "Host *.example.com"
|
||||
// or "all".
|
||||
trimmed := strings.TrimRightFunc(val.val, unicode.IsSpace)
|
||||
spaceBeforeComment := val.val[len(trimmed):]
|
||||
fields := strings.Fields(trimmed)
|
||||
if len(fields) == 0 {
|
||||
p.raiseErrorf(val, "ssh_config: Match directive requires at least one criterion")
|
||||
return nil
|
||||
}
|
||||
criterion := strings.ToLower(fields[0])
|
||||
|
||||
switch criterion {
|
||||
case "all":
|
||||
// "Match all" is equivalent to "Host *" — matches everything.
|
||||
p.config.Hosts = append(p.config.Hosts, &Host{
|
||||
Patterns: []*Pattern{matchAll},
|
||||
Nodes: make([]Node, 0),
|
||||
EOLComment: comment,
|
||||
spaceBeforeComment: spaceBeforeComment,
|
||||
hasEquals: hasEquals,
|
||||
isMatch: true,
|
||||
matchKeyword: fields[0], // preserve original case
|
||||
})
|
||||
return p.parseStart
|
||||
|
||||
case "host":
|
||||
patterns := make([]*Pattern, 0)
|
||||
for _, s := range fields[1:] {
|
||||
if s == "" {
|
||||
continue
|
||||
}
|
||||
pat, err := NewPattern(s)
|
||||
if err != nil {
|
||||
p.raiseErrorf(val, fmt.Sprintf("Invalid host pattern: %v", err))
|
||||
return nil
|
||||
}
|
||||
patterns = append(patterns, pat)
|
||||
}
|
||||
if len(patterns) == 0 {
|
||||
p.raiseErrorf(val, "ssh_config: Match Host requires at least one pattern")
|
||||
return nil
|
||||
}
|
||||
p.config.Hosts = append(p.config.Hosts, &Host{
|
||||
Patterns: patterns,
|
||||
Nodes: make([]Node, 0),
|
||||
EOLComment: comment,
|
||||
spaceBeforeComment: spaceBeforeComment,
|
||||
hasEquals: hasEquals,
|
||||
isMatch: true,
|
||||
matchKeyword: fields[0], // preserve original case
|
||||
})
|
||||
return p.parseStart
|
||||
|
||||
case "exec":
|
||||
// Match Exec runs arbitrary commands. Supporting it would allow
|
||||
// untrusted SSH config files to execute code on the parsing
|
||||
// machine. Reject it explicitly.
|
||||
p.raiseErrorf(val, "ssh_config: Match Exec is not supported")
|
||||
return nil
|
||||
|
||||
default:
|
||||
p.raiseErrorf(val, fmt.Sprintf("ssh_config: unsupported Match criterion %q", criterion))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (p *sshParser) parseComment() sshParserStateFn {
|
||||
comment := p.getToken()
|
||||
lastHost := p.config.Hosts[len(p.config.Hosts)-1]
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ archives:
|
||||
name_template: "cpuid-{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
formats: [ 'zip' ]
|
||||
files:
|
||||
- LICENSE
|
||||
checksum:
|
||||
|
||||
+69
-1
@@ -2,7 +2,7 @@
|
||||
Package cpuid provides information about the CPU running the current program.
|
||||
|
||||
CPU features are detected on startup, and kept for fast access through the life of the application.
|
||||
Currently x86 / x64 (AMD64/i386) and ARM (ARM64) is supported, and no external C (cgo) code is used, which should make the library very easy to use.
|
||||
Currently x86 / x64 (AMD64/i386), ARM (ARM64), and RISC-V (RV64) are supported, and no external C (cgo) code is used, which should make the library very easy to use.
|
||||
|
||||
You can access the CPU information by accessing the shared CPU variable of the cpuid library.
|
||||
|
||||
@@ -506,6 +506,74 @@ Exit Code 1
|
||||
| SM3 | SM3 instructions |
|
||||
| SM4 | SM4 instructions |
|
||||
| SVE | Scalable Vector Extension |
|
||||
| SVE2 | Scalable Vector Extension 2 |
|
||||
| SB | Speculation barrier (SB instruction) |
|
||||
| SSBS | Speculative Store Bypass Safe (PSTATE.SSBS) |
|
||||
| BTI | Branch Target Identification |
|
||||
| FLAGM2 | Condition flag manipulation version 2 (AXFLAG, XAFLAG) |
|
||||
| FRINTTS | Floating-point to integer rounding (FRINT32Z, FRINT64Z, etc) |
|
||||
| DCPODP | Data cache clean to Point of Deep Persistence (DC CVADP) |
|
||||
| BF16 | BFloat16 instructions (BFDOT, BFMMLA, etc) |
|
||||
| I8MM | Int8 matrix multiplication (SMMLA, UMMLA, USMMLA) |
|
||||
| WFXT | WFE/WFI with timeout (WFET, WFIT) |
|
||||
| MOPS | Memory copy and set instructions (CPYF, SETP, etc) |
|
||||
| HBC | Hinted conditional branches (BC.cond) |
|
||||
| CSSC | Common short sequence compression (ABS, SMAX, UMAX, etc) |
|
||||
|
||||
## riscv64 feature detection
|
||||
|
||||
On `riscv64/linux`, CPU features are detected using the `riscv_hwprobe` syscall (Linux 6.4+).
|
||||
For older kernels, detection falls back to parsing `/proc/cpuinfo` for the ISA string.
|
||||
|
||||
Cache line size is detected via `riscv_hwprobe` (Zicbom block size) or sysfs fallback.
|
||||
Other cache and topology information is not yet available.
|
||||
|
||||
# RISC-V features:
|
||||
|
||||
| Feature Flag | Description |
|
||||
|----------------|----------------------------------------------------|
|
||||
| RV_IMA | IMA base (Integer, Multiply, Atomic) |
|
||||
| RV_C | Compressed instructions |
|
||||
| RV_F | Single-precision FP |
|
||||
| RV_D | Double-precision FP |
|
||||
| RV_V | Vector extension (V) |
|
||||
| RV_ZBA | Address generation |
|
||||
| RV_ZBB | Basic bit manipulation |
|
||||
| RV_ZBC | Carry-less multiplication |
|
||||
| RV_ZBS | Single-bit manipulation |
|
||||
| RV_ZICOND | Integer conditional operations |
|
||||
| RV_ZIHINTPAUSE | Pause hint |
|
||||
| RV_ZICBOM | Cache block management operations |
|
||||
| RV_ZICBOZ | Cache block zero |
|
||||
| RV_ZICBOP | Cache block prefetch |
|
||||
| RV_ZFA | Additional floating-point |
|
||||
| RV_ZFH | Half-precision FP |
|
||||
| RV_ZFHMIN | Minimal half-precision FP |
|
||||
| RV_ZTSO | Total store ordering |
|
||||
| RV_ZACAS | Atomic CAS |
|
||||
| RV_ZBKB | Bit-manipulation for crypto |
|
||||
| RV_ZBKC | Carry-less multiply for crypto |
|
||||
| RV_ZBKX | Crossbar permutations |
|
||||
| RV_ZKND | NIST Suite: AES decrypt |
|
||||
| RV_ZKNE | NIST Suite: AES encrypt |
|
||||
| RV_ZKNH | NIST Suite: SHA-2 (SHA-256/SHA-512) |
|
||||
| RV_ZKSED | ShangMi Suite: SM4 block cipher |
|
||||
| RV_ZKSH | ShangMi Suite: SM3 hash |
|
||||
| RV_ZKT | Data-independent execution latency (Crypto) |
|
||||
| RV_ZKN | NIST Algorithm Suite (combined from individual) |
|
||||
| RV_ZKS | ShangMi Algorithm Suite (combined from individual) |
|
||||
| RV_ZVBB | Vector Basic Bit-manipulation |
|
||||
| RV_ZVBC | Vector Carry-less multiply |
|
||||
| RV_ZVKB | Vector Bit-manipulation for crypto |
|
||||
| RV_ZVKG | Vector GCM/GMAC |
|
||||
| RV_ZVKNED | NIST Suite: Vector AES encrypt+decrypt |
|
||||
| RV_ZVKNHA | NIST Suite: Vector SHA-2 (SHA-256) |
|
||||
| RV_ZVKNHB | NIST Suite: Vector SHA-2 (SHA-512) |
|
||||
| RV_ZVKSED | ShangMi Suite: Vector SM4 |
|
||||
| RV_ZVKSH | ShangMi Suite: Vector SM3 hash |
|
||||
| RV_ZVKT | Vector Data-independent execution latency |
|
||||
| RV_ZVKNG | NIST Suite with GCM (combined from individual) |
|
||||
| RV_ZVKSG | ShangMi Suite with GCM (combined from individual) |
|
||||
|
||||
# license
|
||||
|
||||
|
||||
+200
-13
@@ -3,7 +3,7 @@
|
||||
// Package cpuid provides information about the CPU running the current program.
|
||||
//
|
||||
// CPU features are detected on startup, and kept for fast access through the life of the application.
|
||||
// Currently x86 / x64 (AMD64) as well as arm64 is supported.
|
||||
// Currently x86 / x64 (AMD64), arm64, and riscv64 are supported.
|
||||
//
|
||||
// You can access the CPU information by accessing the shared CPU variable of the cpuid library.
|
||||
//
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"math/bits"
|
||||
"os"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -61,6 +62,13 @@ const (
|
||||
SRE
|
||||
Apple
|
||||
|
||||
// RISC-V vendors
|
||||
SiFive
|
||||
StarFive
|
||||
THead
|
||||
Andes
|
||||
SpacemiT
|
||||
|
||||
lastVendor
|
||||
)
|
||||
|
||||
@@ -95,6 +103,7 @@ const (
|
||||
AVX2 // AVX2 functions
|
||||
AVX512BF16 // AVX-512 BFLOAT16 Instructions
|
||||
AVX512BITALG // AVX-512 Bit Algorithms
|
||||
AVX512BMM // AVX-512 Bit Manipulation Instructions
|
||||
AVX512BW // AVX-512 Byte and Word Instructions
|
||||
AVX512CD // AVX-512 Conflict Detection Instructions
|
||||
AVX512DQ // AVX-512 Doubleword and Quadword Instructions
|
||||
@@ -139,6 +148,7 @@ const (
|
||||
FMA4 // Bulldozer FMA4 functions
|
||||
FP128 // AMD: When set, the internal FP/SIMD execution datapath is no more than 128-bits wide
|
||||
FP256 // AMD: When set, the internal FP/SIMD execution datapath is no more than 256-bits wide
|
||||
FRED // Flexible Return and Event Delivery
|
||||
FSRM // Fast Short Rep Mov
|
||||
FXSR // FXSAVE, FXRESTOR instructions, CR4 bit 9
|
||||
FXSROPT // FXSAVE/FXRSTOR optimizations
|
||||
@@ -308,6 +318,19 @@ const (
|
||||
SM3 // SM3 instructions
|
||||
SM4 // SM4 instructions
|
||||
SVE // Scalable Vector Extension
|
||||
SVE2 // Scalable Vector Extension 2
|
||||
SB // Speculation barrier (SB instruction)
|
||||
SSBS // Speculative Store Bypass Safe (PSTATE.SSBS)
|
||||
BTI // Branch Target Identification
|
||||
FLAGM2 // Condition flag manipulation version 2 (AXFLAG, XAFLAG)
|
||||
FRINTTS // Floating-point to integer rounding (FRINT32Z, FRINT64Z, etc)
|
||||
DCPODP // Data cache clean to Point of Deep Persistence (DC CVADP)
|
||||
BF16 // BFloat16 instructions (BFDOT, BFMMLA, etc)
|
||||
I8MM // Int8 matrix multiplication (SMMLA, UMMLA, USMMLA)
|
||||
WFXT // WFE/WFI with timeout (WFET, WFIT)
|
||||
MOPS // Memory copy and set instructions (CPYF, SETP, etc)
|
||||
HBC // Hinted conditional branches (BC.cond)
|
||||
CSSC // Common short sequence compression (ABS, SMAX, UMAX, etc)
|
||||
|
||||
// PMU
|
||||
PMU_FIXEDCOUNTER_CYCLES
|
||||
@@ -315,6 +338,57 @@ const (
|
||||
PMU_FIXEDCOUNTER_INSTRUCTIONS
|
||||
PMU_FIXEDCOUNTER_TOPDOWN_SLOTS
|
||||
|
||||
// RISC-V features
|
||||
RV_IMA // IMA base (Integer, Multiply, Atomic)
|
||||
RV_C // Compressed instructions
|
||||
RV_F // Single-precision FP
|
||||
RV_D // Double-precision FP
|
||||
RV_V // Vector extension (V)
|
||||
RV_ZBA // Address generation
|
||||
RV_ZBB // Basic bit manipulation
|
||||
RV_ZBC // Carry-less multiplication
|
||||
RV_ZBS // Single-bit manipulation
|
||||
RV_ZICOND // Integer conditional operations
|
||||
RV_ZIHINTPAUSE // Pause hint
|
||||
RV_ZICBOM // Cache block management operations
|
||||
RV_ZICBOZ // Cache block zero
|
||||
RV_ZICBOP // Cache block prefetch
|
||||
RV_ZFA // Additional floating-point
|
||||
RV_ZFH // Half-precision FP
|
||||
RV_ZFHMIN // Minimal half-precision FP
|
||||
RV_ZTSO // Total store ordering
|
||||
RV_ZACAS // Atomic CAS
|
||||
// Scalar cryptography
|
||||
RV_ZBKB // Bit-manipulation for crypto
|
||||
RV_ZBKC // Carry-less multiply for crypto
|
||||
RV_ZBKX // Crossbar permutations
|
||||
RV_ZKND // NIST Suite: AES decrypt
|
||||
RV_ZKNE // NIST Suite: AES encrypt
|
||||
RV_ZKNH // NIST Suite: SHA-2 (SHA-256/SHA-512)
|
||||
RV_ZKSED // ShangMi Suite: SM4 block cipher
|
||||
RV_ZKSH // ShangMi Suite: SM3 hash
|
||||
RV_ZKT // Data-independent execution latency (Crypto)
|
||||
|
||||
// Scalar crypto suites (combined from individual extensions)
|
||||
RV_ZKN // NIST Algorithm Suite (Zknd+Zkne+Zknh+Zbkb+Zbkc+Zbkx+Zkt)
|
||||
RV_ZKS // ShangMi Algorithm Suite (Zksed+Zksh+Zbkb+Zbkc+Zbkx+Zkt)
|
||||
|
||||
// Vector cryptography
|
||||
RV_ZVBB // Vector Basic Bit-manipulation
|
||||
RV_ZVBC // Vector Carry-less multiply
|
||||
RV_ZVKB // Vector Bit-manipulation for crypto
|
||||
RV_ZVKG // Vector GCM/GMAC
|
||||
RV_ZVKNED // NIST Suite: Vector AES encrypt+decrypt
|
||||
RV_ZVKNHA // NIST Suite: Vector SHA-2 (SHA-256)
|
||||
RV_ZVKNHB // NIST Suite: Vector SHA-2 (SHA-512)
|
||||
RV_ZVKSED // ShangMi Suite: Vector SM4
|
||||
RV_ZVKSH // ShangMi Suite: Vector SM3 hash
|
||||
RV_ZVKT // Vector Data-independent execution latency
|
||||
|
||||
// Vector crypto suites (combined from individual extensions)
|
||||
RV_ZVKNG // NIST Suite with GCM (Zvkned+Zvknhb+Zvkg+Zvkb+Zvkt)
|
||||
RV_ZVKSG // ShangMi Suite with GCM (Zvksed+Zvksh+Zvkg+Zvkb+Zvkt)
|
||||
|
||||
// Keep it last. It automatically defines the size of []flagSet
|
||||
lastID
|
||||
|
||||
@@ -419,8 +493,8 @@ func Detect() {
|
||||
os.Exit(1)
|
||||
}
|
||||
if disableFlag != nil {
|
||||
s := strings.Split(*disableFlag, ",")
|
||||
for _, feat := range s {
|
||||
s := strings.SplitSeq(*disableFlag, ",")
|
||||
for feat := range s {
|
||||
feat := ParseFeature(strings.TrimSpace(feat))
|
||||
if feat != UNKNOWN {
|
||||
CPU.featureSet.unset(feat)
|
||||
@@ -471,12 +545,7 @@ func (c *CPUInfo) Has(id FeatureID) bool {
|
||||
|
||||
// AnyOf returns whether the CPU supports one or more of the requested features.
|
||||
func (c CPUInfo) AnyOf(ids ...FeatureID) bool {
|
||||
for _, id := range ids {
|
||||
if c.featureSet.inSet(id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.ContainsFunc(ids, c.featureSet.inSet)
|
||||
}
|
||||
|
||||
// Features contains several features combined for a fast check using
|
||||
@@ -496,6 +565,11 @@ func (c *CPUInfo) HasAll(f Features) bool {
|
||||
return c.featureSet.hasSetP(f)
|
||||
}
|
||||
|
||||
// HasOneOf returns whether the CPU supports one or more of the requested features.
|
||||
func (c *CPUInfo) HasOneOf(f Features) bool {
|
||||
return c.featureSet.hasOneOf(f)
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
|
||||
var oneOfLevel = CombineFeatures(SYSEE, SYSCALL)
|
||||
var level1Features = CombineFeatures(CMOV, CMPXCHG8, X87, FXSR, MMX, SSE, SSE2)
|
||||
@@ -503,6 +577,56 @@ var level2Features = CombineFeatures(CMOV, CMPXCHG8, X87, FXSR, MMX, SSE, SSE2,
|
||||
var level3Features = CombineFeatures(CMOV, CMPXCHG8, X87, FXSR, MMX, SSE, SSE2, CX16, LAHF, POPCNT, SSE3, SSE4, SSE42, SSSE3, AVX, AVX2, BMI1, BMI2, F16C, FMA3, LZCNT, MOVBE, OSXSAVE)
|
||||
var level4Features = CombineFeatures(CMOV, CMPXCHG8, X87, FXSR, MMX, SSE, SSE2, CX16, LAHF, POPCNT, SSE3, SSE4, SSE42, SSSE3, AVX, AVX2, BMI1, BMI2, F16C, FMA3, LZCNT, MOVBE, OSXSAVE, AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL)
|
||||
|
||||
// RV_CRYPTO_FEATS contains all RISC-V scalar cryptography instruction extensions (excludes Zkt since it is a timing guarantee, not a computational instruction).
|
||||
var RV_CRYPTO_FEATS = CombineFeatures(RV_ZBKB, RV_ZBKC, RV_ZBKX, RV_ZKND, RV_ZKNE, RV_ZKNH, RV_ZKSED, RV_ZKSH)
|
||||
|
||||
// RV_VECTOR_CRYPTO_FEATS contains all RISC-V vector cryptography extensions.
|
||||
var RV_VECTOR_CRYPTO_FEATS = CombineFeatures(RV_ZVBB, RV_ZVBC, RV_ZVKB, RV_ZVKG, RV_ZVKNED, RV_ZVKNHA, RV_ZVKNHB, RV_ZVKSED, RV_ZVKSH)
|
||||
|
||||
// RISC-V application profile feature sets.
|
||||
// https://github.com/riscv/riscv-profiles
|
||||
var rvProfile20Features = CombineFeatures(RV_IMA, RV_C, RV_F, RV_D)
|
||||
var rvProfile22Features = CombineFeatures(RV_IMA, RV_C, RV_F, RV_D, RV_ZBA, RV_ZBB, RV_ZBS, RV_ZFHMIN, RV_ZICBOM, RV_ZICBOP, RV_ZICBOZ, RV_ZIHINTPAUSE)
|
||||
var rvProfile23Features = CombineFeatures(RV_IMA, RV_C, RV_F, RV_D, RV_ZBA, RV_ZBB, RV_ZBS, RV_ZFHMIN, RV_ZICBOM, RV_ZICBOP, RV_ZICBOZ, RV_ZIHINTPAUSE, RV_V, RV_ZFA, RV_ZICOND, RV_ZVBB, RV_ZVKB)
|
||||
|
||||
// RISC-V crypto suites — combined from individual extensions.
|
||||
var rvZKNFeatures = CombineFeatures(RV_ZKND, RV_ZKNE, RV_ZKNH, RV_ZBKB, RV_ZBKC, RV_ZBKX, RV_ZKT)
|
||||
var rvZKSFeatures = CombineFeatures(RV_ZKSED, RV_ZKSH, RV_ZBKB, RV_ZBKC, RV_ZBKX, RV_ZKT)
|
||||
var rvZVKNFeatures = CombineFeatures(RV_ZVKNED, RV_ZVKNHB, RV_ZVKG, RV_ZVKB, RV_ZVKT)
|
||||
var rvZVKSFeatures = CombineFeatures(RV_ZVKSED, RV_ZVKSH, RV_ZVKG, RV_ZVKB, RV_ZVKT)
|
||||
|
||||
// ARM64 architecture levels. armV8Levels[m] is the cumulative set of mandatory
|
||||
// user-space instruction features added up to and including ARMv8.m that this
|
||||
// package can detect. EL1/system-only features (PAN, VHE, CSV2/CSV3, ECV, ...)
|
||||
// are excluded since they are irrelevant to user-space code generation, exactly
|
||||
// as X64Level ignores non-instruction features.
|
||||
//
|
||||
// FEAT_SSBS and FEAT_BTI, although mandatory from ARMv8.5, are intentionally NOT
|
||||
// required. Both are OS-policy-gated security features (speculative store bypass
|
||||
// safety and branch-target identification) that Go code generation never depends
|
||||
// on: their HWCAP/sysctl bits are set only when the OS or hypervisor enables the
|
||||
// protection, not purely from CPU capability, so they are routinely hidden even
|
||||
// on capable silicon (neither a Neoverse N2 Linux guest nor Apple Silicon reports
|
||||
// them). Requiring them would cap such CPUs at v8.4. Both are still detected and
|
||||
// reported through FeatureSet when present.
|
||||
// https://go.dev/wiki/MinimumRequirements#arm64
|
||||
var armV8Levels = [...]Features{
|
||||
CombineFeatures(FP, ASIMD), // v8.0
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM), // v8.1
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP), // v8.2
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC), // v8.3
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS), // v8.4
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS, SB, FRINTTS, FLAGM2, DCPODP), // v8.5
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS, SB, FRINTTS, FLAGM2, DCPODP, BF16, I8MM), // v8.6
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS, SB, FRINTTS, FLAGM2, DCPODP, BF16, I8MM, WFXT), // v8.7
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS, SB, FRINTTS, FLAGM2, DCPODP, BF16, I8MM, WFXT, MOPS, HBC), // v8.8
|
||||
CombineFeatures(FP, ASIMD, ATOMICS, CRC32, ASIMDRDM, DCPOP, JSCVT, FCMA, LRCPC, TS, SB, FRINTTS, FLAGM2, DCPODP, BF16, I8MM, WFXT, MOPS, HBC, CSSC), // v8.9
|
||||
}
|
||||
|
||||
// armCrypto matches the GOARM64 ",crypto" option: FEAT_AES, FEAT_PMULL,
|
||||
// FEAT_SHA1 and FEAT_SHA256.
|
||||
var armCrypto = CombineFeatures(AESARM, PMULL, SHA1, SHA2)
|
||||
|
||||
// X64Level returns the microarchitecture level detected on the CPU.
|
||||
// If features are lacking or non x64 mode, 0 is returned.
|
||||
// See https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
|
||||
@@ -525,6 +649,67 @@ func (c CPUInfo) X64Level() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// RVProfile returns the RISC-V application profile level.
|
||||
// 0 = unknown / base ISA only, 20 = RVA20, 22 = RVA22, 23 = RVA23.
|
||||
// Returns 0 on non-RISC-V architectures or if not detected.
|
||||
// https://github.com/riscv/riscv-profiles
|
||||
func (c CPUInfo) RVProfile() int {
|
||||
switch {
|
||||
case c.featureSet.hasSetP(rvProfile23Features):
|
||||
return 23
|
||||
case c.featureSet.hasSetP(rvProfile22Features):
|
||||
return 22
|
||||
case c.featureSet.hasSetP(rvProfile20Features):
|
||||
return 20
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// ARM64Level returns the ARMv8/ARMv9 architecture version supported by the CPU
|
||||
// as (major, minor), e.g. 8, 4 for ARMv8.4-A or 9, 0 for ARMv9.0-A.
|
||||
// Only mandatory user-space instruction features are considered, so the result
|
||||
// is the highest level whose required instructions are all present.
|
||||
// Returns 0, 0 on non-arm64 CPUs or when feature detection was unavailable.
|
||||
func (c CPUInfo) ARM64Level() (major, minor int) {
|
||||
if !c.featureSet.hasSetP(armV8Levels[0]) {
|
||||
return 0, 0
|
||||
}
|
||||
m8 := 0
|
||||
for m := len(armV8Levels) - 1; m >= 1; m-- {
|
||||
if c.featureSet.hasSetP(armV8Levels[m]) {
|
||||
m8 = m
|
||||
break
|
||||
}
|
||||
}
|
||||
// ARMv9.x mandates everything in ARMv8.(x+5) plus SVE2.
|
||||
if m8 >= 5 && c.featureSet.inSet(SVE2) {
|
||||
return 9, m8 - 5
|
||||
}
|
||||
return 8, m8
|
||||
}
|
||||
|
||||
// GOARM64 returns a value usable as the GOARM64 build setting for the detected
|
||||
// CPU, e.g. "v8.4" or "v9.0,crypto". The ",crypto" suffix is appended when AES,
|
||||
// PMULL, SHA1 and SHA256 are all present; the ",lse" suffix is appended in the
|
||||
// rare case LSE is present without the rest of the ARMv8.1 feature set.
|
||||
// Returns "" on non-arm64 CPUs or when feature detection was unavailable.
|
||||
// See https://go.dev/wiki/MinimumRequirements#arm64
|
||||
func (c CPUInfo) GOARM64() string {
|
||||
major, minor := c.ARM64Level()
|
||||
if major == 0 {
|
||||
return ""
|
||||
}
|
||||
v := fmt.Sprintf("v%d.%d", major, minor)
|
||||
if major == 8 && minor == 0 && c.featureSet.inSet(ATOMICS) {
|
||||
v += ",lse"
|
||||
}
|
||||
if c.featureSet.hasSetP(armCrypto) {
|
||||
v += ",crypto"
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Disable will disable one or several features.
|
||||
func (c *CPUInfo) Disable(ids ...FeatureID) bool {
|
||||
for _, id := range ids {
|
||||
@@ -771,7 +956,7 @@ func flagSetWith(feat ...FeatureID) flagSet {
|
||||
// Will return UNKNOWN if not found.
|
||||
func ParseFeature(s string) FeatureID {
|
||||
s = strings.ToUpper(s)
|
||||
for i := firstID; i < lastID; i++ {
|
||||
for i := range lastID {
|
||||
if i.String() == s {
|
||||
return i
|
||||
}
|
||||
@@ -785,7 +970,7 @@ func (s flagSet) Strings() []string {
|
||||
return []string{""}
|
||||
}
|
||||
r := make([]string, 0)
|
||||
for i := firstID; i < lastID; i++ {
|
||||
for i := range lastID {
|
||||
if s.inSet(i) {
|
||||
r = append(r, i.String())
|
||||
}
|
||||
@@ -806,7 +991,7 @@ func maxFunctionID() uint32 {
|
||||
func brandName() string {
|
||||
if maxExtendedFunction() >= 0x80000004 {
|
||||
v := make([]uint32, 0, 48)
|
||||
for i := uint32(0); i < 3; i++ {
|
||||
for i := range uint32(3) {
|
||||
a, b, c, d := cpuid(0x80000002 + i)
|
||||
v = append(v, a, b, c, d)
|
||||
}
|
||||
@@ -1075,7 +1260,7 @@ func (c *CPUInfo) cacheSize() {
|
||||
// Hack: When we encounter the same entry 100 times we break.
|
||||
nSame := 0
|
||||
var last uint32
|
||||
for i := uint32(0); i < math.MaxUint32; i++ {
|
||||
for i := range uint32(math.MaxUint32) {
|
||||
eax, ebx, ecx, _ := cpuidex(0x8000001D, i)
|
||||
|
||||
level := (eax >> 5) & 7
|
||||
@@ -1329,6 +1514,7 @@ func support() flagSet {
|
||||
fs.setIf(eax1&(1<<10) != 0, MOVSB_ZL)
|
||||
fs.setIf(eax1&(1<<11) != 0, STOSB_SHORT)
|
||||
fs.setIf(eax1&(1<<12) != 0, CMPSB_SCADBS_SHORT)
|
||||
fs.setIf(eax1&(1<<17) != 0, FRED)
|
||||
fs.setIf(eax1&(1<<22) != 0, HRESET)
|
||||
fs.setIf(eax1&(1<<23) != 0, AVXIFMA)
|
||||
fs.setIf(eax1&(1<<26) != 0, LAM)
|
||||
@@ -1562,6 +1748,7 @@ func support() flagSet {
|
||||
fs.setIf((a>>29)&1 == 1, SRSO_NO)
|
||||
fs.setIf((a>>28)&1 == 1, IBPB_BRTYPE)
|
||||
fs.setIf((a>>27)&1 == 1, SBPB)
|
||||
fs.setIf((a>>23)&1 == 1, AVX512BMM)
|
||||
fs.setIf((c>>1)&1 == 1, TSA_L1_NO)
|
||||
fs.setIf((c>>2)&1 == 1, TSA_SQ_NO)
|
||||
fs.setIf((a>>5)&1 == 1, TSA_VERW_CLEAR)
|
||||
|
||||
+8
-1
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build arm64 && !gccgo && !noasm && !appengine
|
||||
// +build arm64,!gccgo,!noasm,!appengine
|
||||
|
||||
package cpuid
|
||||
|
||||
@@ -189,6 +188,7 @@ func addInfo(c *CPUInfo, safe bool) {
|
||||
f.setIf(instAttrReg0&(0xf<<60) != 0, RNDR)
|
||||
f.setIf(instAttrReg0&(0xf<<56) != 0, TLB)
|
||||
f.setIf(instAttrReg0&(0xf<<52) != 0, TS)
|
||||
f.setIf(instAttrReg0&(0xf<<52) == 2<<52, FLAGM2) // TS == 0b0010 (FEAT_FlagM2)
|
||||
f.setIf(instAttrReg0&(0xf<<48) != 0, FHM)
|
||||
f.setIf(instAttrReg0&(0xf<<44) != 0, ASIMDDP)
|
||||
f.setIf(instAttrReg0&(0xf<<40) != 0, SM4)
|
||||
@@ -244,6 +244,13 @@ func addInfo(c *CPUInfo, safe bool) {
|
||||
// fmt.Println("APA")
|
||||
// }
|
||||
f.setIf(instAttrReg1&(0xf<<0) != 0, DCPOP)
|
||||
f.setIf(instAttrReg1&(0xf<<0) == 2<<0, DCPODP) // DPB == 0b0010 (FEAT_DPB2)
|
||||
|
||||
// Upper ID_AA64ISAR1_EL1 fields, not in the table above.
|
||||
f.setIf(instAttrReg1&(0xf<<32) != 0, FRINTTS) // bits [35:32]
|
||||
f.setIf(instAttrReg1&(0xf<<36) != 0, SB) // bits [39:36]
|
||||
f.setIf(instAttrReg1&(0xf<<44) != 0, BF16) // bits [47:44]
|
||||
f.setIf(instAttrReg1&(0xf<<52) != 0, I8MM) // bits [55:52]
|
||||
|
||||
// Store
|
||||
c.featureSet.or(f)
|
||||
|
||||
+1
-2
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build (!amd64 && !386 && !arm64) || gccgo || noasm || appengine
|
||||
// +build !amd64,!386,!arm64 gccgo noasm appengine
|
||||
//go:build (!amd64 && !386 && !arm64 && !riscv64) || ((amd64 || 386) && (gccgo || noasm || appengine))
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build arm64 && (gccgo || noasm || appengine)
|
||||
|
||||
package cpuid
|
||||
|
||||
func initCPU() {
|
||||
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
|
||||
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
}
|
||||
|
||||
func addInfo(c *CPUInfo, safe bool) {
|
||||
c.CacheLine = 64
|
||||
detectOS(c)
|
||||
}
|
||||
|
||||
func getVectorLength() (vl, pl uint64) { return 0, 0 }
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Copyright (c) 2026 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
package cpuid
|
||||
|
||||
func getVectorLength() (vl, pl uint64) { return 0, 0 }
|
||||
|
||||
func initCPU() {
|
||||
cpuid = func(uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
cpuidex = func(x, y uint32) (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
xgetbv = func(uint32) (a, b uint32) { return 0, 0 }
|
||||
rdtscpAsm = func() (a, b, c, d uint32) { return 0, 0, 0, 0 }
|
||||
}
|
||||
|
||||
func addInfo(c *CPUInfo, safe bool) {
|
||||
detectOS(c)
|
||||
}
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2015 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build (386 && !gccgo && !noasm && !appengine) || (amd64 && !gccgo && !noasm && !appengine)
|
||||
// +build 386,!gccgo,!noasm,!appengine amd64,!gccgo,!noasm,!appengine
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
+289
-225
@@ -29,234 +29,292 @@ func _() {
|
||||
_ = x[AVX2-19]
|
||||
_ = x[AVX512BF16-20]
|
||||
_ = x[AVX512BITALG-21]
|
||||
_ = x[AVX512BW-22]
|
||||
_ = x[AVX512CD-23]
|
||||
_ = x[AVX512DQ-24]
|
||||
_ = x[AVX512ER-25]
|
||||
_ = x[AVX512F-26]
|
||||
_ = x[AVX512FP16-27]
|
||||
_ = x[AVX512IFMA-28]
|
||||
_ = x[AVX512PF-29]
|
||||
_ = x[AVX512VBMI-30]
|
||||
_ = x[AVX512VBMI2-31]
|
||||
_ = x[AVX512VL-32]
|
||||
_ = x[AVX512VNNI-33]
|
||||
_ = x[AVX512VP2INTERSECT-34]
|
||||
_ = x[AVX512VPOPCNTDQ-35]
|
||||
_ = x[AVXIFMA-36]
|
||||
_ = x[AVXNECONVERT-37]
|
||||
_ = x[AVXSLOW-38]
|
||||
_ = x[AVXVNNI-39]
|
||||
_ = x[AVXVNNIINT8-40]
|
||||
_ = x[AVXVNNIINT16-41]
|
||||
_ = x[BHI_CTRL-42]
|
||||
_ = x[BMI1-43]
|
||||
_ = x[BMI2-44]
|
||||
_ = x[CETIBT-45]
|
||||
_ = x[CETSS-46]
|
||||
_ = x[CLDEMOTE-47]
|
||||
_ = x[CLMUL-48]
|
||||
_ = x[CLZERO-49]
|
||||
_ = x[CMOV-50]
|
||||
_ = x[CMPCCXADD-51]
|
||||
_ = x[CMPSB_SCADBS_SHORT-52]
|
||||
_ = x[CMPXCHG8-53]
|
||||
_ = x[CPBOOST-54]
|
||||
_ = x[CPPC-55]
|
||||
_ = x[CX16-56]
|
||||
_ = x[EFER_LMSLE_UNS-57]
|
||||
_ = x[ENQCMD-58]
|
||||
_ = x[ERMS-59]
|
||||
_ = x[F16C-60]
|
||||
_ = x[FLUSH_L1D-61]
|
||||
_ = x[FMA3-62]
|
||||
_ = x[FMA4-63]
|
||||
_ = x[FP128-64]
|
||||
_ = x[FP256-65]
|
||||
_ = x[FSRM-66]
|
||||
_ = x[FXSR-67]
|
||||
_ = x[FXSROPT-68]
|
||||
_ = x[GFNI-69]
|
||||
_ = x[HLE-70]
|
||||
_ = x[HRESET-71]
|
||||
_ = x[HTT-72]
|
||||
_ = x[HWA-73]
|
||||
_ = x[HYBRID_CPU-74]
|
||||
_ = x[HYPERVISOR-75]
|
||||
_ = x[IA32_ARCH_CAP-76]
|
||||
_ = x[IA32_CORE_CAP-77]
|
||||
_ = x[IBPB-78]
|
||||
_ = x[IBPB_BRTYPE-79]
|
||||
_ = x[IBRS-80]
|
||||
_ = x[IBRS_PREFERRED-81]
|
||||
_ = x[IBRS_PROVIDES_SMP-82]
|
||||
_ = x[IBS-83]
|
||||
_ = x[IBSBRNTRGT-84]
|
||||
_ = x[IBSFETCHSAM-85]
|
||||
_ = x[IBSFFV-86]
|
||||
_ = x[IBSOPCNT-87]
|
||||
_ = x[IBSOPCNTEXT-88]
|
||||
_ = x[IBSOPSAM-89]
|
||||
_ = x[IBSRDWROPCNT-90]
|
||||
_ = x[IBSRIPINVALIDCHK-91]
|
||||
_ = x[IBS_FETCH_CTLX-92]
|
||||
_ = x[IBS_OPDATA4-93]
|
||||
_ = x[IBS_OPFUSE-94]
|
||||
_ = x[IBS_PREVENTHOST-95]
|
||||
_ = x[IBS_ZEN4-96]
|
||||
_ = x[IDPRED_CTRL-97]
|
||||
_ = x[INT_WBINVD-98]
|
||||
_ = x[INVLPGB-99]
|
||||
_ = x[KEYLOCKER-100]
|
||||
_ = x[KEYLOCKERW-101]
|
||||
_ = x[LAHF-102]
|
||||
_ = x[LAM-103]
|
||||
_ = x[LBRVIRT-104]
|
||||
_ = x[LZCNT-105]
|
||||
_ = x[MCAOVERFLOW-106]
|
||||
_ = x[MCDT_NO-107]
|
||||
_ = x[MCOMMIT-108]
|
||||
_ = x[MD_CLEAR-109]
|
||||
_ = x[MMX-110]
|
||||
_ = x[MMXEXT-111]
|
||||
_ = x[MOVBE-112]
|
||||
_ = x[MOVDIR64B-113]
|
||||
_ = x[MOVDIRI-114]
|
||||
_ = x[MOVSB_ZL-115]
|
||||
_ = x[MOVU-116]
|
||||
_ = x[MPX-117]
|
||||
_ = x[MSRIRC-118]
|
||||
_ = x[MSRLIST-119]
|
||||
_ = x[MSR_PAGEFLUSH-120]
|
||||
_ = x[NRIPS-121]
|
||||
_ = x[NX-122]
|
||||
_ = x[OSXSAVE-123]
|
||||
_ = x[PCONFIG-124]
|
||||
_ = x[POPCNT-125]
|
||||
_ = x[PPIN-126]
|
||||
_ = x[PREFETCHI-127]
|
||||
_ = x[PSFD-128]
|
||||
_ = x[RDPRU-129]
|
||||
_ = x[RDRAND-130]
|
||||
_ = x[RDSEED-131]
|
||||
_ = x[RDTSCP-132]
|
||||
_ = x[RRSBA_CTRL-133]
|
||||
_ = x[RTM-134]
|
||||
_ = x[RTM_ALWAYS_ABORT-135]
|
||||
_ = x[SBPB-136]
|
||||
_ = x[SERIALIZE-137]
|
||||
_ = x[SEV-138]
|
||||
_ = x[SEV_64BIT-139]
|
||||
_ = x[SEV_ALTERNATIVE-140]
|
||||
_ = x[SEV_DEBUGSWAP-141]
|
||||
_ = x[SEV_ES-142]
|
||||
_ = x[SEV_RESTRICTED-143]
|
||||
_ = x[SEV_SNP-144]
|
||||
_ = x[SGX-145]
|
||||
_ = x[SGXLC-146]
|
||||
_ = x[SGXPQC-147]
|
||||
_ = x[SHA-148]
|
||||
_ = x[SME-149]
|
||||
_ = x[SME_COHERENT-150]
|
||||
_ = x[SM3_X86-151]
|
||||
_ = x[SM4_X86-152]
|
||||
_ = x[SPEC_CTRL_SSBD-153]
|
||||
_ = x[SRBDS_CTRL-154]
|
||||
_ = x[SRSO_MSR_FIX-155]
|
||||
_ = x[SRSO_NO-156]
|
||||
_ = x[SRSO_USER_KERNEL_NO-157]
|
||||
_ = x[SSE-158]
|
||||
_ = x[SSE2-159]
|
||||
_ = x[SSE3-160]
|
||||
_ = x[SSE4-161]
|
||||
_ = x[SSE42-162]
|
||||
_ = x[SSE4A-163]
|
||||
_ = x[SSSE3-164]
|
||||
_ = x[STIBP-165]
|
||||
_ = x[STIBP_ALWAYSON-166]
|
||||
_ = x[STOSB_SHORT-167]
|
||||
_ = x[SUCCOR-168]
|
||||
_ = x[SVM-169]
|
||||
_ = x[SVMDA-170]
|
||||
_ = x[SVMFBASID-171]
|
||||
_ = x[SVML-172]
|
||||
_ = x[SVMNP-173]
|
||||
_ = x[SVMPF-174]
|
||||
_ = x[SVMPFT-175]
|
||||
_ = x[SYSCALL-176]
|
||||
_ = x[SYSEE-177]
|
||||
_ = x[TBM-178]
|
||||
_ = x[TDX_GUEST-179]
|
||||
_ = x[TLB_FLUSH_NESTED-180]
|
||||
_ = x[TME-181]
|
||||
_ = x[TOPEXT-182]
|
||||
_ = x[TSA_L1_NO-183]
|
||||
_ = x[TSA_SQ_NO-184]
|
||||
_ = x[TSA_VERW_CLEAR-185]
|
||||
_ = x[TSCRATEMSR-186]
|
||||
_ = x[TSXLDTRK-187]
|
||||
_ = x[VAES-188]
|
||||
_ = x[VMCBCLEAN-189]
|
||||
_ = x[VMPL-190]
|
||||
_ = x[VMSA_REGPROT-191]
|
||||
_ = x[VMX-192]
|
||||
_ = x[VPCLMULQDQ-193]
|
||||
_ = x[VTE-194]
|
||||
_ = x[WAITPKG-195]
|
||||
_ = x[WBNOINVD-196]
|
||||
_ = x[WRMSRNS-197]
|
||||
_ = x[X87-198]
|
||||
_ = x[XGETBV1-199]
|
||||
_ = x[XOP-200]
|
||||
_ = x[XSAVE-201]
|
||||
_ = x[XSAVEC-202]
|
||||
_ = x[XSAVEOPT-203]
|
||||
_ = x[XSAVES-204]
|
||||
_ = x[AESARM-205]
|
||||
_ = x[ARMCPUID-206]
|
||||
_ = x[ASIMD-207]
|
||||
_ = x[ASIMDDP-208]
|
||||
_ = x[ASIMDHP-209]
|
||||
_ = x[ASIMDRDM-210]
|
||||
_ = x[ATOMICS-211]
|
||||
_ = x[CRC32-212]
|
||||
_ = x[DCPOP-213]
|
||||
_ = x[EVTSTRM-214]
|
||||
_ = x[FCMA-215]
|
||||
_ = x[FHM-216]
|
||||
_ = x[FP-217]
|
||||
_ = x[FPHP-218]
|
||||
_ = x[GPA-219]
|
||||
_ = x[JSCVT-220]
|
||||
_ = x[LRCPC-221]
|
||||
_ = x[PMULL-222]
|
||||
_ = x[RNDR-223]
|
||||
_ = x[TLB-224]
|
||||
_ = x[TS-225]
|
||||
_ = x[SHA1-226]
|
||||
_ = x[SHA2-227]
|
||||
_ = x[SHA3-228]
|
||||
_ = x[SHA512-229]
|
||||
_ = x[SM3-230]
|
||||
_ = x[SM4-231]
|
||||
_ = x[SVE-232]
|
||||
_ = x[PMU_FIXEDCOUNTER_CYCLES-233]
|
||||
_ = x[PMU_FIXEDCOUNTER_REFCYCLES-234]
|
||||
_ = x[PMU_FIXEDCOUNTER_INSTRUCTIONS-235]
|
||||
_ = x[PMU_FIXEDCOUNTER_TOPDOWN_SLOTS-236]
|
||||
_ = x[lastID-237]
|
||||
_ = x[AVX512BMM-22]
|
||||
_ = x[AVX512BW-23]
|
||||
_ = x[AVX512CD-24]
|
||||
_ = x[AVX512DQ-25]
|
||||
_ = x[AVX512ER-26]
|
||||
_ = x[AVX512F-27]
|
||||
_ = x[AVX512FP16-28]
|
||||
_ = x[AVX512IFMA-29]
|
||||
_ = x[AVX512PF-30]
|
||||
_ = x[AVX512VBMI-31]
|
||||
_ = x[AVX512VBMI2-32]
|
||||
_ = x[AVX512VL-33]
|
||||
_ = x[AVX512VNNI-34]
|
||||
_ = x[AVX512VP2INTERSECT-35]
|
||||
_ = x[AVX512VPOPCNTDQ-36]
|
||||
_ = x[AVXIFMA-37]
|
||||
_ = x[AVXNECONVERT-38]
|
||||
_ = x[AVXSLOW-39]
|
||||
_ = x[AVXVNNI-40]
|
||||
_ = x[AVXVNNIINT8-41]
|
||||
_ = x[AVXVNNIINT16-42]
|
||||
_ = x[BHI_CTRL-43]
|
||||
_ = x[BMI1-44]
|
||||
_ = x[BMI2-45]
|
||||
_ = x[CETIBT-46]
|
||||
_ = x[CETSS-47]
|
||||
_ = x[CLDEMOTE-48]
|
||||
_ = x[CLMUL-49]
|
||||
_ = x[CLZERO-50]
|
||||
_ = x[CMOV-51]
|
||||
_ = x[CMPCCXADD-52]
|
||||
_ = x[CMPSB_SCADBS_SHORT-53]
|
||||
_ = x[CMPXCHG8-54]
|
||||
_ = x[CPBOOST-55]
|
||||
_ = x[CPPC-56]
|
||||
_ = x[CX16-57]
|
||||
_ = x[EFER_LMSLE_UNS-58]
|
||||
_ = x[ENQCMD-59]
|
||||
_ = x[ERMS-60]
|
||||
_ = x[F16C-61]
|
||||
_ = x[FLUSH_L1D-62]
|
||||
_ = x[FMA3-63]
|
||||
_ = x[FMA4-64]
|
||||
_ = x[FP128-65]
|
||||
_ = x[FP256-66]
|
||||
_ = x[FRED-67]
|
||||
_ = x[FSRM-68]
|
||||
_ = x[FXSR-69]
|
||||
_ = x[FXSROPT-70]
|
||||
_ = x[GFNI-71]
|
||||
_ = x[HLE-72]
|
||||
_ = x[HRESET-73]
|
||||
_ = x[HTT-74]
|
||||
_ = x[HWA-75]
|
||||
_ = x[HYBRID_CPU-76]
|
||||
_ = x[HYPERVISOR-77]
|
||||
_ = x[IA32_ARCH_CAP-78]
|
||||
_ = x[IA32_CORE_CAP-79]
|
||||
_ = x[IBPB-80]
|
||||
_ = x[IBPB_BRTYPE-81]
|
||||
_ = x[IBRS-82]
|
||||
_ = x[IBRS_PREFERRED-83]
|
||||
_ = x[IBRS_PROVIDES_SMP-84]
|
||||
_ = x[IBS-85]
|
||||
_ = x[IBSBRNTRGT-86]
|
||||
_ = x[IBSFETCHSAM-87]
|
||||
_ = x[IBSFFV-88]
|
||||
_ = x[IBSOPCNT-89]
|
||||
_ = x[IBSOPCNTEXT-90]
|
||||
_ = x[IBSOPSAM-91]
|
||||
_ = x[IBSRDWROPCNT-92]
|
||||
_ = x[IBSRIPINVALIDCHK-93]
|
||||
_ = x[IBS_FETCH_CTLX-94]
|
||||
_ = x[IBS_OPDATA4-95]
|
||||
_ = x[IBS_OPFUSE-96]
|
||||
_ = x[IBS_PREVENTHOST-97]
|
||||
_ = x[IBS_ZEN4-98]
|
||||
_ = x[IDPRED_CTRL-99]
|
||||
_ = x[INT_WBINVD-100]
|
||||
_ = x[INVLPGB-101]
|
||||
_ = x[KEYLOCKER-102]
|
||||
_ = x[KEYLOCKERW-103]
|
||||
_ = x[LAHF-104]
|
||||
_ = x[LAM-105]
|
||||
_ = x[LBRVIRT-106]
|
||||
_ = x[LZCNT-107]
|
||||
_ = x[MCAOVERFLOW-108]
|
||||
_ = x[MCDT_NO-109]
|
||||
_ = x[MCOMMIT-110]
|
||||
_ = x[MD_CLEAR-111]
|
||||
_ = x[MMX-112]
|
||||
_ = x[MMXEXT-113]
|
||||
_ = x[MOVBE-114]
|
||||
_ = x[MOVDIR64B-115]
|
||||
_ = x[MOVDIRI-116]
|
||||
_ = x[MOVSB_ZL-117]
|
||||
_ = x[MOVU-118]
|
||||
_ = x[MPX-119]
|
||||
_ = x[MSRIRC-120]
|
||||
_ = x[MSRLIST-121]
|
||||
_ = x[MSR_PAGEFLUSH-122]
|
||||
_ = x[NRIPS-123]
|
||||
_ = x[NX-124]
|
||||
_ = x[OSXSAVE-125]
|
||||
_ = x[PCONFIG-126]
|
||||
_ = x[POPCNT-127]
|
||||
_ = x[PPIN-128]
|
||||
_ = x[PREFETCHI-129]
|
||||
_ = x[PSFD-130]
|
||||
_ = x[RDPRU-131]
|
||||
_ = x[RDRAND-132]
|
||||
_ = x[RDSEED-133]
|
||||
_ = x[RDTSCP-134]
|
||||
_ = x[RRSBA_CTRL-135]
|
||||
_ = x[RTM-136]
|
||||
_ = x[RTM_ALWAYS_ABORT-137]
|
||||
_ = x[SBPB-138]
|
||||
_ = x[SERIALIZE-139]
|
||||
_ = x[SEV-140]
|
||||
_ = x[SEV_64BIT-141]
|
||||
_ = x[SEV_ALTERNATIVE-142]
|
||||
_ = x[SEV_DEBUGSWAP-143]
|
||||
_ = x[SEV_ES-144]
|
||||
_ = x[SEV_RESTRICTED-145]
|
||||
_ = x[SEV_SNP-146]
|
||||
_ = x[SGX-147]
|
||||
_ = x[SGXLC-148]
|
||||
_ = x[SGXPQC-149]
|
||||
_ = x[SHA-150]
|
||||
_ = x[SME-151]
|
||||
_ = x[SME_COHERENT-152]
|
||||
_ = x[SM3_X86-153]
|
||||
_ = x[SM4_X86-154]
|
||||
_ = x[SPEC_CTRL_SSBD-155]
|
||||
_ = x[SRBDS_CTRL-156]
|
||||
_ = x[SRSO_MSR_FIX-157]
|
||||
_ = x[SRSO_NO-158]
|
||||
_ = x[SRSO_USER_KERNEL_NO-159]
|
||||
_ = x[SSE-160]
|
||||
_ = x[SSE2-161]
|
||||
_ = x[SSE3-162]
|
||||
_ = x[SSE4-163]
|
||||
_ = x[SSE42-164]
|
||||
_ = x[SSE4A-165]
|
||||
_ = x[SSSE3-166]
|
||||
_ = x[STIBP-167]
|
||||
_ = x[STIBP_ALWAYSON-168]
|
||||
_ = x[STOSB_SHORT-169]
|
||||
_ = x[SUCCOR-170]
|
||||
_ = x[SVM-171]
|
||||
_ = x[SVMDA-172]
|
||||
_ = x[SVMFBASID-173]
|
||||
_ = x[SVML-174]
|
||||
_ = x[SVMNP-175]
|
||||
_ = x[SVMPF-176]
|
||||
_ = x[SVMPFT-177]
|
||||
_ = x[SYSCALL-178]
|
||||
_ = x[SYSEE-179]
|
||||
_ = x[TBM-180]
|
||||
_ = x[TDX_GUEST-181]
|
||||
_ = x[TLB_FLUSH_NESTED-182]
|
||||
_ = x[TME-183]
|
||||
_ = x[TOPEXT-184]
|
||||
_ = x[TSA_L1_NO-185]
|
||||
_ = x[TSA_SQ_NO-186]
|
||||
_ = x[TSA_VERW_CLEAR-187]
|
||||
_ = x[TSCRATEMSR-188]
|
||||
_ = x[TSXLDTRK-189]
|
||||
_ = x[VAES-190]
|
||||
_ = x[VMCBCLEAN-191]
|
||||
_ = x[VMPL-192]
|
||||
_ = x[VMSA_REGPROT-193]
|
||||
_ = x[VMX-194]
|
||||
_ = x[VPCLMULQDQ-195]
|
||||
_ = x[VTE-196]
|
||||
_ = x[WAITPKG-197]
|
||||
_ = x[WBNOINVD-198]
|
||||
_ = x[WRMSRNS-199]
|
||||
_ = x[X87-200]
|
||||
_ = x[XGETBV1-201]
|
||||
_ = x[XOP-202]
|
||||
_ = x[XSAVE-203]
|
||||
_ = x[XSAVEC-204]
|
||||
_ = x[XSAVEOPT-205]
|
||||
_ = x[XSAVES-206]
|
||||
_ = x[AESARM-207]
|
||||
_ = x[ARMCPUID-208]
|
||||
_ = x[ASIMD-209]
|
||||
_ = x[ASIMDDP-210]
|
||||
_ = x[ASIMDHP-211]
|
||||
_ = x[ASIMDRDM-212]
|
||||
_ = x[ATOMICS-213]
|
||||
_ = x[CRC32-214]
|
||||
_ = x[DCPOP-215]
|
||||
_ = x[EVTSTRM-216]
|
||||
_ = x[FCMA-217]
|
||||
_ = x[FHM-218]
|
||||
_ = x[FP-219]
|
||||
_ = x[FPHP-220]
|
||||
_ = x[GPA-221]
|
||||
_ = x[JSCVT-222]
|
||||
_ = x[LRCPC-223]
|
||||
_ = x[PMULL-224]
|
||||
_ = x[RNDR-225]
|
||||
_ = x[TLB-226]
|
||||
_ = x[TS-227]
|
||||
_ = x[SHA1-228]
|
||||
_ = x[SHA2-229]
|
||||
_ = x[SHA3-230]
|
||||
_ = x[SHA512-231]
|
||||
_ = x[SM3-232]
|
||||
_ = x[SM4-233]
|
||||
_ = x[SVE-234]
|
||||
_ = x[SVE2-235]
|
||||
_ = x[SB-236]
|
||||
_ = x[SSBS-237]
|
||||
_ = x[BTI-238]
|
||||
_ = x[FLAGM2-239]
|
||||
_ = x[FRINTTS-240]
|
||||
_ = x[DCPODP-241]
|
||||
_ = x[BF16-242]
|
||||
_ = x[I8MM-243]
|
||||
_ = x[WFXT-244]
|
||||
_ = x[MOPS-245]
|
||||
_ = x[HBC-246]
|
||||
_ = x[CSSC-247]
|
||||
_ = x[PMU_FIXEDCOUNTER_CYCLES-248]
|
||||
_ = x[PMU_FIXEDCOUNTER_REFCYCLES-249]
|
||||
_ = x[PMU_FIXEDCOUNTER_INSTRUCTIONS-250]
|
||||
_ = x[PMU_FIXEDCOUNTER_TOPDOWN_SLOTS-251]
|
||||
_ = x[RV_IMA-252]
|
||||
_ = x[RV_C-253]
|
||||
_ = x[RV_F-254]
|
||||
_ = x[RV_D-255]
|
||||
_ = x[RV_V-256]
|
||||
_ = x[RV_ZBA-257]
|
||||
_ = x[RV_ZBB-258]
|
||||
_ = x[RV_ZBC-259]
|
||||
_ = x[RV_ZBS-260]
|
||||
_ = x[RV_ZICOND-261]
|
||||
_ = x[RV_ZIHINTPAUSE-262]
|
||||
_ = x[RV_ZICBOM-263]
|
||||
_ = x[RV_ZICBOZ-264]
|
||||
_ = x[RV_ZICBOP-265]
|
||||
_ = x[RV_ZFA-266]
|
||||
_ = x[RV_ZFH-267]
|
||||
_ = x[RV_ZFHMIN-268]
|
||||
_ = x[RV_ZTSO-269]
|
||||
_ = x[RV_ZACAS-270]
|
||||
_ = x[RV_ZBKB-271]
|
||||
_ = x[RV_ZBKC-272]
|
||||
_ = x[RV_ZBKX-273]
|
||||
_ = x[RV_ZKND-274]
|
||||
_ = x[RV_ZKNE-275]
|
||||
_ = x[RV_ZKNH-276]
|
||||
_ = x[RV_ZKSED-277]
|
||||
_ = x[RV_ZKSH-278]
|
||||
_ = x[RV_ZKT-279]
|
||||
_ = x[RV_ZKN-280]
|
||||
_ = x[RV_ZKS-281]
|
||||
_ = x[RV_ZVBB-282]
|
||||
_ = x[RV_ZVBC-283]
|
||||
_ = x[RV_ZVKB-284]
|
||||
_ = x[RV_ZVKG-285]
|
||||
_ = x[RV_ZVKNED-286]
|
||||
_ = x[RV_ZVKNHA-287]
|
||||
_ = x[RV_ZVKNHB-288]
|
||||
_ = x[RV_ZVKSED-289]
|
||||
_ = x[RV_ZVKSH-290]
|
||||
_ = x[RV_ZVKT-291]
|
||||
_ = x[RV_ZVKNG-292]
|
||||
_ = x[RV_ZVKSG-293]
|
||||
_ = x[lastID-294]
|
||||
_ = x[firstID-0]
|
||||
}
|
||||
|
||||
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXFP16AMXINT8AMXFP8AMXTILEAMXTF32AMXCOMPLEXAMXTRANSPOSEAPX_FAVXAVX10AVX10_128AVX10_256AVX10_512AVX2AVX512BF16AVX512BITALGAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXIFMAAVXNECONVERTAVXSLOWAVXVNNIAVXVNNIINT8AVXVNNIINT16BHI_CTRLBMI1BMI2CETIBTCETSSCLDEMOTECLMULCLZEROCMOVCMPCCXADDCMPSB_SCADBS_SHORTCMPXCHG8CPBOOSTCPPCCX16EFER_LMSLE_UNSENQCMDERMSF16CFLUSH_L1DFMA3FMA4FP128FP256FSRMFXSRFXSROPTGFNIHLEHRESETHTTHWAHYBRID_CPUHYPERVISORIA32_ARCH_CAPIA32_CORE_CAPIBPBIBPB_BRTYPEIBRSIBRS_PREFERREDIBRS_PROVIDES_SMPIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKIBS_FETCH_CTLXIBS_OPDATA4IBS_OPFUSEIBS_PREVENTHOSTIBS_ZEN4IDPRED_CTRLINT_WBINVDINVLPGBKEYLOCKERKEYLOCKERWLAHFLAMLBRVIRTLZCNTMCAOVERFLOWMCDT_NOMCOMMITMD_CLEARMMXMMXEXTMOVBEMOVDIR64BMOVDIRIMOVSB_ZLMOVUMPXMSRIRCMSRLISTMSR_PAGEFLUSHNRIPSNXOSXSAVEPCONFIGPOPCNTPPINPREFETCHIPSFDRDPRURDRANDRDSEEDRDTSCPRRSBA_CTRLRTMRTM_ALWAYS_ABORTSBPBSERIALIZESEVSEV_64BITSEV_ALTERNATIVESEV_DEBUGSWAPSEV_ESSEV_RESTRICTEDSEV_SNPSGXSGXLCSGXPQCSHASMESME_COHERENTSM3_X86SM4_X86SPEC_CTRL_SSBDSRBDS_CTRLSRSO_MSR_FIXSRSO_NOSRSO_USER_KERNEL_NOSSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSTIBP_ALWAYSONSTOSB_SHORTSUCCORSVMSVMDASVMFBASIDSVMLSVMNPSVMPFSVMPFTSYSCALLSYSEETBMTDX_GUESTTLB_FLUSH_NESTEDTMETOPEXTTSA_L1_NOTSA_SQ_NOTSA_VERW_CLEARTSCRATEMSRTSXLDTRKVAESVMCBCLEANVMPLVMSA_REGPROTVMXVPCLMULQDQVTEWAITPKGWBNOINVDWRMSRNSX87XGETBV1XOPXSAVEXSAVECXSAVEOPTXSAVESAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFHMFPFPHPGPAJSCVTLRCPCPMULLRNDRTLBTSSHA1SHA2SHA3SHA512SM3SM4SVEPMU_FIXEDCOUNTER_CYCLESPMU_FIXEDCOUNTER_REFCYCLESPMU_FIXEDCOUNTER_INSTRUCTIONSPMU_FIXEDCOUNTER_TOPDOWN_SLOTSlastID"
|
||||
const _FeatureID_name = "firstIDADXAESNIAMD3DNOWAMD3DNOWEXTAMXBF16AMXFP16AMXINT8AMXFP8AMXTILEAMXTF32AMXCOMPLEXAMXTRANSPOSEAPX_FAVXAVX10AVX10_128AVX10_256AVX10_512AVX2AVX512BF16AVX512BITALGAVX512BMMAVX512BWAVX512CDAVX512DQAVX512ERAVX512FAVX512FP16AVX512IFMAAVX512PFAVX512VBMIAVX512VBMI2AVX512VLAVX512VNNIAVX512VP2INTERSECTAVX512VPOPCNTDQAVXIFMAAVXNECONVERTAVXSLOWAVXVNNIAVXVNNIINT8AVXVNNIINT16BHI_CTRLBMI1BMI2CETIBTCETSSCLDEMOTECLMULCLZEROCMOVCMPCCXADDCMPSB_SCADBS_SHORTCMPXCHG8CPBOOSTCPPCCX16EFER_LMSLE_UNSENQCMDERMSF16CFLUSH_L1DFMA3FMA4FP128FP256FREDFSRMFXSRFXSROPTGFNIHLEHRESETHTTHWAHYBRID_CPUHYPERVISORIA32_ARCH_CAPIA32_CORE_CAPIBPBIBPB_BRTYPEIBRSIBRS_PREFERREDIBRS_PROVIDES_SMPIBSIBSBRNTRGTIBSFETCHSAMIBSFFVIBSOPCNTIBSOPCNTEXTIBSOPSAMIBSRDWROPCNTIBSRIPINVALIDCHKIBS_FETCH_CTLXIBS_OPDATA4IBS_OPFUSEIBS_PREVENTHOSTIBS_ZEN4IDPRED_CTRLINT_WBINVDINVLPGBKEYLOCKERKEYLOCKERWLAHFLAMLBRVIRTLZCNTMCAOVERFLOWMCDT_NOMCOMMITMD_CLEARMMXMMXEXTMOVBEMOVDIR64BMOVDIRIMOVSB_ZLMOVUMPXMSRIRCMSRLISTMSR_PAGEFLUSHNRIPSNXOSXSAVEPCONFIGPOPCNTPPINPREFETCHIPSFDRDPRURDRANDRDSEEDRDTSCPRRSBA_CTRLRTMRTM_ALWAYS_ABORTSBPBSERIALIZESEVSEV_64BITSEV_ALTERNATIVESEV_DEBUGSWAPSEV_ESSEV_RESTRICTEDSEV_SNPSGXSGXLCSGXPQCSHASMESME_COHERENTSM3_X86SM4_X86SPEC_CTRL_SSBDSRBDS_CTRLSRSO_MSR_FIXSRSO_NOSRSO_USER_KERNEL_NOSSESSE2SSE3SSE4SSE42SSE4ASSSE3STIBPSTIBP_ALWAYSONSTOSB_SHORTSUCCORSVMSVMDASVMFBASIDSVMLSVMNPSVMPFSVMPFTSYSCALLSYSEETBMTDX_GUESTTLB_FLUSH_NESTEDTMETOPEXTTSA_L1_NOTSA_SQ_NOTSA_VERW_CLEARTSCRATEMSRTSXLDTRKVAESVMCBCLEANVMPLVMSA_REGPROTVMXVPCLMULQDQVTEWAITPKGWBNOINVDWRMSRNSX87XGETBV1XOPXSAVEXSAVECXSAVEOPTXSAVESAESARMARMCPUIDASIMDASIMDDPASIMDHPASIMDRDMATOMICSCRC32DCPOPEVTSTRMFCMAFHMFPFPHPGPAJSCVTLRCPCPMULLRNDRTLBTSSHA1SHA2SHA3SHA512SM3SM4SVESVE2SBSSBSBTIFLAGM2FRINTTSDCPODPBF16I8MMWFXTMOPSHBCCSSCPMU_FIXEDCOUNTER_CYCLESPMU_FIXEDCOUNTER_REFCYCLESPMU_FIXEDCOUNTER_INSTRUCTIONSPMU_FIXEDCOUNTER_TOPDOWN_SLOTSRV_IMARV_CRV_FRV_DRV_VRV_ZBARV_ZBBRV_ZBCRV_ZBSRV_ZICONDRV_ZIHINTPAUSERV_ZICBOMRV_ZICBOZRV_ZICBOPRV_ZFARV_ZFHRV_ZFHMINRV_ZTSORV_ZACASRV_ZBKBRV_ZBKCRV_ZBKXRV_ZKNDRV_ZKNERV_ZKNHRV_ZKSEDRV_ZKSHRV_ZKTRV_ZKNRV_ZKSRV_ZVBBRV_ZVBCRV_ZVKBRV_ZVKGRV_ZVKNEDRV_ZVKNHARV_ZVKNHBRV_ZVKSEDRV_ZVKSHRV_ZVKTRV_ZVKNGRV_ZVKSGlastID"
|
||||
|
||||
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 61, 68, 75, 85, 97, 102, 105, 110, 119, 128, 137, 141, 151, 163, 171, 179, 187, 195, 202, 212, 222, 230, 240, 251, 259, 269, 287, 302, 309, 321, 328, 335, 346, 358, 366, 370, 374, 380, 385, 393, 398, 404, 408, 417, 435, 443, 450, 454, 458, 472, 478, 482, 486, 495, 499, 503, 508, 513, 517, 521, 528, 532, 535, 541, 544, 547, 557, 567, 580, 593, 597, 608, 612, 626, 643, 646, 656, 667, 673, 681, 692, 700, 712, 728, 742, 753, 763, 778, 786, 797, 807, 814, 823, 833, 837, 840, 847, 852, 863, 870, 877, 885, 888, 894, 899, 908, 915, 923, 927, 930, 936, 943, 956, 961, 963, 970, 977, 983, 987, 996, 1000, 1005, 1011, 1017, 1023, 1033, 1036, 1052, 1056, 1065, 1068, 1077, 1092, 1105, 1111, 1125, 1132, 1135, 1140, 1146, 1149, 1152, 1164, 1171, 1178, 1192, 1202, 1214, 1221, 1240, 1243, 1247, 1251, 1255, 1260, 1265, 1270, 1275, 1289, 1300, 1306, 1309, 1314, 1323, 1327, 1332, 1337, 1343, 1350, 1355, 1358, 1367, 1383, 1386, 1392, 1401, 1410, 1424, 1434, 1442, 1446, 1455, 1459, 1471, 1474, 1484, 1487, 1494, 1502, 1509, 1512, 1519, 1522, 1527, 1533, 1541, 1547, 1553, 1561, 1566, 1573, 1580, 1588, 1595, 1600, 1605, 1612, 1616, 1619, 1621, 1625, 1628, 1633, 1638, 1643, 1647, 1650, 1652, 1656, 1660, 1664, 1670, 1673, 1676, 1679, 1702, 1728, 1757, 1787, 1793}
|
||||
var _FeatureID_index = [...]uint16{0, 7, 10, 15, 23, 34, 41, 48, 55, 61, 68, 75, 85, 97, 102, 105, 110, 119, 128, 137, 141, 151, 163, 172, 180, 188, 196, 204, 211, 221, 231, 239, 249, 260, 268, 278, 296, 311, 318, 330, 337, 344, 355, 367, 375, 379, 383, 389, 394, 402, 407, 413, 417, 426, 444, 452, 459, 463, 467, 481, 487, 491, 495, 504, 508, 512, 517, 522, 526, 530, 534, 541, 545, 548, 554, 557, 560, 570, 580, 593, 606, 610, 621, 625, 639, 656, 659, 669, 680, 686, 694, 705, 713, 725, 741, 755, 766, 776, 791, 799, 810, 820, 827, 836, 846, 850, 853, 860, 865, 876, 883, 890, 898, 901, 907, 912, 921, 928, 936, 940, 943, 949, 956, 969, 974, 976, 983, 990, 996, 1000, 1009, 1013, 1018, 1024, 1030, 1036, 1046, 1049, 1065, 1069, 1078, 1081, 1090, 1105, 1118, 1124, 1138, 1145, 1148, 1153, 1159, 1162, 1165, 1177, 1184, 1191, 1205, 1215, 1227, 1234, 1253, 1256, 1260, 1264, 1268, 1273, 1278, 1283, 1288, 1302, 1313, 1319, 1322, 1327, 1336, 1340, 1345, 1350, 1356, 1363, 1368, 1371, 1380, 1396, 1399, 1405, 1414, 1423, 1437, 1447, 1455, 1459, 1468, 1472, 1484, 1487, 1497, 1500, 1507, 1515, 1522, 1525, 1532, 1535, 1540, 1546, 1554, 1560, 1566, 1574, 1579, 1586, 1593, 1601, 1608, 1613, 1618, 1625, 1629, 1632, 1634, 1638, 1641, 1646, 1651, 1656, 1660, 1663, 1665, 1669, 1673, 1677, 1683, 1686, 1689, 1692, 1696, 1698, 1702, 1705, 1711, 1718, 1724, 1728, 1732, 1736, 1740, 1743, 1747, 1770, 1796, 1825, 1855, 1861, 1865, 1869, 1873, 1877, 1883, 1889, 1895, 1901, 1910, 1924, 1933, 1942, 1951, 1957, 1963, 1972, 1979, 1987, 1994, 2001, 2008, 2015, 2022, 2029, 2037, 2044, 2050, 2056, 2062, 2069, 2076, 2083, 2090, 2099, 2108, 2117, 2126, 2134, 2141, 2149, 2157, 2163}
|
||||
|
||||
func (i FeatureID) String() string {
|
||||
if i < 0 || i >= FeatureID(len(_FeatureID_index)-1) {
|
||||
idx := int(i) - 0
|
||||
if i < 0 || idx >= len(_FeatureID_index)-1 {
|
||||
return "FeatureID(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _FeatureID_name[_FeatureID_index[i]:_FeatureID_index[i+1]]
|
||||
return _FeatureID_name[_FeatureID_index[idx]:_FeatureID_index[idx+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
@@ -293,16 +351,22 @@ func _() {
|
||||
_ = x[ACRN-28]
|
||||
_ = x[SRE-29]
|
||||
_ = x[Apple-30]
|
||||
_ = x[lastVendor-31]
|
||||
_ = x[SiFive-31]
|
||||
_ = x[StarFive-32]
|
||||
_ = x[THead-33]
|
||||
_ = x[Andes-34]
|
||||
_ = x[SpacemiT-35]
|
||||
_ = x[lastVendor-36]
|
||||
}
|
||||
|
||||
const _Vendor_name = "VendorUnknownIntelAMDVIATransmetaNSCKVMMSVMVMwareXenHVMBhyveHygonSiSRDCAmpereARMBroadcomCaviumDECFujitsuInfineonMotorolaNVIDIAAMCCQualcommMarvellQEMUQNXACRNSREApplelastVendor"
|
||||
const _Vendor_name = "VendorUnknownIntelAMDVIATransmetaNSCKVMMSVMVMwareXenHVMBhyveHygonSiSRDCAmpereARMBroadcomCaviumDECFujitsuInfineonMotorolaNVIDIAAMCCQualcommMarvellQEMUQNXACRNSREAppleSiFiveStarFiveTHeadAndesSpacemiTlastVendor"
|
||||
|
||||
var _Vendor_index = [...]uint8{0, 13, 18, 21, 24, 33, 36, 39, 43, 49, 55, 60, 65, 68, 71, 77, 80, 88, 94, 97, 104, 112, 120, 126, 130, 138, 145, 149, 152, 156, 159, 164, 174}
|
||||
var _Vendor_index = [...]uint8{0, 13, 18, 21, 24, 33, 36, 39, 43, 49, 55, 60, 65, 68, 71, 77, 80, 88, 94, 97, 104, 112, 120, 126, 130, 138, 145, 149, 152, 156, 159, 164, 170, 178, 183, 188, 196, 206}
|
||||
|
||||
func (i Vendor) String() string {
|
||||
if i < 0 || i >= Vendor(len(_Vendor_index)-1) {
|
||||
idx := int(i) - 0
|
||||
if i < 0 || idx >= len(_Vendor_index)-1 {
|
||||
return "Vendor(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _Vendor_name[_Vendor_index[i]:_Vendor_index[i+1]]
|
||||
return _Vendor_name[_Vendor_index[idx]:_Vendor_index[idx+1]]
|
||||
}
|
||||
+13
@@ -126,4 +126,17 @@ func tryToFillCPUInfoFomSysctl(c *CPUInfo) {
|
||||
setFeature(c, SM3, "hw.optional.arm.FEAT_SM3") // SM3 instructions
|
||||
setFeature(c, SM4, "hw.optional.arm.FEAT_SM4") // SM4 instructions
|
||||
setFeature(c, SVE, "hw.optional.arm.FEAT_SVE") // Scalable Vector Extension
|
||||
setFeature(c, SVE2, "hw.optional.arm.FEAT_SVE2") // Scalable Vector Extension 2
|
||||
setFeature(c, SB, "hw.optional.arm.FEAT_SB") // Speculation barrier
|
||||
setFeature(c, SSBS, "hw.optional.arm.FEAT_SSBS") // Speculative Store Bypass Safe
|
||||
setFeature(c, BTI, "hw.optional.arm.FEAT_BTI") // Branch Target Identification
|
||||
setFeature(c, FLAGM2, "hw.optional.arm.FEAT_FlagM2") // Condition flag manipulation version 2
|
||||
setFeature(c, FRINTTS, "hw.optional.arm.FEAT_FRINTTS") // Floating-point to integer rounding
|
||||
setFeature(c, DCPODP, "hw.optional.arm.FEAT_DPB2") // Data cache clean to Point of Deep Persistence
|
||||
setFeature(c, BF16, "hw.optional.arm.FEAT_BF16") // BFloat16 instructions
|
||||
setFeature(c, I8MM, "hw.optional.arm.FEAT_I8MM") // Int8 matrix multiplication
|
||||
setFeature(c, WFXT, "hw.optional.arm.FEAT_WFxT") // WFE/WFI with timeout
|
||||
setFeature(c, MOPS, "hw.optional.arm.FEAT_MOPS") // Memory copy and set instructions
|
||||
setFeature(c, HBC, "hw.optional.arm.FEAT_HBC") // Hinted conditional branches
|
||||
setFeature(c, CSSC, "hw.optional.arm.FEAT_CSSC") // Common short sequence compression
|
||||
}
|
||||
+52
-36
@@ -115,15 +115,19 @@ const (
|
||||
hwcap2_POE = 1 << 63
|
||||
)
|
||||
|
||||
// hwcap2 holds AT_HWCAP2. Unlike hwcap, the arm64 runtime does not expose it
|
||||
// through internal/cpu, so detectOS reads it from the auxiliary vector.
|
||||
var hwcap2 uint
|
||||
|
||||
func detectOS(c *CPUInfo) bool {
|
||||
// For now assuming no hyperthreading is reasonable.
|
||||
c.LogicalCores = runtime.NumCPU()
|
||||
c.PhysicalCores = c.LogicalCores
|
||||
c.ThreadsPerCore = 1
|
||||
if hwcap == 0 {
|
||||
// We did not get values from the runtime.
|
||||
// Try reading /proc/self/auxv
|
||||
|
||||
// hwcap is provided by the runtime through the internal/cpu.HWCap linkname,
|
||||
// but the runtime does not expose HWCAP2 on arm64. Read the auxiliary vector
|
||||
// directly to obtain hwcap2 (and hwcap when the linkname is unavailable).
|
||||
if hwcap == 0 || hwcap2 == 0 {
|
||||
// From https://github.com/golang/sys
|
||||
const (
|
||||
_AT_HWCAP = 16
|
||||
@@ -132,37 +136,34 @@ func detectOS(c *CPUInfo) bool {
|
||||
uintSize = int(32 << (^uint(0) >> 63))
|
||||
)
|
||||
|
||||
buf, err := ioutil.ReadFile("/proc/self/auxv")
|
||||
if err != nil {
|
||||
// e.g. on android /proc/self/auxv is not accessible, so silently
|
||||
// ignore the error and leave Initialized = false. On some
|
||||
// architectures (e.g. arm64) doinit() implements a fallback
|
||||
// readout and will set Initialized = true again.
|
||||
return false
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
for len(buf) >= 2*(uintSize/8) {
|
||||
var tag, val uint
|
||||
switch uintSize {
|
||||
case 32:
|
||||
tag = uint(bo.Uint32(buf[0:]))
|
||||
val = uint(bo.Uint32(buf[4:]))
|
||||
buf = buf[8:]
|
||||
case 64:
|
||||
tag = uint(bo.Uint64(buf[0:]))
|
||||
val = uint(bo.Uint64(buf[8:]))
|
||||
buf = buf[16:]
|
||||
}
|
||||
switch tag {
|
||||
case _AT_HWCAP:
|
||||
hwcap = val
|
||||
case _AT_HWCAP2:
|
||||
// Not used
|
||||
// e.g. on android /proc/self/auxv is not accessible, so silently ignore
|
||||
// the error and fall back to whatever the runtime provided.
|
||||
if buf, err := ioutil.ReadFile("/proc/self/auxv"); err == nil {
|
||||
bo := binary.LittleEndian
|
||||
for len(buf) >= 2*(uintSize/8) {
|
||||
var tag, val uint
|
||||
switch uintSize {
|
||||
case 32:
|
||||
tag = uint(bo.Uint32(buf[0:]))
|
||||
val = uint(bo.Uint32(buf[4:]))
|
||||
buf = buf[8:]
|
||||
case 64:
|
||||
tag = uint(bo.Uint64(buf[0:]))
|
||||
val = uint(bo.Uint64(buf[8:]))
|
||||
buf = buf[16:]
|
||||
}
|
||||
switch tag {
|
||||
case _AT_HWCAP:
|
||||
hwcap = val
|
||||
case _AT_HWCAP2:
|
||||
hwcap2 = val
|
||||
}
|
||||
}
|
||||
}
|
||||
if hwcap == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
if hwcap == 0 {
|
||||
// Nothing detected, e.g. on android or a restricted environment.
|
||||
return false
|
||||
}
|
||||
|
||||
// HWCap was populated by the runtime from the auxiliary vector.
|
||||
@@ -184,9 +185,9 @@ func detectOS(c *CPUInfo) bool {
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_JSCVT), JSCVT)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_LRCPC), LRCPC)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_PMULL), PMULL)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap2_RNG), RNDR)
|
||||
// c.featureSet.setIf(isSet(hwcap, hwcap_), TLB)
|
||||
// c.featureSet.setIf(isSet(hwcap, hwcap_), TS)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_RNG), RNDR)
|
||||
// TLB (FEAT_TLBIOS/TLBIRANGE) has no HWCAP bit; only detectable via ID registers.
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_FLAGM), TS)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SHA1), SHA1)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SHA2), SHA2)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SHA3), SHA3)
|
||||
@@ -194,6 +195,21 @@ func detectOS(c *CPUInfo) bool {
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SM3), SM3)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SM4), SM4)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SVE), SVE)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SB), SB)
|
||||
c.featureSet.setIf(isSet(hwcap, hwcap_SSBS), SSBS)
|
||||
|
||||
// Features reported through the second hardware capability word (HWCAP2).
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_SVE2), SVE2)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_BTI), BTI)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_FLAGM2), FLAGM2)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_FRINT), FRINTTS)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_DCPODP), DCPODP)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_BF16), BF16)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_I8MM), I8MM)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_WFXT), WFXT)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_MOPS), MOPS)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_HBC), HBC)
|
||||
c.featureSet.setIf(isSet(hwcap2, hwcap2_CSSC), CSSC)
|
||||
|
||||
// The Samsung S9+ kernel reports support for atomics, but not all cores
|
||||
// actually support them, resulting in SIGILL. See issue #28431.
|
||||
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
// Copyright (c) 2026 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
package cpuid
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
const __NR_riscv_hwprobe = 258
|
||||
|
||||
type riscvHWProbePair struct {
|
||||
key int64
|
||||
value uint64
|
||||
}
|
||||
|
||||
// Keys from linux/include/uapi/asm/hwprobe.h
|
||||
const (
|
||||
riscv_hwprobe_key_mvendorid = 0
|
||||
riscv_hwprobe_key_marchid = 1
|
||||
riscv_hwprobe_key_mimpid = 2
|
||||
riscv_hwprobe_key_base_behavior = 3
|
||||
riscv_hwprobe_key_ima_ext_0 = 4
|
||||
riscv_hwprobe_key_cpuperf_0 = 5
|
||||
riscv_hwprobe_key_zicbom_block_size = 12
|
||||
)
|
||||
|
||||
// Bits from linux/arch/riscv/include/uapi/asm/hwprobe.h
|
||||
const (
|
||||
riscv_hwprobe_ima_fd = 1 << 0
|
||||
riscv_hwprobe_ima_c = 1 << 1
|
||||
riscv_hwprobe_ima_v = 1 << 2
|
||||
riscv_hwprobe_ext_zba = 1 << 3
|
||||
riscv_hwprobe_ext_zbb = 1 << 4
|
||||
riscv_hwprobe_ext_zbs = 1 << 5
|
||||
riscv_hwprobe_ext_zicboz = 1 << 6
|
||||
riscv_hwprobe_ext_zbc = 1 << 7
|
||||
riscv_hwprobe_ext_zbkb = 1 << 8
|
||||
riscv_hwprobe_ext_zbkc = 1 << 9
|
||||
riscv_hwprobe_ext_zbkx = 1 << 10
|
||||
riscv_hwprobe_ext_zknd = 1 << 11
|
||||
riscv_hwprobe_ext_zkne = 1 << 12
|
||||
riscv_hwprobe_ext_zknh = 1 << 13
|
||||
riscv_hwprobe_ext_zksed = 1 << 14
|
||||
riscv_hwprobe_ext_zksh = 1 << 15
|
||||
riscv_hwprobe_ext_zkt = 1 << 16
|
||||
riscv_hwprobe_ext_zvbb = 1 << 17
|
||||
riscv_hwprobe_ext_zvbc = 1 << 18
|
||||
riscv_hwprobe_ext_zvkb = 1 << 19
|
||||
riscv_hwprobe_ext_zvkg = 1 << 20
|
||||
riscv_hwprobe_ext_zvkned = 1 << 21
|
||||
riscv_hwprobe_ext_zvknha = 1 << 22
|
||||
riscv_hwprobe_ext_zvknhb = 1 << 23
|
||||
riscv_hwprobe_ext_zvksed = 1 << 24
|
||||
riscv_hwprobe_ext_zvksh = 1 << 25
|
||||
riscv_hwprobe_ext_zvkt = 1 << 26
|
||||
riscv_hwprobe_ext_zfh = 1 << 27
|
||||
riscv_hwprobe_ext_zfhmin = 1 << 28
|
||||
riscv_hwprobe_ext_zihintntl = 1 << 29
|
||||
riscv_hwprobe_ext_zvfh = 1 << 30
|
||||
riscv_hwprobe_ext_zvfhmin = 1 << 31
|
||||
riscv_hwprobe_ext_zfa = 1 << 32
|
||||
riscv_hwprobe_ext_ztso = 1 << 33
|
||||
riscv_hwprobe_ext_zacas = 1 << 34
|
||||
riscv_hwprobe_ext_zicond = 1 << 35
|
||||
riscv_hwprobe_ext_zihintpause = 1 << 36
|
||||
riscv_hwprobe_ext_zicbom = 1 << 55
|
||||
riscv_hwprobe_ext_zicbop = 1 << 60
|
||||
)
|
||||
|
||||
func riscvHWProbe(pairs []riscvHWProbePair) int64 {
|
||||
if len(pairs) == 0 {
|
||||
return -1
|
||||
}
|
||||
ret, _, _ := unix.Syscall6(__NR_riscv_hwprobe,
|
||||
uintptr(unsafe.Pointer(&pairs[0])),
|
||||
uintptr(len(pairs)),
|
||||
0, 0, 0, 0)
|
||||
return int64(ret)
|
||||
}
|
||||
|
||||
func detectOS(c *CPUInfo) bool {
|
||||
c.LogicalCores = runtime.NumCPU()
|
||||
c.PhysicalCores = c.LogicalCores
|
||||
c.ThreadsPerCore = 1
|
||||
|
||||
pairs := []riscvHWProbePair{
|
||||
{key: riscv_hwprobe_key_mvendorid},
|
||||
{key: riscv_hwprobe_key_marchid},
|
||||
{key: riscv_hwprobe_key_mimpid},
|
||||
{key: riscv_hwprobe_key_ima_ext_0},
|
||||
{key: riscv_hwprobe_key_zicbom_block_size},
|
||||
}
|
||||
ret := riscvHWProbe(pairs)
|
||||
if ret == 0 && pairs[3].value != ^uint64(0) {
|
||||
detectFromHWProbe(c, pairs)
|
||||
if pairs[4].value != ^uint64(0) && pairs[4].value > 0 {
|
||||
c.CacheLine = int(pairs[4].value)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
c.CacheLine = detectCacheLine()
|
||||
return detectFromCPUInfo(c)
|
||||
}
|
||||
|
||||
func detectFromHWProbe(c *CPUInfo, pairs []riscvHWProbePair) {
|
||||
if pairs[0].value != ^uint64(0) {
|
||||
c.VendorID = riscvVendorID(pairs[0].value)
|
||||
c.VendorString = c.VendorID.String()
|
||||
}
|
||||
if pairs[1].value != ^uint64(0) {
|
||||
c.Model = int(pairs[1].value)
|
||||
}
|
||||
if pairs[2].value != ^uint64(0) {
|
||||
c.Family = int(pairs[2].value)
|
||||
}
|
||||
|
||||
imaExt := pairs[3].value
|
||||
|
||||
if imaExt&riscv_hwprobe_ima_fd != 0 {
|
||||
c.featureSet.set(RV_D)
|
||||
c.featureSet.set(RV_F)
|
||||
}
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ima_c != 0, RV_C)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ima_v != 0, RV_V)
|
||||
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zba != 0, RV_ZBA)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbb != 0, RV_ZBB)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbc != 0, RV_ZBC)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbs != 0, RV_ZBS)
|
||||
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zicbom != 0, RV_ZICBOM)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zicboz != 0, RV_ZICBOZ)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zicbop != 0, RV_ZICBOP)
|
||||
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zicond != 0, RV_ZICOND)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zihintpause != 0, RV_ZIHINTPAUSE)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zfa != 0, RV_ZFA)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zfh != 0, RV_ZFH)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zfhmin != 0, RV_ZFHMIN)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_ztso != 0, RV_ZTSO)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zacas != 0, RV_ZACAS)
|
||||
|
||||
// Scalar cryptography
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbkb != 0, RV_ZBKB)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbkc != 0, RV_ZBKC)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zbkx != 0, RV_ZBKX)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zknd != 0, RV_ZKND)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zkne != 0, RV_ZKNE)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zknh != 0, RV_ZKNH)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zksed != 0, RV_ZKSED)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zksh != 0, RV_ZKSH)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zkt != 0, RV_ZKT)
|
||||
|
||||
// Vector cryptography
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvbb != 0, RV_ZVBB)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvbc != 0, RV_ZVBC)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvkb != 0, RV_ZVKB)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvkg != 0, RV_ZVKG)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvkned != 0, RV_ZVKNED)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvknha != 0, RV_ZVKNHA)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvknhb != 0, RV_ZVKNHB)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvksed != 0, RV_ZVKSED)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvksh != 0, RV_ZVKSH)
|
||||
c.featureSet.setIf(imaExt&riscv_hwprobe_ext_zvkt != 0, RV_ZVKT)
|
||||
|
||||
// Crypto suites (combined from individual features)
|
||||
c.featureSet.setIf(c.featureSet.hasSetP(rvZKNFeatures), RV_ZKN)
|
||||
c.featureSet.setIf(c.featureSet.hasSetP(rvZKSFeatures), RV_ZKS)
|
||||
c.featureSet.setIf(c.featureSet.hasSetP(rvZVKNFeatures), RV_ZVKNG)
|
||||
c.featureSet.setIf(c.featureSet.hasSetP(rvZVKSFeatures), RV_ZVKSG)
|
||||
|
||||
// Every Linux-capable riscv64 core has I, M, A base.
|
||||
c.featureSet.set(RV_IMA)
|
||||
}
|
||||
|
||||
func detectFromCPUInfo(c *CPUInfo) bool {
|
||||
f, err := os.Open("/proc/cpuinfo")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
fields := strings.SplitN(line, ":", 2)
|
||||
if len(fields) < 2 {
|
||||
continue
|
||||
}
|
||||
key := strings.TrimSpace(fields[0])
|
||||
value := strings.TrimSpace(fields[1])
|
||||
|
||||
switch key {
|
||||
case "isa":
|
||||
parseISAString(c, value)
|
||||
case "mvendorid":
|
||||
if vid, err := strconv.ParseUint(value, 0, 64); err == nil {
|
||||
c.VendorID = riscvVendorID(vid)
|
||||
c.VendorString = c.VendorID.String()
|
||||
}
|
||||
case "uarch":
|
||||
c.BrandName = value
|
||||
}
|
||||
}
|
||||
return scanner.Err() == nil
|
||||
}
|
||||
|
||||
func detectCacheLine() int {
|
||||
data, err := os.ReadFile("/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size")
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
if n, err := strconv.Atoi(strings.TrimSpace(string(data))); err == nil && n > 0 {
|
||||
return n
|
||||
}
|
||||
return 0
|
||||
}
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2020 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build arm64 && !linux && !darwin
|
||||
// +build arm64,!linux,!darwin
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2026 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build riscv64 && !linux
|
||||
|
||||
package cpuid
|
||||
|
||||
import "runtime"
|
||||
|
||||
func detectOS(c *CPUInfo) bool {
|
||||
c.PhysicalCores = runtime.NumCPU()
|
||||
c.ThreadsPerCore = 1
|
||||
c.LogicalCores = c.PhysicalCores
|
||||
return false
|
||||
}
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build nounsafe
|
||||
// +build nounsafe
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
-1
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2021 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
//go:build !nounsafe
|
||||
// +build !nounsafe
|
||||
|
||||
package cpuid
|
||||
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
// Copyright (c) 2026 Klaus Post, released under MIT License. See LICENSE file.
|
||||
|
||||
package cpuid
|
||||
|
||||
import "strings"
|
||||
|
||||
func parseISAString(c *CPUInfo, isa string) {
|
||||
isa = strings.ToLower(isa)
|
||||
extMap := make(map[string]bool)
|
||||
for ext := range strings.SplitSeq(isa, "_") {
|
||||
ext = strings.TrimSpace(ext)
|
||||
if strings.HasPrefix(ext, "rv64") {
|
||||
extMap["i"] = true
|
||||
for _, ch := range ext[4:] {
|
||||
extMap[string(ch)] = true
|
||||
}
|
||||
} else if ext != "" {
|
||||
extMap[ext] = true
|
||||
}
|
||||
}
|
||||
|
||||
if extMap["g"] {
|
||||
extMap["i"] = true
|
||||
extMap["m"] = true
|
||||
extMap["a"] = true
|
||||
extMap["f"] = true
|
||||
extMap["d"] = true
|
||||
}
|
||||
|
||||
c.featureSet.setIf(extMap["i"] && extMap["m"] && extMap["a"], RV_IMA)
|
||||
c.featureSet.setIf(extMap["c"], RV_C)
|
||||
c.featureSet.setIf(extMap["f"], RV_F)
|
||||
c.featureSet.setIf(extMap["d"], RV_D)
|
||||
c.featureSet.setIf(extMap["v"], RV_V)
|
||||
c.featureSet.setIf(extMap["zihintpause"], RV_ZIHINTPAUSE)
|
||||
c.featureSet.setIf(extMap["zba"], RV_ZBA)
|
||||
c.featureSet.setIf(extMap["zbb"], RV_ZBB)
|
||||
c.featureSet.setIf(extMap["zbc"], RV_ZBC)
|
||||
c.featureSet.setIf(extMap["zbs"], RV_ZBS)
|
||||
c.featureSet.setIf(extMap["zicond"], RV_ZICOND)
|
||||
c.featureSet.setIf(extMap["zicbom"], RV_ZICBOM)
|
||||
c.featureSet.setIf(extMap["zicboz"], RV_ZICBOZ)
|
||||
c.featureSet.setIf(extMap["zicbop"], RV_ZICBOP)
|
||||
c.featureSet.setIf(extMap["zfa"], RV_ZFA)
|
||||
c.featureSet.setIf(extMap["zfh"], RV_ZFH)
|
||||
c.featureSet.setIf(extMap["zfhmin"], RV_ZFHMIN)
|
||||
c.featureSet.setIf(extMap["ztso"], RV_ZTSO)
|
||||
c.featureSet.setIf(extMap["zacas"], RV_ZACAS)
|
||||
|
||||
// Scalar cryptography
|
||||
c.featureSet.setIf(extMap["zbkb"], RV_ZBKB)
|
||||
c.featureSet.setIf(extMap["zbkc"], RV_ZBKC)
|
||||
c.featureSet.setIf(extMap["zbkx"], RV_ZBKX)
|
||||
c.featureSet.setIf(extMap["zknd"], RV_ZKND)
|
||||
c.featureSet.setIf(extMap["zkne"], RV_ZKNE)
|
||||
c.featureSet.setIf(extMap["zknh"], RV_ZKNH)
|
||||
c.featureSet.setIf(extMap["zksed"], RV_ZKSED)
|
||||
c.featureSet.setIf(extMap["zksh"], RV_ZKSH)
|
||||
c.featureSet.setIf(extMap["zkt"], RV_ZKT)
|
||||
|
||||
// Vector cryptography
|
||||
c.featureSet.setIf(extMap["zvbb"], RV_ZVBB)
|
||||
c.featureSet.setIf(extMap["zvbc"], RV_ZVBC)
|
||||
c.featureSet.setIf(extMap["zvkb"], RV_ZVKB)
|
||||
c.featureSet.setIf(extMap["zvkg"], RV_ZVKG)
|
||||
c.featureSet.setIf(extMap["zvkned"], RV_ZVKNED)
|
||||
c.featureSet.setIf(extMap["zvknha"], RV_ZVKNHA)
|
||||
c.featureSet.setIf(extMap["zvknhb"], RV_ZVKNHB)
|
||||
c.featureSet.setIf(extMap["zvksed"], RV_ZVKSED)
|
||||
c.featureSet.setIf(extMap["zvksh"], RV_ZVKSH)
|
||||
c.featureSet.setIf(extMap["zvkt"], RV_ZVKT)
|
||||
|
||||
// Crypto suites (combined from individual features or bundle tokens)
|
||||
c.featureSet.setIf(extMap["zkn"] || c.featureSet.hasSetP(rvZKNFeatures), RV_ZKN)
|
||||
c.featureSet.setIf(extMap["zks"] || c.featureSet.hasSetP(rvZKSFeatures), RV_ZKS)
|
||||
c.featureSet.setIf(extMap["zvkng"] || c.featureSet.hasSetP(rvZVKNFeatures), RV_ZVKNG)
|
||||
c.featureSet.setIf(extMap["zvksg"] || c.featureSet.hasSetP(rvZVKSFeatures), RV_ZVKSG)
|
||||
}
|
||||
|
||||
var riscvVendorMap = map[uint64]Vendor{
|
||||
0x489: SiFive,
|
||||
0x5b7: StarFive,
|
||||
0x5b1: THead,
|
||||
0x31e: Andes,
|
||||
0x710: SpacemiT,
|
||||
}
|
||||
|
||||
func riscvVendorID(mvendorid uint64) Vendor {
|
||||
if v, ok := riscvVendorMap[mvendorid]; ok {
|
||||
return v
|
||||
}
|
||||
return VendorUnknown
|
||||
}
|
||||
-1
@@ -20,7 +20,6 @@ Package [github.com/skeema/knownhosts](https://github.com/skeema/knownhosts) pro
|
||||
* Auto-populate ssh.ClientConfig.HostKeyAlgorithms easily based on known_hosts, providing a solution for [golang/go#29286](https://github.com/golang/go/issues/29286). (This also properly handles cert algorithms for hosts using CA keys when [using the NewDB constructor](#enhancements-requiring-extra-parsing) added in skeema/knownhosts v1.3.0.)
|
||||
* Properly match wildcard hostname known_hosts entries regardless of port number, providing a solution for [golang/go#52056](https://github.com/golang/go/issues/52056). (Added in v1.3.0; requires [using the NewDB constructor](#enhancements-requiring-extra-parsing))
|
||||
* Write new known_hosts entries to an io.Writer
|
||||
* Properly format/normalize new known_hosts entries containing ipv6 addresses, providing a solution for [golang/go#53463](https://github.com/golang/go/issues/53463)
|
||||
* Easily determine if an ssh.HostKeyCallback's error corresponds to a host whose key has changed (indicating potential MitM attack) vs a host that just isn't known yet
|
||||
|
||||
## How host key lookup works
|
||||
|
||||
+14
-19
@@ -194,11 +194,9 @@ func (hkdb *HostKeyDB) HostKeys(hostWithPort string) (keys []PublicKey) {
|
||||
// in the known_hosts file will properly be converted to the corresponding
|
||||
// ssh.CertAlgo* values.
|
||||
func (hkdb *HostKeyDB) HostKeyAlgorithms(hostWithPort string) (algos []string) {
|
||||
// We ensure that algos never contains duplicates. This is done for robustness
|
||||
// even though currently golang.org/x/crypto/ssh/knownhosts never exposes
|
||||
// multiple keys of the same type. This way our behavior here is unaffected
|
||||
// even if https://github.com/golang/go/issues/28870 is implemented, for
|
||||
// example by https://github.com/golang/crypto/pull/254.
|
||||
// We ensure that the return value never contains duplicates. This is needed
|
||||
// since golang.org/x/crypto/ssh/knownhosts can now return multiple keys of
|
||||
// the same type after https://github.com/golang/crypto/pull/254 was merged.
|
||||
hostKeys := hkdb.HostKeys(hostWithPort)
|
||||
seen := make(map[string]struct{}, len(hostKeys))
|
||||
addAlgo := func(typ string, cert bool) {
|
||||
@@ -367,26 +365,23 @@ func IsHostUnknown(err error) bool {
|
||||
}
|
||||
|
||||
// Normalize normalizes an address into the form used in known_hosts. This
|
||||
// implementation includes a fix for https://github.com/golang/go/issues/53463
|
||||
// and will omit brackets around ipv6 addresses on standard port 22.
|
||||
// implementation fixes the buggy IPv6 edge-cases found in golang.org/x/crypto
|
||||
// below v0.42.0; see https://github.com/golang/go/issues/53463. In all other
|
||||
// cases, this simply delegates to the upstream Normalize implementation.
|
||||
func Normalize(address string) string {
|
||||
host, port, err := net.SplitHostPort(address)
|
||||
if err != nil {
|
||||
host = address
|
||||
port = "22"
|
||||
// Although our go.mod specifies a new-enough golang.org/x/crypto to avoid
|
||||
// the IPv6 bug, this logic will remain in-place for sake of robustness in
|
||||
// non-go.mod use-cases (OS package managers, hacky forks like go-git's, etc)
|
||||
result := xknownhosts.Normalize(address)
|
||||
if strings.HasSuffix(result, "]") && strings.HasPrefix(result, "[") {
|
||||
return result[1 : len(result)-1]
|
||||
}
|
||||
entry := host
|
||||
if port != "22" {
|
||||
entry = "[" + entry + "]:" + port
|
||||
} else if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
|
||||
entry = entry[1 : len(entry)-1]
|
||||
}
|
||||
return entry
|
||||
return result
|
||||
}
|
||||
|
||||
// Line returns a line to append to the known_hosts files. This implementation
|
||||
// uses the local patched implementation of Normalize in order to solve
|
||||
// https://github.com/golang/go/issues/53463.
|
||||
// https://github.com/golang/go/issues/53463 when using x/crypto below v0.42.0.
|
||||
func Line(addresses []string, key ssh.PublicKey) string {
|
||||
var trimmed []string
|
||||
for _, a := range addresses {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build (!amd64 && !loong64 && !ppc64le && !ppc64 && !s390x) || !gc || purego
|
||||
//go:build (!amd64 && !loong64 && !ppc64le && !ppc64 && !riscv64 && !s390x) || !gc || purego
|
||||
|
||||
package poly1305
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build gc && !purego && (amd64 || loong64 || ppc64 || ppc64le)
|
||||
//go:build gc && !purego && (amd64 || loong64 || ppc64 || ppc64le || riscv64)
|
||||
|
||||
package poly1305
|
||||
|
||||
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
// Copyright 2026 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 gc && !purego
|
||||
|
||||
#define LOAD64U(base, offset, t0, t1, t2, t3, dst) \
|
||||
MOVBU (offset+0*1)(base), t0; \
|
||||
MOVBU (offset+1*1)(base), t1; \
|
||||
MOVBU (offset+2*1)(base), t2; \
|
||||
MOVBU (offset+3*1)(base), t3; \
|
||||
SLL $8, t1; \
|
||||
SLL $16, t2; \
|
||||
SLL $24, t3; \
|
||||
OR t1, t0; \
|
||||
OR t3, t2; \
|
||||
OR t2, t0, dst; \
|
||||
MOVBU (offset+4*1)(base), t0; \
|
||||
MOVBU (offset+5*1)(base), t1; \
|
||||
MOVBU (offset+6*1)(base), t2; \
|
||||
MOVBU (offset+7*1)(base), t3; \
|
||||
SLL $32, t0; \
|
||||
SLL $40, t1; \
|
||||
SLL $48, t2; \
|
||||
SLL $56, t3; \
|
||||
OR t1, t0; \
|
||||
OR t3, t2; \
|
||||
OR t2, t0; \
|
||||
OR t0, dst
|
||||
|
||||
// func update(state *macState, msg []byte)
|
||||
TEXT ·update(SB), $0-32
|
||||
MOV state+0(FP), X5
|
||||
MOV msg_base+8(FP), X6
|
||||
MOV msg_len+16(FP), X7
|
||||
|
||||
MOV $16, X8
|
||||
|
||||
AND $7, X6, X28
|
||||
|
||||
MOV (0*8)(X5), X9 // h0
|
||||
MOV (1*8)(X5), X10 // h1
|
||||
MOV (2*8)(X5), X11 // h2
|
||||
MOV (3*8)(X5), X12 // r0
|
||||
MOV (4*8)(X5), X13 // r1
|
||||
|
||||
BLT X7, X8, tail
|
||||
|
||||
loop:
|
||||
BEQZ X28, aligned_load
|
||||
|
||||
LOAD64U(X6, 0*8, X16, X18, X19, X20, X15) // msg[0:8]
|
||||
LOAD64U(X6, 1*8, X16, X18, X19, X20, X17) // msg[8:16]
|
||||
JMP block
|
||||
|
||||
aligned_load:
|
||||
MOV (0*8)(X6), X15 // msg[0:8]
|
||||
MOV (1*8)(X6), X17 // msg[8:16]
|
||||
|
||||
block:
|
||||
ADD X15, X9 // h0 (x1 + y1 = z1', if z1' < x1 then z1' overflow)
|
||||
SLTU X15, X9, X19 // h0.carry
|
||||
ADD X17, X10, X22
|
||||
SLTU X17, X22, X23
|
||||
ADD X22, X19, X10 // h1
|
||||
SLTU X22, X10, X19
|
||||
OR X23, X19 // h1.carry
|
||||
ADD $1, X19
|
||||
ADD X19, X11 // h2
|
||||
|
||||
ADD $16, X6 // msg = msg[16:]
|
||||
|
||||
multiply:
|
||||
MULHU X9, X12, X16 // h0r0.hi
|
||||
MUL X9, X12, X15 // h0r0.lo
|
||||
MULHU X10, X12, X17 // h1r0.hi
|
||||
MUL X10, X12, X14 // h1r0.lo
|
||||
ADD X14, X16
|
||||
SLTU X14, X16, X19
|
||||
ADD X19, X17
|
||||
MUL X11, X12, X20
|
||||
ADD X17, X20
|
||||
MULHU X9, X13, X17 // h0r1.hi
|
||||
MUL X9, X13, X14 // h0r1.lo
|
||||
ADD X14, X16
|
||||
SLTU X14, X16, X19
|
||||
ADD X19, X17
|
||||
MOV X17, X9
|
||||
MUL X11, X13, X21 // h2r1
|
||||
MULHU X10, X13, X17 // h1r1.hi
|
||||
MUL X10, X13, X14 // h1r1.lo
|
||||
ADD X14, X20
|
||||
ADD X17, X21, X22
|
||||
SLTU X14, X20, X19
|
||||
ADD X22, X19, X21
|
||||
ADD X9, X20
|
||||
SLTU X9, X20, X19
|
||||
ADD X19, X21
|
||||
AND $3, X20, X11
|
||||
AND $-4, X20, X18
|
||||
ADD X18, X15, X9
|
||||
ADD X21, X16, X22
|
||||
SLTU X18, X9, X19
|
||||
SLTU X21, X22, X23
|
||||
ADD X22, X19, X10
|
||||
SLTU X22, X10, X19
|
||||
OR X19, X23, X19
|
||||
ADD X19, X11
|
||||
SLL $62, X21, X22
|
||||
SRL $2, X20, X23
|
||||
SRL $2, X21, X21
|
||||
OR X22, X23, X20
|
||||
ADD X20, X9, X9
|
||||
ADD X21, X10, X22
|
||||
SLTU X20, X9, X19
|
||||
SLTU X21, X22, X23
|
||||
ADD X22, X19, X10
|
||||
SLTU X22, X10, X19
|
||||
OR X19, X23, X19
|
||||
ADD X19, X11, X11
|
||||
|
||||
SUB $16, X7, X7
|
||||
BGE X7, X8, loop
|
||||
|
||||
tail:
|
||||
BEQ X7, X0, done
|
||||
MOV $1, X15
|
||||
MOV $0, X16
|
||||
ADD X7, X6, X6
|
||||
|
||||
flush_buffer:
|
||||
MOVBU -1(X6), X20
|
||||
SRL $56, X15, X19
|
||||
SLL $8, X16, X23
|
||||
SLL $8, X15, X15
|
||||
OR X19, X23, X16
|
||||
XOR X20, X15
|
||||
SUB $1, X7, X7
|
||||
SUB $1, X6, X6
|
||||
BNE X7, X0, flush_buffer
|
||||
|
||||
ADD X15, X9
|
||||
SLTU X15, X9, X19
|
||||
ADD X16, X10, X22
|
||||
SLTU X16, X22, X23
|
||||
ADD X22, X19, X10
|
||||
SLTU X22, X10, X19
|
||||
OR X23, X19
|
||||
ADD X19, X11
|
||||
|
||||
MOV $16, X7
|
||||
JMP multiply
|
||||
|
||||
done:
|
||||
MOV X9, (0*8)(X5) // h0
|
||||
MOV X10, (1*8)(X5)
|
||||
MOV X11, (2*8)(X5)
|
||||
RET
|
||||
+12
-5
@@ -85,7 +85,8 @@ type certID struct {
|
||||
|
||||
// https://tools.ietf.org/html/rfc2560#section-4.1.1
|
||||
type ocspRequest struct {
|
||||
TBSRequest tbsRequest
|
||||
TBSRequest tbsRequest
|
||||
OptionalSignature asn1.RawValue `asn1:"explicit,tag:0,optional"`
|
||||
}
|
||||
|
||||
type tbsRequest struct {
|
||||
@@ -321,10 +322,10 @@ type Request struct {
|
||||
func (req *Request) Marshal() ([]byte, error) {
|
||||
hashAlg := getOIDFromHashAlgorithm(req.HashAlgorithm)
|
||||
if hashAlg == nil {
|
||||
return nil, errors.New("Unknown hash algorithm")
|
||||
return nil, errors.New("unknown hash algorithm")
|
||||
}
|
||||
return asn1.Marshal(ocspRequest{
|
||||
tbsRequest{
|
||||
TBSRequest: tbsRequest{
|
||||
Version: 0,
|
||||
RequestList: []request{
|
||||
{
|
||||
@@ -418,8 +419,10 @@ func (p ParseError) Error() string {
|
||||
}
|
||||
|
||||
// ParseRequest parses an OCSP request in DER form. It only supports
|
||||
// requests for a single certificate. Signed requests are not supported.
|
||||
// If a request includes a signature, it will result in a ParseError.
|
||||
// requests for a single certificate identifier. If a request includes
|
||||
// multiple certificate identifiers, only the first will be included in
|
||||
// the parsed Request. Signed requests are not supported. If a request
|
||||
// includes a signature, it will result in a ParseError.
|
||||
func ParseRequest(bytes []byte) (*Request, error) {
|
||||
var req ocspRequest
|
||||
rest, err := asn1.Unmarshal(bytes, &req)
|
||||
@@ -430,6 +433,10 @@ func ParseRequest(bytes []byte) (*Request, error) {
|
||||
return nil, ParseError("trailing data in OCSP request")
|
||||
}
|
||||
|
||||
if len(req.OptionalSignature.FullBytes) > 0 {
|
||||
return nil, ParseError("signed OCSP requests are not supported")
|
||||
}
|
||||
|
||||
if len(req.TBSRequest.RequestList) == 0 {
|
||||
return nil, ParseError("OCSP request contains no request body")
|
||||
}
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ func (r *keyring) Unlock(passphrase []byte) error {
|
||||
if !r.locked {
|
||||
return errors.New("agent: not locked")
|
||||
}
|
||||
if 1 != subtle.ConstantTimeCompare(passphrase, r.passphrase) {
|
||||
if subtle.ConstantTimeCompare(passphrase, r.passphrase) != 1 {
|
||||
return fmt.Errorf("agent: incorrect passphrase")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -246,10 +246,10 @@ func setConstraints(key *AddedKey, constraintBytes []byte) error {
|
||||
// on arbitrary inputs; the CRT coefficient recomputation is cubic in
|
||||
// |p| and can consume excessive CPU on oversized keys.
|
||||
func checkRSAKeyParams(N, E, P, Q *big.Int) error {
|
||||
if N.BitLen() > 8192 {
|
||||
if N.BitLen() > 16384 {
|
||||
return errors.New("agent: RSA modulus too large")
|
||||
}
|
||||
if P.BitLen() > 4096 || Q.BitLen() > 4096 {
|
||||
if P.BitLen() > 8192 || Q.BitLen() > 8192 {
|
||||
return errors.New("agent: RSA prime too large")
|
||||
}
|
||||
if E.BitLen() > 24 {
|
||||
|
||||
+10
-5
@@ -229,15 +229,20 @@ func parseCert(in []byte, privAlgo string) (*Certificate, error) {
|
||||
return nil, err
|
||||
}
|
||||
c.Reserved = g.Reserved
|
||||
// Reject a certificate whose signature key is itself a certificate before
|
||||
// parsing it. Certificates signed by certificates are not supported (see
|
||||
// PROTOCOL.certkeys), and rejecting after ParsePublicKey returns would allow
|
||||
// a chain of nested certificates to recurse once per level, exhausting the
|
||||
// goroutine stack.
|
||||
if sigAlgo, _, ok := parseString(g.SignatureKey); !ok {
|
||||
return nil, errShortRead
|
||||
} else if _, ok := certKeyAlgoNames[string(sigAlgo)]; ok {
|
||||
return nil, fmt.Errorf("ssh: the signature key type %q is invalid for certificates", sigAlgo)
|
||||
}
|
||||
k, err := ParsePublicKey(g.SignatureKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// The Type() function is intended to return only certificate key types, but
|
||||
// we use certKeyAlgoNames anyway for safety, to match [Certificate.Type].
|
||||
if _, ok := certKeyAlgoNames[k.Type()]; ok {
|
||||
return nil, fmt.Errorf("ssh: the signature key type %q is invalid for certificates", k.Type())
|
||||
}
|
||||
c.SignatureKey = k
|
||||
c.Signature, rest, ok = parseSignatureBody(g.Signature)
|
||||
if !ok || len(rest) > 0 {
|
||||
|
||||
+42
-25
@@ -216,6 +216,10 @@ type channel struct {
|
||||
// packetPool has a buffer for each extended channel ID to
|
||||
// save allocations during writes.
|
||||
packetPool map[uint32][]byte
|
||||
|
||||
// closeOnce guards close so it is idempotent: closing the internal Go
|
||||
// channels (msg, incomingRequests) more than once would panic.
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
// writePacket sends a packet. If the packet is a channel close, it updates
|
||||
@@ -340,7 +344,18 @@ func (ch *channel) handleData(packet []byte) error {
|
||||
if extended == 1 {
|
||||
ch.extPending.write(data)
|
||||
} else if extended > 0 {
|
||||
// discard other extended data.
|
||||
// RFC 4254, Section 5.2 defines no extended data types other
|
||||
// than stderr (type 1, handled above) and this package provides
|
||||
// no API to read them, so the data is discarded. Credit its
|
||||
// window back immediately: it can never be read, so the
|
||||
// deduction above would otherwise shrink the window permanently.
|
||||
// adjustWindow returns io.EOF if the local side has already
|
||||
// sent a channel close; ignore it like ReadExtended does, since
|
||||
// an error returned here would terminate the mux read loop and
|
||||
// tear down the whole connection.
|
||||
if err := ch.adjustWindow(length); err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
ch.pending.write(data)
|
||||
}
|
||||
@@ -393,17 +408,19 @@ func (c *channel) ReadExtended(data []byte, extended uint32) (n int, err error)
|
||||
}
|
||||
|
||||
func (c *channel) close() {
|
||||
c.pending.eof()
|
||||
c.extPending.eof()
|
||||
close(c.msg)
|
||||
close(c.incomingRequests)
|
||||
c.writeMu.Lock()
|
||||
// This is not necessary for a normal channel teardown, but if
|
||||
// there was another error, it is.
|
||||
c.sentClose = true
|
||||
c.writeMu.Unlock()
|
||||
// Unblock writers.
|
||||
c.remoteWin.close()
|
||||
c.closeOnce.Do(func() {
|
||||
c.pending.eof()
|
||||
c.extPending.eof()
|
||||
close(c.msg)
|
||||
close(c.incomingRequests)
|
||||
c.writeMu.Lock()
|
||||
// This is not necessary for a normal channel teardown, but if
|
||||
// there was another error, it is.
|
||||
c.sentClose = true
|
||||
c.writeMu.Unlock()
|
||||
// Unblock writers.
|
||||
c.remoteWin.close()
|
||||
})
|
||||
}
|
||||
|
||||
// responseMessageReceived is called when a success or failure message is
|
||||
@@ -493,19 +510,20 @@ func (ch *channel) handlePacket(packet []byte) error {
|
||||
|
||||
func (m *mux) newChannel(chanType string, direction channelDirection, extraData []byte) *channel {
|
||||
ch := &channel{
|
||||
remoteWin: window{Cond: newCond()},
|
||||
myWindow: channelWindowSize,
|
||||
pending: newBuffer(),
|
||||
extPending: newBuffer(),
|
||||
direction: direction,
|
||||
incomingRequests: make(chan *Request, chanSize),
|
||||
msg: make(chan interface{}, chanSize),
|
||||
chanType: chanType,
|
||||
extraData: extraData,
|
||||
mux: m,
|
||||
packetPool: make(map[uint32][]byte),
|
||||
remoteWin: window{Cond: newCond()},
|
||||
myWindow: channelWindowSize,
|
||||
maxIncomingPayload: channelMaxPacket,
|
||||
pending: newBuffer(),
|
||||
extPending: newBuffer(),
|
||||
direction: direction,
|
||||
incomingRequests: make(chan *Request, chanSize),
|
||||
msg: make(chan interface{}, chanSize),
|
||||
chanType: chanType,
|
||||
extraData: extraData,
|
||||
mux: m,
|
||||
packetPool: make(map[uint32][]byte),
|
||||
}
|
||||
ch.localId = m.chanList.add(ch)
|
||||
m.chanList.add(ch)
|
||||
return ch
|
||||
}
|
||||
|
||||
@@ -529,7 +547,6 @@ func (ch *channel) Accept() (Channel, <-chan *Request, error) {
|
||||
if ch.decided {
|
||||
return nil, nil, errDecidedAlready
|
||||
}
|
||||
ch.maxIncomingPayload = channelMaxPacket
|
||||
confirm := channelOpenConfirmMsg{
|
||||
PeersID: ch.remoteId,
|
||||
MyID: ch.localId,
|
||||
|
||||
+1
-1
@@ -798,7 +798,7 @@ func (g *gssAPIWithMICCallback) auth(session []byte, user string, c packetConn,
|
||||
return authFailure, nil, fmt.Errorf("GSS-API Error:\n"+
|
||||
"Major Status: %d\n"+
|
||||
"Minor Status: %d\n"+
|
||||
"Error Message: %s\n", userAuthGSSAPIErrorResp.MajorStatus, userAuthGSSAPIErrorResp.MinorStatus,
|
||||
"Error Message: %q\n", userAuthGSSAPIErrorResp.MajorStatus, userAuthGSSAPIErrorResp.MinorStatus,
|
||||
userAuthGSSAPIErrorResp.Message)
|
||||
case msgUserAuthGSSAPIToken:
|
||||
userAuthGSSAPITokenReq := &userAuthGSSAPIToken{}
|
||||
|
||||
+4
-4
@@ -419,7 +419,7 @@ type AlgorithmNegotiationError struct {
|
||||
}
|
||||
|
||||
func (a *AlgorithmNegotiationError) Error() string {
|
||||
return fmt.Sprintf("ssh: no common algorithm for %s; we offered: %v, peer offered: %v",
|
||||
return fmt.Sprintf("ssh: no common algorithm for %s; we offered: %q, peer offered: %q",
|
||||
a.What, a.SupportedAlgorithms, a.RequestedAlgorithms)
|
||||
}
|
||||
|
||||
@@ -544,7 +544,7 @@ func (c *Config) SetDefaults() {
|
||||
if c.Rand == nil {
|
||||
c.Rand = rand.Reader
|
||||
}
|
||||
if c.Ciphers == nil {
|
||||
if len(c.Ciphers) == 0 {
|
||||
c.Ciphers = defaultCiphers
|
||||
}
|
||||
var ciphers []string
|
||||
@@ -556,7 +556,7 @@ func (c *Config) SetDefaults() {
|
||||
}
|
||||
c.Ciphers = ciphers
|
||||
|
||||
if c.KeyExchanges == nil {
|
||||
if len(c.KeyExchanges) == 0 {
|
||||
c.KeyExchanges = defaultKexAlgos
|
||||
}
|
||||
var kexs []string
|
||||
@@ -571,7 +571,7 @@ func (c *Config) SetDefaults() {
|
||||
}
|
||||
c.KeyExchanges = kexs
|
||||
|
||||
if c.MACs == nil {
|
||||
if len(c.MACs) == 0 {
|
||||
c.MACs = defaultMACs
|
||||
}
|
||||
var macs []string
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ type OpenChannelError struct {
|
||||
}
|
||||
|
||||
func (e *OpenChannelError) Error() string {
|
||||
return fmt.Sprintf("ssh: rejected: %s (%s)", e.Reason, e.Message)
|
||||
return fmt.Sprintf("ssh: rejected: %s (%q)", e.Reason, e.Message)
|
||||
}
|
||||
|
||||
// ConnMetadata holds metadata for the connection.
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ func newClientTransport(conn keyingTransport, clientVersion, serverVersion []byt
|
||||
t.remoteAddr = addr
|
||||
t.hostKeyCallback = config.HostKeyCallback
|
||||
t.bannerCallback = config.BannerCallback
|
||||
if config.HostKeyAlgorithms != nil {
|
||||
if len(config.HostKeyAlgorithms) > 0 {
|
||||
t.hostKeyAlgorithms = config.HostKeyAlgorithms
|
||||
} else {
|
||||
t.hostKeyAlgorithms = defaultHostKeyAlgos
|
||||
|
||||
+9
-8
@@ -485,10 +485,11 @@ func parseRSA(in []byte) (out PublicKey, rest []byte, err error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// 8192 bits is also the maximum RSA key size accepted by crypto/tls for
|
||||
// signature verification:
|
||||
// https://github.com/golang/go/blob/69801b25/src/crypto/tls/handshake_client.go#L1096
|
||||
if w.N.BitLen() > 8192 {
|
||||
// 16384 bits is the largest RSA key OpenSSH will generate (ssh-keygen
|
||||
// caps -b at 16384), so it is the practical upper bound for keys seen on
|
||||
// the wire. Rejecting anything larger bounds the CPU spent verifying an
|
||||
// attacker-supplied key and signature, mitigating a denial of service.
|
||||
if w.N.BitLen() > 16384 {
|
||||
return nil, nil, errors.New("ssh: rsa modulus too large")
|
||||
}
|
||||
if w.E.BitLen() > 24 {
|
||||
@@ -1669,13 +1670,13 @@ func parseOpenSSHPrivateKey(key []byte, decrypt openSSHDecryptFunc) (crypto.Priv
|
||||
}
|
||||
|
||||
// Mirror the validation done in parseRSA for public keys: cap the
|
||||
// modulus at the same limit enforced by crypto/tls, reject oversized
|
||||
// or invalid exponents, and additionally bound the prime factors to
|
||||
// modulus at the OpenSSH-generated maximum, reject oversized or
|
||||
// invalid exponents, and additionally bound the prime factors to
|
||||
// avoid the expensive CRT coefficient recomputation in pk.Precompute.
|
||||
if key.N.BitLen() > 8192 {
|
||||
if key.N.BitLen() > 16384 {
|
||||
return nil, errors.New("ssh: rsa modulus too large")
|
||||
}
|
||||
if key.P.BitLen() > 4096 || key.Q.BitLen() > 4096 {
|
||||
if key.P.BitLen() > 8192 || key.Q.BitLen() > 8192 {
|
||||
return nil, errors.New("ssh: rsa prime too large")
|
||||
}
|
||||
if key.E.BitLen() > 24 {
|
||||
|
||||
+1
-10
@@ -44,16 +44,7 @@ type disconnectMsg struct {
|
||||
}
|
||||
|
||||
func (d *disconnectMsg) Error() string {
|
||||
return fmt.Sprintf("ssh: disconnect, reason %d: %q", d.Reason, sanitizeString(d.Message))
|
||||
}
|
||||
|
||||
func sanitizeString(s string) string {
|
||||
return strings.Map(func(r rune) rune {
|
||||
if r == '\t' || (r >= ' ' && r < 0x7f) {
|
||||
return r
|
||||
}
|
||||
return -1
|
||||
}, s)
|
||||
return fmt.Sprintf("ssh: disconnect, reason %d: %q", d.Reason, d.Message)
|
||||
}
|
||||
|
||||
// See RFC 4253, section 7.1.
|
||||
|
||||
+7
-6
@@ -32,18 +32,21 @@ type chanList struct {
|
||||
offset uint32
|
||||
}
|
||||
|
||||
// Assigns a channel ID to the given channel.
|
||||
func (c *chanList) add(ch *channel) uint32 {
|
||||
// add stores the given channel and assigns its localId while holding the
|
||||
// lock, so that getChan can never return a channel whose localId is not yet
|
||||
// initialized.
|
||||
func (c *chanList) add(ch *channel) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
for i := range c.chans {
|
||||
if c.chans[i] == nil {
|
||||
c.chans[i] = ch
|
||||
return uint32(i) + c.offset
|
||||
ch.localId = uint32(i) + c.offset
|
||||
return
|
||||
}
|
||||
}
|
||||
c.chans = append(c.chans, ch)
|
||||
return uint32(len(c.chans)-1) + c.offset
|
||||
ch.localId = uint32(len(c.chans)-1) + c.offset
|
||||
}
|
||||
|
||||
// getChan returns the channel for the given ID.
|
||||
@@ -343,8 +346,6 @@ func (m *mux) OpenChannel(chanType string, extra []byte) (Channel, <-chan *Reque
|
||||
func (m *mux) openChannel(chanType string, extra []byte) (*channel, error) {
|
||||
ch := m.newChannel(chanType, channelOutbound, extra)
|
||||
|
||||
ch.maxIncomingPayload = channelMaxPacket
|
||||
|
||||
open := channelOpenMsg{
|
||||
ChanType: chanType,
|
||||
PeersWindow: ch.myWindow,
|
||||
|
||||
+56
-23
@@ -26,10 +26,16 @@ type Permissions struct {
|
||||
// defines "force-command" (only allow the given command to
|
||||
// execute) and "source-address" (only allow connections from
|
||||
// the given address). The SSH package currently only enforces
|
||||
// the "source-address" critical option. It is up to server
|
||||
// implementations to enforce other critical options, such as
|
||||
// "force-command", by checking them after the SSH handshake
|
||||
// is successful. In general, SSH servers should reject
|
||||
// the "source-address" critical option: it is validated against
|
||||
// the client's remote address whenever it is present in the
|
||||
// Permissions returned by any authentication callback. Its value
|
||||
// is a comma-separated list of IP addresses and CIDR blocks;
|
||||
// consistently with OpenSSH, a connection whose remote address is
|
||||
// not an IP address, such as a Unix domain socket, never matches
|
||||
// the list and is rejected when the option is present. It is up
|
||||
// to server implementations to enforce other critical options,
|
||||
// such as "force-command", by checking them after the SSH
|
||||
// handshake is successful. In general, SSH servers should reject
|
||||
// connections that specify critical options that are unknown
|
||||
// or not supported.
|
||||
CriticalOptions map[string]string
|
||||
@@ -223,7 +229,9 @@ type ServerConfig struct {
|
||||
// Permissions object can be the same object, optionally modified, or a
|
||||
// completely new object. If VerifiedPublicKeyCallback is non-nil,
|
||||
// PublicKeyCallback is not allowed to return a PartialSuccessError, which
|
||||
// can instead be returned by VerifiedPublicKeyCallback.
|
||||
// can instead be returned by VerifiedPublicKeyCallback. The
|
||||
// signatureAlgorithm argument is the format of the signature that was
|
||||
// successfully verified.
|
||||
//
|
||||
// VerifiedPublicKeyCallback does not affect which authentication methods
|
||||
// are included in the list of methods that can be attempted by the client.
|
||||
@@ -442,6 +450,10 @@ func (s *connection) serverHandshake(config *ServerConfig) (*Permissions, error)
|
||||
return perms, err
|
||||
}
|
||||
|
||||
// checkSourceAddress matches addr against sourceAddrs, a comma-separated list
|
||||
// of IP addresses and CIDR blocks. Consistently with OpenSSH, a remote address
|
||||
// that is not IP-based, such as a Unix domain socket, never matches the list
|
||||
// and is rejected.
|
||||
func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
||||
if addr == nil {
|
||||
return errors.New("ssh: no address known for client, but source-address match required")
|
||||
@@ -449,7 +461,7 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
||||
|
||||
tcpAddr, ok := addr.(*net.TCPAddr)
|
||||
if !ok {
|
||||
return fmt.Errorf("ssh: remote address %v is not an TCP address when checking source-address match", addr)
|
||||
return fmt.Errorf("ssh: remote address %v is not a TCP address when checking source-address match", addr)
|
||||
}
|
||||
|
||||
for _, sourceAddr := range strings.Split(sourceAddrs, ",") {
|
||||
@@ -472,6 +484,21 @@ func checkSourceAddress(addr net.Addr, sourceAddrs string) error {
|
||||
return fmt.Errorf("ssh: remote address %v is not allowed because of source-address restriction", addr)
|
||||
}
|
||||
|
||||
// checkSourceAddressCriticalOption enforces the source-address critical
|
||||
// option, if present in perms, as documented in Permissions.CriticalOptions.
|
||||
// A present but empty value matches no address, so it denies authentication,
|
||||
// consistently with OpenSSH, rather than being treated as absent.
|
||||
func checkSourceAddressCriticalOption(addr net.Addr, perms *Permissions) error {
|
||||
if perms == nil {
|
||||
return nil
|
||||
}
|
||||
saco, ok := perms.CriticalOptions[sourceAddressCriticalOption]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return checkSourceAddress(addr, saco)
|
||||
}
|
||||
|
||||
func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, token []byte, s *connection,
|
||||
sessionID []byte, userAuthReq userAuthRequestMsg) (authErr error, perms *Permissions, err error) {
|
||||
gssAPIServer := gssapiConfig.Server
|
||||
@@ -685,7 +712,7 @@ userAuthLoop:
|
||||
}
|
||||
|
||||
if userAuthReq.Service != serviceSSH {
|
||||
return nil, errors.New("ssh: client attempted to negotiate for unknown service: " + userAuthReq.Service)
|
||||
return nil, fmt.Errorf("ssh: client attempted to negotiate for unknown service: %q", userAuthReq.Service)
|
||||
}
|
||||
|
||||
if s.user != userAuthReq.User && partialSuccessReturned {
|
||||
@@ -771,7 +798,8 @@ userAuthLoop:
|
||||
|
||||
pubKey, err := ParsePublicKey(pubKeyData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
authErr = err
|
||||
break
|
||||
}
|
||||
|
||||
candidate, ok := cache.get(s.user, pubKeyData)
|
||||
@@ -784,13 +812,14 @@ userAuthLoop:
|
||||
return nil, errors.New("ssh: invalid library usage: PublicKeyCallback must not return partial success when VerifiedPublicKeyCallback is defined")
|
||||
}
|
||||
|
||||
if (candidate.result == nil || isPartialSuccessError) &&
|
||||
candidate.perms != nil &&
|
||||
candidate.perms.CriticalOptions != nil &&
|
||||
candidate.perms.CriticalOptions[sourceAddressCriticalOption] != "" {
|
||||
if err := checkSourceAddress(
|
||||
s.RemoteAddr(),
|
||||
candidate.perms.CriticalOptions[sourceAddressCriticalOption]); err != nil {
|
||||
// This check is authoritative for the Permissions returned by
|
||||
// PublicKeyCallback: the check at the end of the auth loop sees
|
||||
// the final Permissions, which VerifiedPublicKeyCallback may
|
||||
// have replaced, and is skipped on partial success. It also
|
||||
// makes public key queries fail before the client signs when
|
||||
// PublicKeyCallback supplies the restriction.
|
||||
if candidate.result == nil || isPartialSuccessError {
|
||||
if err := checkSourceAddressCriticalOption(s.RemoteAddr(), candidate.perms); err != nil {
|
||||
candidate.result = err
|
||||
}
|
||||
}
|
||||
@@ -864,14 +893,7 @@ userAuthLoop:
|
||||
// Only call VerifiedPublicKeyCallback after the key has been accepted
|
||||
// and successfully verified. If authErr is non-nil, the key is not
|
||||
// considered verified and the callback must not run.
|
||||
perms, authErr = config.VerifiedPublicKeyCallback(s, pubKey, perms, algo)
|
||||
}
|
||||
if authErr == nil && perms != nil && perms.CriticalOptions != nil {
|
||||
if saco := perms.CriticalOptions[sourceAddressCriticalOption]; saco != "" {
|
||||
if err := checkSourceAddress(s.RemoteAddr(), saco); err != nil {
|
||||
authErr = err
|
||||
}
|
||||
}
|
||||
perms, authErr = config.VerifiedPublicKeyCallback(s, pubKey, perms, sig.Format)
|
||||
}
|
||||
}
|
||||
case "gssapi-with-mic":
|
||||
@@ -925,6 +947,17 @@ userAuthLoop:
|
||||
authErr = fmt.Errorf("ssh: unknown method %q", userAuthReq.Method)
|
||||
}
|
||||
|
||||
// The source-address critical option is enforced on the Permissions
|
||||
// returned by any authentication callback. Permissions returned
|
||||
// together with a PartialSuccessError skip this check: that is safe
|
||||
// because they are required to be nil, as enforced in the partial
|
||||
// success handling below.
|
||||
if authErr == nil {
|
||||
if err := checkSourceAddressCriticalOption(s.RemoteAddr(), perms); err != nil {
|
||||
authErr = err
|
||||
}
|
||||
}
|
||||
|
||||
authErrs = append(authErrs, authErr)
|
||||
|
||||
if config.AuthLogCallback != nil {
|
||||
|
||||
+10
-6
@@ -118,24 +118,28 @@ func parseGSSAPIPayload(payload []byte) (*userAuthRequestGSSAPI, error) {
|
||||
OIDS: make([]asn1.ObjectIdentifier, n),
|
||||
}
|
||||
for i := 0; i < int(n); i++ {
|
||||
var (
|
||||
desiredMech []byte
|
||||
err error
|
||||
)
|
||||
var desiredMech []byte
|
||||
desiredMech, rest, ok = parseString(rest)
|
||||
if !ok {
|
||||
return nil, errors.New("parse string failed")
|
||||
}
|
||||
if rest, err = asn1.Unmarshal(desiredMech, &s.OIDS[i]); err != nil {
|
||||
trailing, err := asn1.Unmarshal(desiredMech, &s.OIDS[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(trailing) != 0 {
|
||||
return nil, errors.New("trailing bytes after OID")
|
||||
}
|
||||
}
|
||||
if len(rest) != 0 {
|
||||
return nil, errors.New("trailing bytes after mechanisms")
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// See RFC 4462 section 3.6.
|
||||
func buildMIC(sessionID string, username string, service string, authMethod string) []byte {
|
||||
out := make([]byte, 0, 0)
|
||||
out := make([]byte, 0)
|
||||
out = appendString(out, sessionID)
|
||||
out = append(out, msgUserAuthRequest)
|
||||
out = appendString(out, username)
|
||||
|
||||
+2
@@ -58,6 +58,7 @@ func (c *Client) dialStreamLocal(socketPath string) (Channel, error) {
|
||||
return nil, err
|
||||
}
|
||||
go DiscardRequests(in)
|
||||
go io.Copy(io.Discard, ch.Stderr())
|
||||
return ch, err
|
||||
}
|
||||
|
||||
@@ -79,6 +80,7 @@ func (l *unixListener) Accept() (net.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
go DiscardRequests(incoming)
|
||||
go io.Copy(io.Discard, ch.Stderr())
|
||||
|
||||
return &chanConn{
|
||||
Channel: ch,
|
||||
|
||||
+2
@@ -332,6 +332,7 @@ func (l *tcpListener) Accept() (net.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
go DiscardRequests(incoming)
|
||||
go io.Copy(io.Discard, ch.Stderr())
|
||||
|
||||
return &chanConn{
|
||||
Channel: ch,
|
||||
@@ -495,6 +496,7 @@ func (c *Client) dial(laddr string, lport int, raddr string, rport int) (Channel
|
||||
return nil, err
|
||||
}
|
||||
go DiscardRequests(in)
|
||||
go io.Copy(io.Discard, ch.Stderr())
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -39,7 +39,6 @@ func NewEncoder(w io.Writer) *Encoder {
|
||||
tableSizeUpdate: false,
|
||||
w: w,
|
||||
}
|
||||
e.dynTab.table.init()
|
||||
e.dynTab.setMaxSize(initialHeaderTableSize)
|
||||
return e
|
||||
}
|
||||
|
||||
-1
@@ -105,7 +105,6 @@ func NewDecoder(maxDynamicTableSize uint32, emitFunc func(f HeaderField)) *Decod
|
||||
emitEnabled: true,
|
||||
firstField: true,
|
||||
}
|
||||
d.dynTab.table.init()
|
||||
d.dynTab.allowedMaxSize = maxDynamicTableSize
|
||||
d.dynTab.setMaxSize(maxDynamicTableSize)
|
||||
return d
|
||||
|
||||
+37
-14
@@ -31,10 +31,18 @@ type headerFieldTable struct {
|
||||
|
||||
// byName maps a HeaderField name to the unique id of the newest entry with
|
||||
// the same name. See above for a definition of "unique id".
|
||||
//
|
||||
// byName and byNameValue are used only by search, which is only called
|
||||
// for tables used by encoders. For tables used only by decoders, the
|
||||
// maps are never built, as a memory optimization for servers with many
|
||||
// mostly-idle connections, each pinning a dynamic table. The maps are
|
||||
// built lazily by the first search call and are nil until then. The two
|
||||
// maps are always both nil or both non-nil.
|
||||
byName map[string]uint64
|
||||
|
||||
// byNameValue maps a HeaderField name/value pair to the unique id of the newest
|
||||
// entry with the same name and value. See above for a definition of "unique id".
|
||||
// See byName for when this map is non-nil.
|
||||
byNameValue map[pairNameValue]uint64
|
||||
}
|
||||
|
||||
@@ -42,9 +50,17 @@ type pairNameValue struct {
|
||||
name, value string
|
||||
}
|
||||
|
||||
func (t *headerFieldTable) init() {
|
||||
t.byName = make(map[string]uint64)
|
||||
t.byNameValue = make(map[pairNameValue]uint64)
|
||||
// buildMaps initializes byName and byNameValue from ents.
|
||||
func (t *headerFieldTable) buildMaps() {
|
||||
t.byName = make(map[string]uint64, len(t.ents))
|
||||
t.byNameValue = make(map[pairNameValue]uint64, len(t.ents))
|
||||
for k, f := range t.ents {
|
||||
// Map to the newest matching entry: later (newer) entries
|
||||
// overwrite earlier ones, matching addEntry's behavior.
|
||||
id := t.evictCount + uint64(k) + 1
|
||||
t.byName[f.Name] = id
|
||||
t.byNameValue[pairNameValue{f.Name, f.Value}] = id
|
||||
}
|
||||
}
|
||||
|
||||
// len reports the number of entries in the table.
|
||||
@@ -54,9 +70,11 @@ func (t *headerFieldTable) len() int {
|
||||
|
||||
// addEntry adds a new entry.
|
||||
func (t *headerFieldTable) addEntry(f HeaderField) {
|
||||
id := uint64(t.len()) + t.evictCount + 1
|
||||
t.byName[f.Name] = id
|
||||
t.byNameValue[pairNameValue{f.Name, f.Value}] = id
|
||||
if t.byName != nil {
|
||||
id := uint64(t.len()) + t.evictCount + 1
|
||||
t.byName[f.Name] = id
|
||||
t.byNameValue[pairNameValue{f.Name, f.Value}] = id
|
||||
}
|
||||
t.ents = append(t.ents, f)
|
||||
}
|
||||
|
||||
@@ -65,14 +83,16 @@ func (t *headerFieldTable) evictOldest(n int) {
|
||||
if n > t.len() {
|
||||
panic(fmt.Sprintf("evictOldest(%v) on table with %v entries", n, t.len()))
|
||||
}
|
||||
for k := 0; k < n; k++ {
|
||||
f := t.ents[k]
|
||||
id := t.evictCount + uint64(k) + 1
|
||||
if t.byName[f.Name] == id {
|
||||
delete(t.byName, f.Name)
|
||||
}
|
||||
if p := (pairNameValue{f.Name, f.Value}); t.byNameValue[p] == id {
|
||||
delete(t.byNameValue, p)
|
||||
if t.byName != nil {
|
||||
for k := 0; k < n; k++ {
|
||||
f := t.ents[k]
|
||||
id := t.evictCount + uint64(k) + 1
|
||||
if t.byName[f.Name] == id {
|
||||
delete(t.byName, f.Name)
|
||||
}
|
||||
if p := (pairNameValue{f.Name, f.Value}); t.byNameValue[p] == id {
|
||||
delete(t.byNameValue, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
copy(t.ents, t.ents[n:])
|
||||
@@ -100,6 +120,9 @@ func (t *headerFieldTable) evictOldest(n int) {
|
||||
//
|
||||
// See Section 2.3.3.
|
||||
func (t *headerFieldTable) search(f HeaderField) (i uint64, nameValueMatch bool) {
|
||||
if t.byName == nil {
|
||||
t.buildMaps()
|
||||
}
|
||||
if !f.Sensitive {
|
||||
if id := t.byNameValue[pairNameValue{f.Name, f.Value}]; id != 0 {
|
||||
return t.idToIndex(id), true
|
||||
|
||||
+32
-19
@@ -237,32 +237,40 @@ type ClientConn struct {
|
||||
}
|
||||
|
||||
func (cc *ClientConn) roundTrip(req *http.Request) (*http.Response, error) {
|
||||
err := func() error {
|
||||
haveReservation, err := func() (bool, error) {
|
||||
cc.mu.Lock()
|
||||
defer cc.mu.Unlock()
|
||||
if cc.doNotReuse {
|
||||
return errClientConnUnusable
|
||||
}
|
||||
cc.roundTrips++
|
||||
if cc.reserved > 0 {
|
||||
// We've already reserved a concurrency slot for this request.
|
||||
cc.reserved--
|
||||
} else if cc.cc.Reserve() != nil {
|
||||
// We don't seem to have an available concurrency slot,
|
||||
// so bump the pending count (requests waiting for a slot).
|
||||
cc.pending++
|
||||
return false, errClientConnUnusable
|
||||
}
|
||||
|
||||
// ClientConn.Shutdown will not shut down the conn while
|
||||
// cc.starting > 0 or cc.cc.InFlight() > 0.
|
||||
//
|
||||
// The starting state covers the gap between us deciding to
|
||||
// start sending the request, and actually sending it.
|
||||
cc.starting++
|
||||
return nil
|
||||
|
||||
cc.roundTrips++
|
||||
if cc.reserved == 0 {
|
||||
// We do not have a concurrency slot reserved for this request.
|
||||
return false, nil
|
||||
}
|
||||
cc.reserved--
|
||||
return true, nil
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If we have no reservation, try to acquire one.
|
||||
// (This must be done without cc.mu held, since Reserve may call back to the state hook.)
|
||||
if !haveReservation && cc.cc.Reserve() != nil {
|
||||
// We could not acquire a concurrency slot, so bump the pending count
|
||||
// (requests waiting for a slot).
|
||||
cc.mu.Lock()
|
||||
cc.pending++
|
||||
cc.mu.Unlock()
|
||||
}
|
||||
resp, err := cc.cc.RoundTrip(req)
|
||||
cc.mu.Lock()
|
||||
cc.starting--
|
||||
@@ -293,16 +301,21 @@ func (cc *ClientConn) ping(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (cc *ClientConn) reserveNewRequest() bool {
|
||||
cc.mu.Lock()
|
||||
defer cc.mu.Unlock()
|
||||
if cc.doNotReuse {
|
||||
return false
|
||||
}
|
||||
if err := cc.cc.Reserve(); err != nil {
|
||||
return false
|
||||
}
|
||||
cc.reserved++
|
||||
return true
|
||||
reserved := true
|
||||
cc.mu.Lock()
|
||||
if cc.doNotReuse {
|
||||
reserved = false
|
||||
} else {
|
||||
cc.reserved++
|
||||
}
|
||||
cc.mu.Unlock()
|
||||
if !reserved {
|
||||
cc.cc.Release()
|
||||
}
|
||||
return reserved
|
||||
}
|
||||
|
||||
func (cc *ClientConn) setDoNotReuse() {
|
||||
|
||||
+41
@@ -10,6 +10,7 @@ import (
|
||||
"go/token"
|
||||
"iter"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/tools/go/ast/edge"
|
||||
)
|
||||
@@ -110,6 +111,46 @@ func (c Cursor) String() string {
|
||||
return reflect.TypeOf(c.Node()).String()
|
||||
}
|
||||
|
||||
// GoString returns a string describing the cursor's path from the
|
||||
// root, if any.
|
||||
func (c Cursor) GoString() string {
|
||||
if !c.Valid() {
|
||||
return "(invalid)"
|
||||
}
|
||||
if c.index < 0 {
|
||||
return "(root)"
|
||||
}
|
||||
// e.g "File.Decls[1].(*ast.GenDecl).Specs[0].(*ast.TypeSpec)"
|
||||
//
|
||||
// In hindsight even the File node should have reported a
|
||||
// virtual ParentEdge of (Root_Files, i) where i is the index
|
||||
// among the files passed to NewInspector. Then the path would
|
||||
// read "(root).Files[i]", etc; but we missed the boat.
|
||||
var buf strings.Builder
|
||||
buf.WriteString("File")
|
||||
var visit func(Cursor)
|
||||
visit = func(c Cursor) {
|
||||
ek, idx := c.ParentEdge()
|
||||
if ek == edge.Invalid {
|
||||
return // File
|
||||
}
|
||||
visit(c.Parent())
|
||||
fmt.Fprintf(&buf, ".%s", ek.FieldName())
|
||||
if idx >= 0 {
|
||||
fmt.Fprintf(&buf, "[%d]", idx)
|
||||
}
|
||||
ftype := ek.FieldType()
|
||||
if idx >= 0 {
|
||||
ftype = ftype.Elem() // []T -> T
|
||||
}
|
||||
if ftype.Kind() == reflect.Interface {
|
||||
fmt.Fprintf(&buf, ".(%T)", c.Node())
|
||||
}
|
||||
}
|
||||
visit(c)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// indices return the [start, end) half-open interval of event indices.
|
||||
func (c Cursor) indices() (int32, int32) {
|
||||
if c.index < 0 {
|
||||
|
||||
+4
-29
@@ -5,11 +5,11 @@
|
||||
package packages
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"iter"
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"golang.org/x/tools/internal/moremaps"
|
||||
)
|
||||
|
||||
// Visit visits all the packages in the import graph whose roots are
|
||||
@@ -40,7 +40,7 @@ func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package)) {
|
||||
seen[pkg] = true
|
||||
|
||||
if pre == nil || pre(pkg) {
|
||||
for _, imp := range sorted(pkg.Imports) { // for determinism
|
||||
for _, imp := range moremaps.Sorted(pkg.Imports) { // for determinism
|
||||
visit(imp)
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func Postorder(pkgs []*Package) iter.Seq[*Package] {
|
||||
visit = func(pkg *Package) bool {
|
||||
if !seen[pkg] {
|
||||
seen[pkg] = true
|
||||
for _, imp := range sorted(pkg.Imports) { // for determinism
|
||||
for _, imp := range moremaps.Sorted(pkg.Imports) { // for determinism
|
||||
if !visit(imp) {
|
||||
return false
|
||||
}
|
||||
@@ -106,28 +106,3 @@ func Postorder(pkgs []*Package) iter.Seq[*Package] {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -- copied from golang.org.x/tools/gopls/internal/util/moremaps --
|
||||
|
||||
// sorted returns an iterator over the entries of m in key order.
|
||||
func sorted[M ~map[K]V, K cmp.Ordered, V any](m M) iter.Seq2[K, V] {
|
||||
// TODO(adonovan): use maps.Sorted if proposal #68598 is accepted.
|
||||
return func(yield func(K, V) bool) {
|
||||
keys := keySlice(m)
|
||||
slices.Sort(keys)
|
||||
for _, k := range keys {
|
||||
if !yield(k, m[k]) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// KeySlice returns the keys of the map M, like slices.Collect(maps.Keys(m)).
|
||||
func keySlice[M ~map[K]V, K comparable, V any](m M) []K {
|
||||
r := make([]K, 0, len(m))
|
||||
for k := range m {
|
||||
r = append(r, k)
|
||||
}
|
||||
return r
|
||||
}
|
||||
-86
@@ -1,86 +0,0 @@
|
||||
// Copyright 2018 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 typeutil
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/types"
|
||||
_ "unsafe" // for linkname
|
||||
)
|
||||
|
||||
// Callee returns the named target of a function call, if any:
|
||||
// a function, method, builtin, or variable.
|
||||
// It returns nil for a T(x) conversion.
|
||||
//
|
||||
// Functions and methods may potentially have type parameters.
|
||||
//
|
||||
// Note: for calls of instantiated functions and methods, Callee returns
|
||||
// the corresponding generic function or method on the generic type.
|
||||
func Callee(info *types.Info, call *ast.CallExpr) types.Object {
|
||||
obj := info.Uses[usedIdent(info, call.Fun)]
|
||||
if obj == nil {
|
||||
return nil
|
||||
}
|
||||
if _, ok := obj.(*types.TypeName); ok {
|
||||
return nil
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// StaticCallee returns the target (function or method) of a static function
|
||||
// call, if any. It returns nil for calls to builtins.
|
||||
//
|
||||
// Note: for calls of instantiated functions and methods, StaticCallee returns
|
||||
// the corresponding generic function or method on the generic type.
|
||||
func StaticCallee(info *types.Info, call *ast.CallExpr) *types.Func {
|
||||
obj := info.Uses[usedIdent(info, call.Fun)]
|
||||
fn, _ := obj.(*types.Func)
|
||||
if fn == nil || interfaceMethod(fn) {
|
||||
return nil
|
||||
}
|
||||
return fn
|
||||
}
|
||||
|
||||
// usedIdent is the implementation of [internal/typesinternal.UsedIdent].
|
||||
// It returns the identifier associated with e.
|
||||
// See typesinternal.UsedIdent for a fuller description.
|
||||
// This function should live in typesinternal, but cannot because it would
|
||||
// create an import cycle.
|
||||
//
|
||||
//go:linkname usedIdent golang.org/x/tools/go/types/typeutil.usedIdent
|
||||
func usedIdent(info *types.Info, e ast.Expr) *ast.Ident {
|
||||
if info.Types == nil || info.Uses == nil {
|
||||
panic("one of info.Types or info.Uses is nil; both must be populated")
|
||||
}
|
||||
// Look through type instantiation if necessary.
|
||||
switch d := ast.Unparen(e).(type) {
|
||||
case *ast.IndexExpr:
|
||||
if info.Types[d.Index].IsType() {
|
||||
e = d.X
|
||||
}
|
||||
case *ast.IndexListExpr:
|
||||
e = d.X
|
||||
}
|
||||
|
||||
switch e := ast.Unparen(e).(type) {
|
||||
// info.Uses always has the object we want, even for selector expressions.
|
||||
// We don't need info.Selections.
|
||||
// See go/types/recording.go:recordSelection.
|
||||
case *ast.Ident:
|
||||
return e
|
||||
case *ast.SelectorExpr:
|
||||
return e.Sel
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// interfaceMethod reports whether its argument is a method of an interface.
|
||||
// This function should live in typesinternal, but cannot because it would create an import cycle.
|
||||
//
|
||||
//go:linkname interfaceMethod golang.org/x/tools/go/types/typeutil.interfaceMethod
|
||||
func interfaceMethod(f *types.Func) bool {
|
||||
recv := f.Signature().Recv()
|
||||
return recv != nil && types.IsInterface(recv.Type())
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
// Copyright 2014 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 typeutil
|
||||
|
||||
import "go/types"
|
||||
|
||||
// Dependencies returns all dependencies of the specified packages.
|
||||
//
|
||||
// Dependent packages appear in topological order: if package P imports
|
||||
// package Q, Q appears earlier than P in the result.
|
||||
// The algorithm follows import statements in the order they
|
||||
// appear in the source code, so the result is a total order.
|
||||
func Dependencies(pkgs ...*types.Package) []*types.Package {
|
||||
var result []*types.Package
|
||||
seen := make(map[*types.Package]bool)
|
||||
var visit func(pkgs []*types.Package)
|
||||
visit = func(pkgs []*types.Package) {
|
||||
for _, p := range pkgs {
|
||||
if !seen[p] {
|
||||
seen[p] = true
|
||||
visit(p.Imports())
|
||||
result = append(result, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
visit(pkgs)
|
||||
return result
|
||||
}
|
||||
-459
@@ -1,459 +0,0 @@
|
||||
// Copyright 2014 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 typeutil defines various utilities for types, such as [Map],
|
||||
// a hash table that maps [types.Type] to any value.
|
||||
package typeutil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"go/types"
|
||||
"hash/maphash"
|
||||
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
)
|
||||
|
||||
// Map is a hash-table-based mapping from types (types.Type) to
|
||||
// arbitrary values. The concrete types that implement
|
||||
// the Type interface are pointers. Since they are not canonicalized,
|
||||
// == cannot be used to check for equivalence, and thus we cannot
|
||||
// simply use a Go map.
|
||||
//
|
||||
// Just as with map[K]V, a nil *Map is a valid empty map.
|
||||
//
|
||||
// Read-only map operations ([Map.At], [Map.Len], and so on) may
|
||||
// safely be called concurrently.
|
||||
//
|
||||
// TODO(adonovan): deprecate in favor of https://go.dev/issues/69420
|
||||
// and 69559, if the latter proposals for a generic hash-map type and
|
||||
// a types.Hash function are accepted.
|
||||
type Map struct {
|
||||
table map[uint32][]entry // maps hash to bucket; entry.key==nil means unused
|
||||
length int // number of map entries
|
||||
}
|
||||
|
||||
// entry is an entry (key/value association) in a hash bucket.
|
||||
type entry struct {
|
||||
key types.Type
|
||||
value any
|
||||
}
|
||||
|
||||
// SetHasher has no effect.
|
||||
//
|
||||
// It is a relic of an optimization that is no longer profitable. Do
|
||||
// not use [Hasher], [MakeHasher], or [SetHasher] in new code.
|
||||
func (m *Map) SetHasher(Hasher) {}
|
||||
|
||||
// Delete removes the entry with the given key, if any.
|
||||
// It returns true if the entry was found.
|
||||
func (m *Map) Delete(key types.Type) bool {
|
||||
if m != nil && m.table != nil {
|
||||
hash := hash(key)
|
||||
bucket := m.table[hash]
|
||||
for i, e := range bucket {
|
||||
if e.key != nil && types.Identical(key, e.key) {
|
||||
// We can't compact the bucket as it
|
||||
// would disturb iterators.
|
||||
bucket[i] = entry{}
|
||||
m.length--
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// At returns the map entry for the given key.
|
||||
// The result is nil if the entry is not present.
|
||||
func (m *Map) At(key types.Type) any {
|
||||
if m != nil && m.table != nil {
|
||||
for _, e := range m.table[hash(key)] {
|
||||
if e.key != nil && types.Identical(key, e.key) {
|
||||
return e.value
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Set sets the map entry for key to val,
|
||||
// and returns the previous entry, if any.
|
||||
func (m *Map) Set(key types.Type, value any) (prev any) {
|
||||
if m.table != nil {
|
||||
hash := hash(key)
|
||||
bucket := m.table[hash]
|
||||
var hole *entry
|
||||
for i, e := range bucket {
|
||||
if e.key == nil {
|
||||
hole = &bucket[i]
|
||||
} else if types.Identical(key, e.key) {
|
||||
prev = e.value
|
||||
bucket[i].value = value
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if hole != nil {
|
||||
*hole = entry{key, value} // overwrite deleted entry
|
||||
} else {
|
||||
m.table[hash] = append(bucket, entry{key, value})
|
||||
}
|
||||
} else {
|
||||
hash := hash(key)
|
||||
m.table = map[uint32][]entry{hash: {entry{key, value}}}
|
||||
}
|
||||
|
||||
m.length++
|
||||
return
|
||||
}
|
||||
|
||||
// Len returns the number of map entries.
|
||||
func (m *Map) Len() int {
|
||||
if m != nil {
|
||||
return m.length
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Iterate calls function f on each entry in the map in unspecified order.
|
||||
//
|
||||
// If f should mutate the map, Iterate provides the same guarantees as
|
||||
// Go maps: if f deletes a map entry that Iterate has not yet reached,
|
||||
// f will not be invoked for it, but if f inserts a map entry that
|
||||
// Iterate has not yet reached, whether or not f will be invoked for
|
||||
// it is unspecified.
|
||||
func (m *Map) Iterate(f func(key types.Type, value any)) {
|
||||
if m != nil {
|
||||
for _, bucket := range m.table {
|
||||
for _, e := range bucket {
|
||||
if e.key != nil {
|
||||
f(e.key, e.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keys returns a new slice containing the set of map keys.
|
||||
// The order is unspecified.
|
||||
func (m *Map) Keys() []types.Type {
|
||||
keys := make([]types.Type, 0, m.Len())
|
||||
m.Iterate(func(key types.Type, _ any) {
|
||||
keys = append(keys, key)
|
||||
})
|
||||
return keys
|
||||
}
|
||||
|
||||
func (m *Map) toString(values bool) string {
|
||||
if m == nil {
|
||||
return "{}"
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
fmt.Fprint(&buf, "{")
|
||||
sep := ""
|
||||
m.Iterate(func(key types.Type, value any) {
|
||||
fmt.Fprint(&buf, sep)
|
||||
sep = ", "
|
||||
fmt.Fprint(&buf, key)
|
||||
if values {
|
||||
fmt.Fprintf(&buf, ": %q", value)
|
||||
}
|
||||
})
|
||||
fmt.Fprint(&buf, "}")
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// String returns a string representation of the map's entries.
|
||||
// Values are printed using fmt.Sprintf("%v", v).
|
||||
// Order is unspecified.
|
||||
func (m *Map) String() string {
|
||||
return m.toString(true)
|
||||
}
|
||||
|
||||
// KeysString returns a string representation of the map's key set.
|
||||
// Order is unspecified.
|
||||
func (m *Map) KeysString() string {
|
||||
return m.toString(false)
|
||||
}
|
||||
|
||||
// -- Hasher --
|
||||
|
||||
// hash returns the hash of type t.
|
||||
// TODO(adonovan): replace by types.Hash when Go proposal #69420 is accepted.
|
||||
func hash(t types.Type) uint32 {
|
||||
return theHasher.Hash(t)
|
||||
}
|
||||
|
||||
// A Hasher provides a [Hasher.Hash] method to map a type to its hash value.
|
||||
// Hashers are stateless, and all are equivalent.
|
||||
type Hasher struct{}
|
||||
|
||||
var theHasher Hasher
|
||||
|
||||
// MakeHasher returns Hasher{}.
|
||||
// Hashers are stateless; all are equivalent.
|
||||
func MakeHasher() Hasher { return theHasher }
|
||||
|
||||
// Hash computes a hash value for the given type t such that
|
||||
// Identical(t, t') => Hash(t) == Hash(t').
|
||||
func (h Hasher) Hash(t types.Type) uint32 {
|
||||
return hasher{inGenericSig: false}.hash(t)
|
||||
}
|
||||
|
||||
// hasher holds the state of a single Hash traversal: whether we are
|
||||
// inside the signature of a generic function; this is used to
|
||||
// optimize [hasher.hashTypeParam].
|
||||
type hasher struct{ inGenericSig bool }
|
||||
|
||||
// hashString computes the Fowler–Noll–Vo hash of s.
|
||||
func hashString(s string) uint32 {
|
||||
var h uint32
|
||||
for i := 0; i < len(s); i++ {
|
||||
h ^= uint32(s[i])
|
||||
h *= 16777619
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// hash computes the hash of t.
|
||||
func (h hasher) hash(t types.Type) uint32 {
|
||||
// See Identical for rationale.
|
||||
switch t := t.(type) {
|
||||
case *types.Basic:
|
||||
return uint32(t.Kind())
|
||||
|
||||
case *types.Alias:
|
||||
return h.hash(types.Unalias(t))
|
||||
|
||||
case *types.Array:
|
||||
return 9043 + 2*uint32(t.Len()) + 3*h.hash(t.Elem())
|
||||
|
||||
case *types.Slice:
|
||||
return 9049 + 2*h.hash(t.Elem())
|
||||
|
||||
case *types.Struct:
|
||||
var hash uint32 = 9059
|
||||
for i, n := 0, t.NumFields(); i < n; i++ {
|
||||
f := t.Field(i)
|
||||
if f.Anonymous() {
|
||||
hash += 8861
|
||||
}
|
||||
hash += hashString(t.Tag(i))
|
||||
hash += hashString(f.Name()) // (ignore f.Pkg)
|
||||
hash += h.hash(f.Type())
|
||||
}
|
||||
return hash
|
||||
|
||||
case *types.Pointer:
|
||||
return 9067 + 2*h.hash(t.Elem())
|
||||
|
||||
case *types.Signature:
|
||||
var hash uint32 = 9091
|
||||
if t.Variadic() {
|
||||
hash *= 8863
|
||||
}
|
||||
|
||||
tparams := t.TypeParams()
|
||||
if n := tparams.Len(); n > 0 {
|
||||
h.inGenericSig = true // affects constraints, params, and results
|
||||
|
||||
for i := range n {
|
||||
tparam := tparams.At(i)
|
||||
hash += 7 * h.hash(tparam.Constraint())
|
||||
}
|
||||
}
|
||||
|
||||
return hash + 3*h.hashTuple(t.Params()) + 5*h.hashTuple(t.Results())
|
||||
|
||||
case *types.Union:
|
||||
return h.hashUnion(t)
|
||||
|
||||
case *types.Interface:
|
||||
// Interfaces are identical if they have the same set of methods, with
|
||||
// identical names and types, and they have the same set of type
|
||||
// restrictions. See go/types.identical for more details.
|
||||
var hash uint32 = 9103
|
||||
|
||||
// Hash methods.
|
||||
for i, n := 0, t.NumMethods(); i < n; i++ {
|
||||
// Method order is not significant.
|
||||
// Ignore m.Pkg().
|
||||
m := t.Method(i)
|
||||
// Use shallow hash on method signature to
|
||||
// avoid anonymous interface cycles.
|
||||
hash += 3*hashString(m.Name()) + 5*h.shallowHash(m.Type())
|
||||
}
|
||||
|
||||
// Hash type restrictions.
|
||||
terms, err := typeparams.InterfaceTermSet(t)
|
||||
// if err != nil t has invalid type restrictions.
|
||||
if err == nil {
|
||||
hash += h.hashTermSet(terms)
|
||||
}
|
||||
|
||||
return hash
|
||||
|
||||
case *types.Map:
|
||||
return 9109 + 2*h.hash(t.Key()) + 3*h.hash(t.Elem())
|
||||
|
||||
case *types.Chan:
|
||||
return 9127 + 2*uint32(t.Dir()) + 3*h.hash(t.Elem())
|
||||
|
||||
case *types.Named:
|
||||
hash := h.hashTypeName(t.Obj())
|
||||
targs := t.TypeArgs()
|
||||
for targ := range targs.Types() {
|
||||
hash += 2 * h.hash(targ)
|
||||
}
|
||||
return hash
|
||||
|
||||
case *types.TypeParam:
|
||||
return h.hashTypeParam(t)
|
||||
|
||||
case *types.Tuple:
|
||||
return h.hashTuple(t)
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("%T: %v", t, t))
|
||||
}
|
||||
|
||||
func (h hasher) hashTuple(tuple *types.Tuple) uint32 {
|
||||
// See go/types.identicalTypes for rationale.
|
||||
n := tuple.Len()
|
||||
hash := 9137 + 2*uint32(n)
|
||||
for i := range n {
|
||||
hash += 3 * h.hash(tuple.At(i).Type())
|
||||
}
|
||||
return hash
|
||||
}
|
||||
|
||||
func (h hasher) hashUnion(t *types.Union) uint32 {
|
||||
// Hash type restrictions.
|
||||
terms, err := typeparams.UnionTermSet(t)
|
||||
// if err != nil t has invalid type restrictions. Fall back on a non-zero
|
||||
// hash.
|
||||
if err != nil {
|
||||
return 9151
|
||||
}
|
||||
return h.hashTermSet(terms)
|
||||
}
|
||||
|
||||
func (h hasher) hashTermSet(terms []*types.Term) uint32 {
|
||||
hash := 9157 + 2*uint32(len(terms))
|
||||
for _, term := range terms {
|
||||
// term order is not significant.
|
||||
termHash := h.hash(term.Type())
|
||||
if term.Tilde() {
|
||||
termHash *= 9161
|
||||
}
|
||||
hash += 3 * termHash
|
||||
}
|
||||
return hash
|
||||
}
|
||||
|
||||
// hashTypeParam returns the hash of a type parameter.
|
||||
func (h hasher) hashTypeParam(t *types.TypeParam) uint32 {
|
||||
// Within the signature of a generic function, TypeParams are
|
||||
// identical if they have the same index and constraint, so we
|
||||
// hash them based on index.
|
||||
//
|
||||
// When we are outside a generic function, free TypeParams are
|
||||
// identical iff they are the same object, so we can use a
|
||||
// more discriminating hash consistent with object identity.
|
||||
// This optimization saves [Map] about 4% when hashing all the
|
||||
// types.Info.Types in the forward closure of net/http.
|
||||
if !h.inGenericSig {
|
||||
// Optimization: outside a generic function signature,
|
||||
// use a more discrimating hash consistent with object identity.
|
||||
return h.hashTypeName(t.Obj())
|
||||
}
|
||||
return 9173 + 3*uint32(t.Index())
|
||||
}
|
||||
|
||||
var theSeed = maphash.MakeSeed()
|
||||
|
||||
// hashTypeName hashes the pointer of tname.
|
||||
func (hasher) hashTypeName(tname *types.TypeName) uint32 {
|
||||
// Since types.Identical uses == to compare TypeNames,
|
||||
// the Hash function uses maphash.Comparable.
|
||||
hash := maphash.Comparable(theSeed, tname)
|
||||
return uint32(hash ^ (hash >> 32))
|
||||
}
|
||||
|
||||
// shallowHash computes a hash of t without looking at any of its
|
||||
// element Types, to avoid potential anonymous cycles in the types of
|
||||
// interface methods.
|
||||
//
|
||||
// When an unnamed non-empty interface type appears anywhere among the
|
||||
// arguments or results of an interface method, there is a potential
|
||||
// for endless recursion. Consider:
|
||||
//
|
||||
// type X interface { m() []*interface { X } }
|
||||
//
|
||||
// The problem is that the Methods of the interface in m's result type
|
||||
// include m itself; there is no mention of the named type X that
|
||||
// might help us break the cycle.
|
||||
// (See comment in go/types.identical, case *Interface, for more.)
|
||||
func (h hasher) shallowHash(t types.Type) uint32 {
|
||||
// t is the type of an interface method (Signature),
|
||||
// its params or results (Tuples), or their immediate
|
||||
// elements (mostly Slice, Pointer, Basic, Named),
|
||||
// so there's no need to optimize anything else.
|
||||
switch t := t.(type) {
|
||||
case *types.Alias:
|
||||
return h.shallowHash(types.Unalias(t))
|
||||
|
||||
case *types.Signature:
|
||||
var hash uint32 = 604171
|
||||
if t.Variadic() {
|
||||
hash *= 971767
|
||||
}
|
||||
// The Signature/Tuple recursion is always finite
|
||||
// and invariably shallow.
|
||||
return hash + 1062599*h.shallowHash(t.Params()) + 1282529*h.shallowHash(t.Results())
|
||||
|
||||
case *types.Tuple:
|
||||
n := t.Len()
|
||||
hash := 9137 + 2*uint32(n)
|
||||
for i := range n {
|
||||
hash += 53471161 * h.shallowHash(t.At(i).Type())
|
||||
}
|
||||
return hash
|
||||
|
||||
case *types.Basic:
|
||||
return 45212177 * uint32(t.Kind())
|
||||
|
||||
case *types.Array:
|
||||
return 1524181 + 2*uint32(t.Len())
|
||||
|
||||
case *types.Slice:
|
||||
return 2690201
|
||||
|
||||
case *types.Struct:
|
||||
return 3326489
|
||||
|
||||
case *types.Pointer:
|
||||
return 4393139
|
||||
|
||||
case *types.Union:
|
||||
return 562448657
|
||||
|
||||
case *types.Interface:
|
||||
return 2124679 // no recursion here
|
||||
|
||||
case *types.Map:
|
||||
return 9109
|
||||
|
||||
case *types.Chan:
|
||||
return 9127
|
||||
|
||||
case *types.Named:
|
||||
return h.hashTypeName(t.Obj())
|
||||
|
||||
case *types.TypeParam:
|
||||
return h.hashTypeParam(t)
|
||||
}
|
||||
panic(fmt.Sprintf("shallowHash: %T: %v", t, t))
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// This file implements a cache of method sets.
|
||||
|
||||
package typeutil
|
||||
|
||||
import (
|
||||
"go/types"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// A MethodSetCache records the method set of each type T for which
|
||||
// MethodSet(T) is called so that repeat queries are fast.
|
||||
// The zero value is a ready-to-use cache instance.
|
||||
type MethodSetCache struct {
|
||||
mu sync.Mutex
|
||||
named map[*types.Named]struct{ value, pointer *types.MethodSet } // method sets for named N and *N
|
||||
others map[types.Type]*types.MethodSet // all other types
|
||||
}
|
||||
|
||||
// MethodSet returns the method set of type T. It is thread-safe.
|
||||
//
|
||||
// If cache is nil, this function is equivalent to types.NewMethodSet(T).
|
||||
// Utility functions can thus expose an optional *MethodSetCache
|
||||
// parameter to clients that care about performance.
|
||||
func (cache *MethodSetCache) MethodSet(T types.Type) *types.MethodSet {
|
||||
if cache == nil {
|
||||
return types.NewMethodSet(T)
|
||||
}
|
||||
cache.mu.Lock()
|
||||
defer cache.mu.Unlock()
|
||||
|
||||
switch T := types.Unalias(T).(type) {
|
||||
case *types.Named:
|
||||
return cache.lookupNamed(T).value
|
||||
|
||||
case *types.Pointer:
|
||||
if N, ok := types.Unalias(T.Elem()).(*types.Named); ok {
|
||||
return cache.lookupNamed(N).pointer
|
||||
}
|
||||
}
|
||||
|
||||
// all other types
|
||||
// (The map uses pointer equivalence, not type identity.)
|
||||
mset := cache.others[T]
|
||||
if mset == nil {
|
||||
mset = types.NewMethodSet(T)
|
||||
if cache.others == nil {
|
||||
cache.others = make(map[types.Type]*types.MethodSet)
|
||||
}
|
||||
cache.others[T] = mset
|
||||
}
|
||||
return mset
|
||||
}
|
||||
|
||||
func (cache *MethodSetCache) lookupNamed(named *types.Named) struct{ value, pointer *types.MethodSet } {
|
||||
if cache.named == nil {
|
||||
cache.named = make(map[*types.Named]struct{ value, pointer *types.MethodSet })
|
||||
}
|
||||
// Avoid recomputing mset(*T) for each distinct Pointer
|
||||
// instance whose underlying type is a named type.
|
||||
msets, ok := cache.named[named]
|
||||
if !ok {
|
||||
msets.value = types.NewMethodSet(named)
|
||||
msets.pointer = types.NewMethodSet(types.NewPointer(named))
|
||||
cache.named[named] = msets
|
||||
}
|
||||
return msets
|
||||
}
|
||||
-53
@@ -1,53 +0,0 @@
|
||||
// Copyright 2014 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 typeutil
|
||||
|
||||
// This file defines utilities for user interfaces that display types.
|
||||
|
||||
import (
|
||||
"go/types"
|
||||
)
|
||||
|
||||
// IntuitiveMethodSet returns the intuitive method set of a type T,
|
||||
// which is the set of methods you can call on an addressable value of
|
||||
// that type.
|
||||
//
|
||||
// The result always contains MethodSet(T), and is exactly MethodSet(T)
|
||||
// for interface types and for pointer-to-concrete types.
|
||||
// For all other concrete types T, the result additionally
|
||||
// contains each method belonging to *T if there is no identically
|
||||
// named method on T itself.
|
||||
//
|
||||
// This corresponds to user intuition about method sets;
|
||||
// this function is intended only for user interfaces.
|
||||
//
|
||||
// The order of the result is as for types.MethodSet(T).
|
||||
func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection {
|
||||
isPointerToConcrete := func(T types.Type) bool {
|
||||
ptr, ok := types.Unalias(T).(*types.Pointer)
|
||||
return ok && !types.IsInterface(ptr.Elem())
|
||||
}
|
||||
|
||||
var result []*types.Selection
|
||||
mset := msets.MethodSet(T)
|
||||
if types.IsInterface(T) || isPointerToConcrete(T) {
|
||||
for i, n := 0, mset.Len(); i < n; i++ {
|
||||
result = append(result, mset.At(i))
|
||||
}
|
||||
} else {
|
||||
// T is some other concrete type.
|
||||
// Report methods of T and *T, preferring those of T.
|
||||
pmset := msets.MethodSet(types.NewPointer(T))
|
||||
for i, n := 0, pmset.Len(); i < n; i++ {
|
||||
meth := pmset.At(i)
|
||||
if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil {
|
||||
meth = m
|
||||
}
|
||||
result = append(result, meth)
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
// 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 moremaps contains more functions for working with maps.
|
||||
package moremaps
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"iter"
|
||||
"maps"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// Arbitrary returns an arbitrary (key, value) entry from the map and ok is true, if
|
||||
// the map is not empty. Otherwise, it returns zero values for K and V, and false.
|
||||
func Arbitrary[K comparable, V any](m map[K]V) (_ K, _ V, ok bool) {
|
||||
for k, v := range m {
|
||||
return k, v, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Group returns a new non-nil map containing the elements of s grouped by the
|
||||
// keys returned from the key func.
|
||||
func Group[K comparable, V any](s []V, key func(V) K) map[K][]V {
|
||||
m := make(map[K][]V)
|
||||
for _, v := range s {
|
||||
k := key(v)
|
||||
m[k] = append(m[k], v)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// KeySlice returns the keys of the map M, like slices.Collect(maps.Keys(m)).
|
||||
func KeySlice[M ~map[K]V, K comparable, V any](m M) []K {
|
||||
r := make([]K, 0, len(m))
|
||||
for k := range m {
|
||||
r = append(r, k)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// ValueSlice returns the values of the map M, like slices.Collect(maps.Values(m)).
|
||||
func ValueSlice[M ~map[K]V, K comparable, V any](m M) []V {
|
||||
r := make([]V, 0, len(m))
|
||||
for _, v := range m {
|
||||
r = append(r, v)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// SameKeys reports whether x and y have equal sets of keys.
|
||||
func SameKeys[K comparable, V1, V2 any](x map[K]V1, y map[K]V2) bool {
|
||||
ignoreValues := func(V1, V2) bool { return true }
|
||||
return maps.EqualFunc(x, y, ignoreValues)
|
||||
}
|
||||
|
||||
// Sorted returns an iterator over the entries of m in key order.
|
||||
func Sorted[M ~map[K]V, K cmp.Ordered, V any](m M) iter.Seq2[K, V] {
|
||||
// TODO(adonovan): use maps.Sorted if proposal #68598 is accepted.
|
||||
return func(yield func(K, V) bool) {
|
||||
keys := KeySlice(m)
|
||||
slices.Sort(keys)
|
||||
for _, k := range keys {
|
||||
if !yield(k, m[k]) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SortedFunc returns an iterator over the entries of m in the key order determined by cmp.
|
||||
func SortedFunc[M ~map[K]V, K comparable, V any](m M, cmp func(x, y K) int) iter.Seq2[K, V] {
|
||||
// TODO(adonovan): use maps.SortedFunc if proposal #68598 is accepted.
|
||||
return func(yield func(K, V) bool) {
|
||||
keys := KeySlice(m)
|
||||
slices.SortFunc(keys, cmp)
|
||||
for _, k := range keys {
|
||||
if !yield(k, m[k]) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete is like delete(m, k) but reports whether deletion occurred.
|
||||
func Delete[M ~map[K]V, K comparable, V any](m M, k K) bool {
|
||||
pre := len(m)
|
||||
delete(m, k)
|
||||
return pre != len(m)
|
||||
}
|
||||
|
||||
// Entry is a key-value pair obtained from a map.
|
||||
type Entry[K comparable, V any] struct {
|
||||
Key K
|
||||
Value V
|
||||
}
|
||||
|
||||
// Entries returns a new unordered array of the entries of a map.
|
||||
func Entries[M ~map[K]V, K comparable, V any](m M) []Entry[K, V] {
|
||||
entries := make([]Entry[K, V], 0, len(m))
|
||||
for k, v := range m {
|
||||
entries = append(entries, Entry[K, V]{k, v})
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// FromEntries returns a new map into which the entries have been inserted in order.
|
||||
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V {
|
||||
m := make(map[K]V, len(entries))
|
||||
for _, e := range entries {
|
||||
m[e.Key] = e.Value
|
||||
}
|
||||
return m
|
||||
}
|
||||
-68
@@ -1,68 +0,0 @@
|
||||
// Copyright 2021 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 typeparams contains common utilities for writing tools that
|
||||
// interact with generic Go code, as introduced with Go 1.18. It
|
||||
// supplements the standard library APIs. Notably, the StructuralTerms
|
||||
// API computes a minimal representation of the structural
|
||||
// restrictions on a type parameter.
|
||||
//
|
||||
// An external version of these APIs is available in the
|
||||
// golang.org/x/exp/typeparams module.
|
||||
package typeparams
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"go/types"
|
||||
)
|
||||
|
||||
// UnpackIndexExpr extracts data from AST nodes that represent index
|
||||
// expressions.
|
||||
//
|
||||
// For an ast.IndexExpr, the resulting indices slice will contain exactly one
|
||||
// index expression. For an ast.IndexListExpr (go1.18+), it may have a variable
|
||||
// number of index expressions.
|
||||
//
|
||||
// For nodes that don't represent index expressions, the first return value of
|
||||
// UnpackIndexExpr will be nil.
|
||||
func UnpackIndexExpr(n ast.Node) (x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack token.Pos) {
|
||||
switch e := n.(type) {
|
||||
case *ast.IndexExpr:
|
||||
return e.X, e.Lbrack, []ast.Expr{e.Index}, e.Rbrack
|
||||
case *ast.IndexListExpr:
|
||||
return e.X, e.Lbrack, e.Indices, e.Rbrack
|
||||
}
|
||||
return nil, token.NoPos, nil, token.NoPos
|
||||
}
|
||||
|
||||
// PackIndexExpr returns an *ast.IndexExpr or *ast.IndexListExpr, depending on
|
||||
// the cardinality of indices. Calling PackIndexExpr with len(indices) == 0
|
||||
// will panic.
|
||||
func PackIndexExpr(x ast.Expr, lbrack token.Pos, indices []ast.Expr, rbrack token.Pos) ast.Expr {
|
||||
switch len(indices) {
|
||||
case 0:
|
||||
panic("empty indices")
|
||||
case 1:
|
||||
return &ast.IndexExpr{
|
||||
X: x,
|
||||
Lbrack: lbrack,
|
||||
Index: indices[0],
|
||||
Rbrack: rbrack,
|
||||
}
|
||||
default:
|
||||
return &ast.IndexListExpr{
|
||||
X: x,
|
||||
Lbrack: lbrack,
|
||||
Indices: indices,
|
||||
Rbrack: rbrack,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IsTypeParam reports whether t is a type parameter (or an alias of one).
|
||||
func IsTypeParam(t types.Type) bool {
|
||||
_, ok := types.Unalias(t).(*types.TypeParam)
|
||||
return ok
|
||||
}
|
||||
-157
@@ -1,157 +0,0 @@
|
||||
// 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 typeparams
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/types"
|
||||
)
|
||||
|
||||
// CoreType returns the core type of T or nil if T does not have a core type.
|
||||
//
|
||||
// As of Go1.25, the notion of a core type has been removed from the language spec.
|
||||
// See https://go.dev/blog/coretypes for more details.
|
||||
// TODO(mkalil): We should eventually consider removing all uses of CoreType.
|
||||
func CoreType(T types.Type) types.Type {
|
||||
U := T.Underlying()
|
||||
if _, ok := U.(*types.Interface); !ok {
|
||||
return U // for non-interface types,
|
||||
}
|
||||
|
||||
terms, err := NormalTerms(U)
|
||||
if len(terms) == 0 || err != nil {
|
||||
// len(terms) -> empty type set of interface.
|
||||
// err != nil => U is invalid, exceeds complexity bounds, or has an empty type set.
|
||||
return nil // no core type.
|
||||
}
|
||||
|
||||
U = terms[0].Type().Underlying()
|
||||
var identical int // i in [0,identical) => Identical(U, terms[i].Type().Underlying())
|
||||
for identical = 1; identical < len(terms); identical++ {
|
||||
if !types.Identical(U, terms[identical].Type().Underlying()) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if identical == len(terms) {
|
||||
// From the deprecated core types spec:
|
||||
// "There is a single type U which is the underlying type of all types in the type set of T"
|
||||
return U
|
||||
}
|
||||
ch, ok := U.(*types.Chan)
|
||||
if !ok {
|
||||
return nil // no core type as identical < len(terms) and U is not a channel.
|
||||
}
|
||||
// From the deprecated core types spec:
|
||||
// "the type chan E if T contains only bidirectional channels, or the type chan<- E or
|
||||
// <-chan E depending on the direction of the directional channels present."
|
||||
for chans := identical; chans < len(terms); chans++ {
|
||||
curr, ok := terms[chans].Type().Underlying().(*types.Chan)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if !types.Identical(ch.Elem(), curr.Elem()) {
|
||||
return nil // channel elements are not identical.
|
||||
}
|
||||
if ch.Dir() == types.SendRecv {
|
||||
// ch is bidirectional. We can safely always use curr's direction.
|
||||
ch = curr
|
||||
} else if curr.Dir() != types.SendRecv && ch.Dir() != curr.Dir() {
|
||||
// ch and curr are not bidirectional and not the same direction.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ch
|
||||
}
|
||||
|
||||
// NormalTerms returns a slice of terms representing the normalized structural
|
||||
// type restrictions of a type, if any.
|
||||
//
|
||||
// For all types other than *types.TypeParam, *types.Interface, and
|
||||
// *types.Union, this is just a single term with Tilde() == false and
|
||||
// Type() == typ. For *types.TypeParam, *types.Interface, and *types.Union, see
|
||||
// below.
|
||||
//
|
||||
// Structural type restrictions of a type parameter are created via
|
||||
// non-interface types embedded in its constraint interface (directly, or via a
|
||||
// chain of interface embeddings). For example, in the declaration type
|
||||
// T[P interface{~int; m()}] int the structural restriction of the type
|
||||
// parameter P is ~int.
|
||||
//
|
||||
// With interface embedding and unions, the specification of structural type
|
||||
// restrictions may be arbitrarily complex. For example, consider the
|
||||
// following:
|
||||
//
|
||||
// type A interface{ ~string|~[]byte }
|
||||
//
|
||||
// type B interface{ int|string }
|
||||
//
|
||||
// type C interface { ~string|~int }
|
||||
//
|
||||
// type T[P interface{ A|B; C }] int
|
||||
//
|
||||
// In this example, the structural type restriction of P is ~string|int: A|B
|
||||
// expands to ~string|~[]byte|int|string, which reduces to ~string|~[]byte|int,
|
||||
// which when intersected with C (~string|~int) yields ~string|int.
|
||||
//
|
||||
// NormalTerms computes these expansions and reductions, producing a
|
||||
// "normalized" form of the embeddings. A structural restriction is normalized
|
||||
// if it is a single union containing no interface terms, and is minimal in the
|
||||
// sense that removing any term changes the set of types satisfying the
|
||||
// constraint. It is left as a proof for the reader that, modulo sorting, there
|
||||
// is exactly one such normalized form.
|
||||
//
|
||||
// Because the minimal representation always takes this form, NormalTerms
|
||||
// returns a slice of tilde terms corresponding to the terms of the union in
|
||||
// the normalized structural restriction. An error is returned if the type is
|
||||
// invalid, exceeds complexity bounds, or has an empty type set. In the latter
|
||||
// case, NormalTerms returns ErrEmptyTypeSet.
|
||||
//
|
||||
// NormalTerms makes no guarantees about the order of terms, except that it
|
||||
// is deterministic.
|
||||
func NormalTerms(T types.Type) ([]*types.Term, error) {
|
||||
// typeSetOf(T) == typeSetOf(Unalias(T))
|
||||
typ := types.Unalias(T)
|
||||
if named, ok := typ.(*types.Named); ok {
|
||||
typ = named.Underlying()
|
||||
}
|
||||
switch typ := typ.(type) {
|
||||
case *types.TypeParam:
|
||||
return StructuralTerms(typ)
|
||||
case *types.Union:
|
||||
return UnionTermSet(typ)
|
||||
case *types.Interface:
|
||||
return InterfaceTermSet(typ)
|
||||
default:
|
||||
return []*types.Term{types.NewTerm(false, T)}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Deref returns the type of the variable pointed to by t,
|
||||
// if t's core type is a pointer; otherwise it returns t.
|
||||
//
|
||||
// Do not assume that Deref(T)==T implies T is not a pointer:
|
||||
// consider "type T *T", for example.
|
||||
//
|
||||
// TODO(adonovan): ideally this would live in typesinternal, but that
|
||||
// creates an import cycle. Move there when we melt this package down.
|
||||
func Deref(t types.Type) types.Type {
|
||||
if ptr, ok := CoreType(t).(*types.Pointer); ok {
|
||||
return ptr.Elem()
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// MustDeref returns the type of the variable pointed to by t.
|
||||
// It panics if t's core type is not a pointer.
|
||||
//
|
||||
// TODO(adonovan): ideally this would live in typesinternal, but that
|
||||
// creates an import cycle. Move there when we melt this package down.
|
||||
func MustDeref(t types.Type) types.Type {
|
||||
if ptr, ok := CoreType(t).(*types.Pointer); ok {
|
||||
return ptr.Elem()
|
||||
}
|
||||
panic(fmt.Sprintf("%v is not a pointer", t))
|
||||
}
|
||||
-129
@@ -1,129 +0,0 @@
|
||||
// Copyright 2024 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 typeparams
|
||||
|
||||
import (
|
||||
"go/types"
|
||||
)
|
||||
|
||||
// Free is a memoization of the set of free type parameters within a
|
||||
// type. It makes a sequence of calls to [Free.Has] for overlapping
|
||||
// types more efficient. The zero value is ready for use.
|
||||
//
|
||||
// NOTE: Adapted from go/types/infer.go. If it is later exported, factor.
|
||||
type Free struct {
|
||||
seen map[types.Type]bool
|
||||
}
|
||||
|
||||
// Has reports whether the specified type has a free type parameter.
|
||||
func (w *Free) Has(typ types.Type) (res bool) {
|
||||
// detect cycles
|
||||
if x, ok := w.seen[typ]; ok {
|
||||
return x
|
||||
}
|
||||
if w.seen == nil {
|
||||
w.seen = make(map[types.Type]bool)
|
||||
}
|
||||
w.seen[typ] = false
|
||||
defer func() {
|
||||
w.seen[typ] = res
|
||||
}()
|
||||
|
||||
switch t := typ.(type) {
|
||||
case nil, *types.Basic: // TODO(gri) should nil be handled here?
|
||||
break
|
||||
|
||||
case *types.Alias:
|
||||
if t.TypeParams().Len() > t.TypeArgs().Len() {
|
||||
return true // This is an uninstantiated Alias.
|
||||
}
|
||||
// The expansion of an alias can have free type parameters,
|
||||
// whether or not the alias itself has type parameters:
|
||||
//
|
||||
// func _[K comparable]() {
|
||||
// type Set = map[K]bool // free(Set) = {K}
|
||||
// type MapTo[V] = map[K]V // free(Map[foo]) = {V}
|
||||
// }
|
||||
//
|
||||
// So, we must Unalias.
|
||||
return w.Has(types.Unalias(t))
|
||||
|
||||
case *types.Array:
|
||||
return w.Has(t.Elem())
|
||||
|
||||
case *types.Slice:
|
||||
return w.Has(t.Elem())
|
||||
|
||||
case *types.Struct:
|
||||
for i, n := 0, t.NumFields(); i < n; i++ {
|
||||
if w.Has(t.Field(i).Type()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
case *types.Pointer:
|
||||
return w.Has(t.Elem())
|
||||
|
||||
case *types.Tuple:
|
||||
n := t.Len()
|
||||
for i := range n {
|
||||
if w.Has(t.At(i).Type()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
case *types.Signature:
|
||||
// t.tparams may not be nil if we are looking at a signature
|
||||
// of a generic function type (or an interface method) that is
|
||||
// part of the type we're testing. We don't care about these type
|
||||
// parameters.
|
||||
// Similarly, the receiver of a method may declare (rather than
|
||||
// use) type parameters, we don't care about those either.
|
||||
// Thus, we only need to look at the input and result parameters.
|
||||
return w.Has(t.Params()) || w.Has(t.Results())
|
||||
|
||||
case *types.Interface:
|
||||
for i, n := 0, t.NumMethods(); i < n; i++ {
|
||||
if w.Has(t.Method(i).Type()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
terms, err := InterfaceTermSet(t)
|
||||
if err != nil {
|
||||
return false // ill typed
|
||||
}
|
||||
for _, term := range terms {
|
||||
if w.Has(term.Type()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
case *types.Map:
|
||||
return w.Has(t.Key()) || w.Has(t.Elem())
|
||||
|
||||
case *types.Chan:
|
||||
return w.Has(t.Elem())
|
||||
|
||||
case *types.Named:
|
||||
args := t.TypeArgs()
|
||||
if params := t.TypeParams(); params.Len() > args.Len() {
|
||||
return true // this is an uninstantiated named type.
|
||||
}
|
||||
for i, n := 0, args.Len(); i < n; i++ {
|
||||
if w.Has(args.At(i)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return w.Has(t.Underlying()) // recurse for types local to parameterized functions
|
||||
|
||||
case *types.TypeParam:
|
||||
return true
|
||||
|
||||
default:
|
||||
panic(t) // unreachable
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
-216
@@ -1,216 +0,0 @@
|
||||
// Copyright 2021 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 typeparams
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"go/types"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:generate go run copytermlist.go
|
||||
|
||||
const debug = false
|
||||
|
||||
var ErrEmptyTypeSet = errors.New("empty type set")
|
||||
|
||||
// StructuralTerms returns a slice of terms representing the normalized
|
||||
// structural type restrictions of a type parameter, if any.
|
||||
//
|
||||
// Structural type restrictions of a type parameter are created via
|
||||
// non-interface types embedded in its constraint interface (directly, or via a
|
||||
// chain of interface embeddings). For example, in the declaration
|
||||
//
|
||||
// type T[P interface{~int; m()}] int
|
||||
//
|
||||
// the structural restriction of the type parameter P is ~int.
|
||||
//
|
||||
// With interface embedding and unions, the specification of structural type
|
||||
// restrictions may be arbitrarily complex. For example, consider the
|
||||
// following:
|
||||
//
|
||||
// type A interface{ ~string|~[]byte }
|
||||
//
|
||||
// type B interface{ int|string }
|
||||
//
|
||||
// type C interface { ~string|~int }
|
||||
//
|
||||
// type T[P interface{ A|B; C }] int
|
||||
//
|
||||
// In this example, the structural type restriction of P is ~string|int: A|B
|
||||
// expands to ~string|~[]byte|int|string, which reduces to ~string|~[]byte|int,
|
||||
// which when intersected with C (~string|~int) yields ~string|int.
|
||||
//
|
||||
// StructuralTerms computes these expansions and reductions, producing a
|
||||
// "normalized" form of the embeddings. A structural restriction is normalized
|
||||
// if it is a single union containing no interface terms, and is minimal in the
|
||||
// sense that removing any term changes the set of types satisfying the
|
||||
// constraint. It is left as a proof for the reader that, modulo sorting, there
|
||||
// is exactly one such normalized form.
|
||||
//
|
||||
// Because the minimal representation always takes this form, StructuralTerms
|
||||
// returns a slice of tilde terms corresponding to the terms of the union in
|
||||
// the normalized structural restriction. An error is returned if the
|
||||
// constraint interface is invalid, exceeds complexity bounds, or has an empty
|
||||
// type set. In the latter case, StructuralTerms returns ErrEmptyTypeSet.
|
||||
//
|
||||
// StructuralTerms makes no guarantees about the order of terms, except that it
|
||||
// is deterministic.
|
||||
func StructuralTerms(tparam *types.TypeParam) ([]*types.Term, error) {
|
||||
constraint := tparam.Constraint()
|
||||
if constraint == nil {
|
||||
return nil, fmt.Errorf("%s has nil constraint", tparam)
|
||||
}
|
||||
iface, _ := constraint.Underlying().(*types.Interface)
|
||||
if iface == nil {
|
||||
return nil, fmt.Errorf("constraint is %T, not *types.Interface", constraint.Underlying())
|
||||
}
|
||||
return InterfaceTermSet(iface)
|
||||
}
|
||||
|
||||
// InterfaceTermSet computes the normalized terms for a constraint interface,
|
||||
// returning an error if the term set cannot be computed or is empty. In the
|
||||
// latter case, the error will be ErrEmptyTypeSet.
|
||||
//
|
||||
// See the documentation of StructuralTerms for more information on
|
||||
// normalization.
|
||||
func InterfaceTermSet(iface *types.Interface) ([]*types.Term, error) {
|
||||
return computeTermSet(iface)
|
||||
}
|
||||
|
||||
// UnionTermSet computes the normalized terms for a union, returning an error
|
||||
// if the term set cannot be computed or is empty. In the latter case, the
|
||||
// error will be ErrEmptyTypeSet.
|
||||
//
|
||||
// See the documentation of StructuralTerms for more information on
|
||||
// normalization.
|
||||
func UnionTermSet(union *types.Union) ([]*types.Term, error) {
|
||||
return computeTermSet(union)
|
||||
}
|
||||
|
||||
func computeTermSet(typ types.Type) ([]*types.Term, error) {
|
||||
tset, err := computeTermSetInternal(typ, make(map[types.Type]*termSet), 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tset.terms.isEmpty() {
|
||||
return nil, ErrEmptyTypeSet
|
||||
}
|
||||
if tset.terms.isAll() {
|
||||
return nil, nil
|
||||
}
|
||||
var terms []*types.Term
|
||||
for _, term := range tset.terms {
|
||||
terms = append(terms, types.NewTerm(term.tilde, term.typ))
|
||||
}
|
||||
return terms, nil
|
||||
}
|
||||
|
||||
// A termSet holds the normalized set of terms for a given type.
|
||||
//
|
||||
// The name termSet is intentionally distinct from 'type set': a type set is
|
||||
// all types that implement a type (and includes method restrictions), whereas
|
||||
// a term set just represents the structural restrictions on a type.
|
||||
type termSet struct {
|
||||
complete bool
|
||||
terms termlist
|
||||
}
|
||||
|
||||
func indentf(depth int, format string, args ...any) {
|
||||
fmt.Fprintf(os.Stderr, strings.Repeat(".", depth)+format+"\n", args...)
|
||||
}
|
||||
|
||||
func computeTermSetInternal(t types.Type, seen map[types.Type]*termSet, depth int) (res *termSet, err error) {
|
||||
if t == nil {
|
||||
panic("nil type")
|
||||
}
|
||||
|
||||
if debug {
|
||||
indentf(depth, "%s", t.String())
|
||||
defer func() {
|
||||
if err != nil {
|
||||
indentf(depth, "=> %s", err)
|
||||
} else {
|
||||
indentf(depth, "=> %s", res.terms.String())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
const maxTermCount = 100
|
||||
if tset, ok := seen[t]; ok {
|
||||
if !tset.complete {
|
||||
return nil, fmt.Errorf("cycle detected in the declaration of %s", t)
|
||||
}
|
||||
return tset, nil
|
||||
}
|
||||
|
||||
// Mark the current type as seen to avoid infinite recursion.
|
||||
tset := new(termSet)
|
||||
defer func() {
|
||||
tset.complete = true
|
||||
}()
|
||||
seen[t] = tset
|
||||
|
||||
switch u := t.Underlying().(type) {
|
||||
case *types.Interface:
|
||||
// The term set of an interface is the intersection of the term sets of its
|
||||
// embedded types.
|
||||
tset.terms = allTermlist
|
||||
for embedded := range u.EmbeddedTypes() {
|
||||
if _, ok := embedded.Underlying().(*types.TypeParam); ok {
|
||||
return nil, fmt.Errorf("invalid embedded type %T", embedded)
|
||||
}
|
||||
tset2, err := computeTermSetInternal(embedded, seen, depth+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tset.terms = tset.terms.intersect(tset2.terms)
|
||||
}
|
||||
case *types.Union:
|
||||
// The term set of a union is the union of term sets of its terms.
|
||||
tset.terms = nil
|
||||
for t := range u.Terms() {
|
||||
var terms termlist
|
||||
switch t.Type().Underlying().(type) {
|
||||
case *types.Interface:
|
||||
tset2, err := computeTermSetInternal(t.Type(), seen, depth+1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
terms = tset2.terms
|
||||
case *types.TypeParam, *types.Union:
|
||||
// A stand-alone type parameter or union is not permitted as union
|
||||
// term.
|
||||
return nil, fmt.Errorf("invalid union term %T", t)
|
||||
default:
|
||||
if t.Type() == types.Typ[types.Invalid] {
|
||||
continue
|
||||
}
|
||||
terms = termlist{{t.Tilde(), t.Type()}}
|
||||
}
|
||||
tset.terms = tset.terms.union(terms)
|
||||
if len(tset.terms) > maxTermCount {
|
||||
return nil, fmt.Errorf("exceeded max term count %d", maxTermCount)
|
||||
}
|
||||
}
|
||||
case *types.TypeParam:
|
||||
panic("unreachable")
|
||||
default:
|
||||
// For all other types, the term set is just a single non-tilde term
|
||||
// holding the type itself.
|
||||
if u != types.Typ[types.Invalid] {
|
||||
tset.terms = termlist{{false, t}}
|
||||
}
|
||||
}
|
||||
return tset, nil
|
||||
}
|
||||
|
||||
// under is a facade for the go/types internal function of the same name. It is
|
||||
// used by typeterm.go.
|
||||
func under(t types.Type) types.Type {
|
||||
return t.Underlying()
|
||||
}
|
||||
-169
@@ -1,169 +0,0 @@
|
||||
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
|
||||
// Source: ../../cmd/compile/internal/types2/termlist.go
|
||||
|
||||
// Copyright 2021 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.
|
||||
|
||||
// Code generated by copytermlist.go DO NOT EDIT.
|
||||
|
||||
package typeparams
|
||||
|
||||
import (
|
||||
"go/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// A termlist represents the type set represented by the union
|
||||
// t1 ∪ y2 ∪ ... tn of the type sets of the terms t1 to tn.
|
||||
// A termlist is in normal form if all terms are disjoint.
|
||||
// termlist operations don't require the operands to be in
|
||||
// normal form.
|
||||
type termlist []*term
|
||||
|
||||
// allTermlist represents the set of all types.
|
||||
// It is in normal form.
|
||||
var allTermlist = termlist{new(term)}
|
||||
|
||||
// termSep is the separator used between individual terms.
|
||||
const termSep = " | "
|
||||
|
||||
// String prints the termlist exactly (without normalization).
|
||||
func (xl termlist) String() string {
|
||||
if len(xl) == 0 {
|
||||
return "∅"
|
||||
}
|
||||
var buf strings.Builder
|
||||
for i, x := range xl {
|
||||
if i > 0 {
|
||||
buf.WriteString(termSep)
|
||||
}
|
||||
buf.WriteString(x.String())
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// isEmpty reports whether the termlist xl represents the empty set of types.
|
||||
func (xl termlist) isEmpty() bool {
|
||||
// If there's a non-nil term, the entire list is not empty.
|
||||
// If the termlist is in normal form, this requires at most
|
||||
// one iteration.
|
||||
for _, x := range xl {
|
||||
if x != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// isAll reports whether the termlist xl represents the set of all types.
|
||||
func (xl termlist) isAll() bool {
|
||||
// If there's a 𝓤 term, the entire list is 𝓤.
|
||||
// If the termlist is in normal form, this requires at most
|
||||
// one iteration.
|
||||
for _, x := range xl {
|
||||
if x != nil && x.typ == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// norm returns the normal form of xl.
|
||||
func (xl termlist) norm() termlist {
|
||||
// Quadratic algorithm, but good enough for now.
|
||||
// TODO(gri) fix asymptotic performance
|
||||
used := make([]bool, len(xl))
|
||||
var rl termlist
|
||||
for i, xi := range xl {
|
||||
if xi == nil || used[i] {
|
||||
continue
|
||||
}
|
||||
for j := i + 1; j < len(xl); j++ {
|
||||
xj := xl[j]
|
||||
if xj == nil || used[j] {
|
||||
continue
|
||||
}
|
||||
if u1, u2 := xi.union(xj); u2 == nil {
|
||||
// If we encounter a 𝓤 term, the entire list is 𝓤.
|
||||
// Exit early.
|
||||
// (Note that this is not just an optimization;
|
||||
// if we continue, we may end up with a 𝓤 term
|
||||
// and other terms and the result would not be
|
||||
// in normal form.)
|
||||
if u1.typ == nil {
|
||||
return allTermlist
|
||||
}
|
||||
xi = u1
|
||||
used[j] = true // xj is now unioned into xi - ignore it in future iterations
|
||||
}
|
||||
}
|
||||
rl = append(rl, xi)
|
||||
}
|
||||
return rl
|
||||
}
|
||||
|
||||
// union returns the union xl ∪ yl.
|
||||
func (xl termlist) union(yl termlist) termlist {
|
||||
return append(xl, yl...).norm()
|
||||
}
|
||||
|
||||
// intersect returns the intersection xl ∩ yl.
|
||||
func (xl termlist) intersect(yl termlist) termlist {
|
||||
if xl.isEmpty() || yl.isEmpty() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Quadratic algorithm, but good enough for now.
|
||||
// TODO(gri) fix asymptotic performance
|
||||
var rl termlist
|
||||
for _, x := range xl {
|
||||
for _, y := range yl {
|
||||
if r := x.intersect(y); r != nil {
|
||||
rl = append(rl, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
return rl.norm()
|
||||
}
|
||||
|
||||
// equal reports whether xl and yl represent the same type set.
|
||||
func (xl termlist) equal(yl termlist) bool {
|
||||
// TODO(gri) this should be more efficient
|
||||
return xl.subsetOf(yl) && yl.subsetOf(xl)
|
||||
}
|
||||
|
||||
// includes reports whether t ∈ xl.
|
||||
func (xl termlist) includes(t types.Type) bool {
|
||||
for _, x := range xl {
|
||||
if x.includes(t) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// supersetOf reports whether y ⊆ xl.
|
||||
func (xl termlist) supersetOf(y *term) bool {
|
||||
for _, x := range xl {
|
||||
if y.subsetOf(x) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// subsetOf reports whether xl ⊆ yl.
|
||||
func (xl termlist) subsetOf(yl termlist) bool {
|
||||
if yl.isEmpty() {
|
||||
return xl.isEmpty()
|
||||
}
|
||||
|
||||
// each term x of xl must be a subset of yl
|
||||
for _, x := range xl {
|
||||
if !yl.supersetOf(x) {
|
||||
return false // x is not a subset yl
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
-172
@@ -1,172 +0,0 @@
|
||||
// Code generated by "go test -run=Generate -write=all"; DO NOT EDIT.
|
||||
// Source: ../../cmd/compile/internal/types2/typeterm.go
|
||||
|
||||
// Copyright 2021 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.
|
||||
|
||||
// Code generated by copytermlist.go DO NOT EDIT.
|
||||
|
||||
package typeparams
|
||||
|
||||
import "go/types"
|
||||
|
||||
// A term describes elementary type sets:
|
||||
//
|
||||
// ∅: (*term)(nil) == ∅ // set of no types (empty set)
|
||||
// 𝓤: &term{} == 𝓤 // set of all types (𝓤niverse)
|
||||
// T: &term{false, T} == {T} // set of type T
|
||||
// ~t: &term{true, t} == {t' | under(t') == t} // set of types with underlying type t
|
||||
type term struct {
|
||||
tilde bool // valid if typ != nil
|
||||
typ types.Type
|
||||
}
|
||||
|
||||
func (x *term) String() string {
|
||||
switch {
|
||||
case x == nil:
|
||||
return "∅"
|
||||
case x.typ == nil:
|
||||
return "𝓤"
|
||||
case x.tilde:
|
||||
return "~" + x.typ.String()
|
||||
default:
|
||||
return x.typ.String()
|
||||
}
|
||||
}
|
||||
|
||||
// equal reports whether x and y represent the same type set.
|
||||
func (x *term) equal(y *term) bool {
|
||||
// easy cases
|
||||
switch {
|
||||
case x == nil || y == nil:
|
||||
return x == y
|
||||
case x.typ == nil || y.typ == nil:
|
||||
return x.typ == y.typ
|
||||
}
|
||||
// ∅ ⊂ x, y ⊂ 𝓤
|
||||
|
||||
return x.tilde == y.tilde && types.Identical(x.typ, y.typ)
|
||||
}
|
||||
|
||||
// union returns the union x ∪ y: zero, one, or two non-nil terms.
|
||||
func (x *term) union(y *term) (_, _ *term) {
|
||||
// easy cases
|
||||
switch {
|
||||
case x == nil && y == nil:
|
||||
return nil, nil // ∅ ∪ ∅ == ∅
|
||||
case x == nil:
|
||||
return y, nil // ∅ ∪ y == y
|
||||
case y == nil:
|
||||
return x, nil // x ∪ ∅ == x
|
||||
case x.typ == nil:
|
||||
return x, nil // 𝓤 ∪ y == 𝓤
|
||||
case y.typ == nil:
|
||||
return y, nil // x ∪ 𝓤 == 𝓤
|
||||
}
|
||||
// ∅ ⊂ x, y ⊂ 𝓤
|
||||
|
||||
if x.disjoint(y) {
|
||||
return x, y // x ∪ y == (x, y) if x ∩ y == ∅
|
||||
}
|
||||
// x.typ == y.typ
|
||||
|
||||
// ~t ∪ ~t == ~t
|
||||
// ~t ∪ T == ~t
|
||||
// T ∪ ~t == ~t
|
||||
// T ∪ T == T
|
||||
if x.tilde || !y.tilde {
|
||||
return x, nil
|
||||
}
|
||||
return y, nil
|
||||
}
|
||||
|
||||
// intersect returns the intersection x ∩ y.
|
||||
func (x *term) intersect(y *term) *term {
|
||||
// easy cases
|
||||
switch {
|
||||
case x == nil || y == nil:
|
||||
return nil // ∅ ∩ y == ∅ and ∩ ∅ == ∅
|
||||
case x.typ == nil:
|
||||
return y // 𝓤 ∩ y == y
|
||||
case y.typ == nil:
|
||||
return x // x ∩ 𝓤 == x
|
||||
}
|
||||
// ∅ ⊂ x, y ⊂ 𝓤
|
||||
|
||||
if x.disjoint(y) {
|
||||
return nil // x ∩ y == ∅ if x ∩ y == ∅
|
||||
}
|
||||
// x.typ == y.typ
|
||||
|
||||
// ~t ∩ ~t == ~t
|
||||
// ~t ∩ T == T
|
||||
// T ∩ ~t == T
|
||||
// T ∩ T == T
|
||||
if !x.tilde || y.tilde {
|
||||
return x
|
||||
}
|
||||
return y
|
||||
}
|
||||
|
||||
// includes reports whether t ∈ x.
|
||||
func (x *term) includes(t types.Type) bool {
|
||||
// easy cases
|
||||
switch {
|
||||
case x == nil:
|
||||
return false // t ∈ ∅ == false
|
||||
case x.typ == nil:
|
||||
return true // t ∈ 𝓤 == true
|
||||
}
|
||||
// ∅ ⊂ x ⊂ 𝓤
|
||||
|
||||
u := t
|
||||
if x.tilde {
|
||||
u = under(u)
|
||||
}
|
||||
return types.Identical(x.typ, u)
|
||||
}
|
||||
|
||||
// subsetOf reports whether x ⊆ y.
|
||||
func (x *term) subsetOf(y *term) bool {
|
||||
// easy cases
|
||||
switch {
|
||||
case x == nil:
|
||||
return true // ∅ ⊆ y == true
|
||||
case y == nil:
|
||||
return false // x ⊆ ∅ == false since x != ∅
|
||||
case y.typ == nil:
|
||||
return true // x ⊆ 𝓤 == true
|
||||
case x.typ == nil:
|
||||
return false // 𝓤 ⊆ y == false since y != 𝓤
|
||||
}
|
||||
// ∅ ⊂ x, y ⊂ 𝓤
|
||||
|
||||
if x.disjoint(y) {
|
||||
return false // x ⊆ y == false if x ∩ y == ∅
|
||||
}
|
||||
// x.typ == y.typ
|
||||
|
||||
// ~t ⊆ ~t == true
|
||||
// ~t ⊆ T == false
|
||||
// T ⊆ ~t == true
|
||||
// T ⊆ T == true
|
||||
return !x.tilde || y.tilde
|
||||
}
|
||||
|
||||
// disjoint reports whether x ∩ y == ∅.
|
||||
// x.typ and y.typ must not be nil.
|
||||
func (x *term) disjoint(y *term) bool {
|
||||
if debug && (x.typ == nil || y.typ == nil) {
|
||||
panic("invalid argument(s)")
|
||||
}
|
||||
ux := x.typ
|
||||
if y.tilde {
|
||||
ux = under(ux)
|
||||
}
|
||||
uy := y.typ
|
||||
if x.tilde {
|
||||
uy = under(uy)
|
||||
}
|
||||
return !types.Identical(ux, uy)
|
||||
}
|
||||
Loaded 100 of 131 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user