// 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 impl is a registry of alternative implementations of cryptographic// primitives, to allow selecting them for testing.
package implimporttype implementation struct { Package string Name string Available bool Toggle *bool}var allImplementations []implementation// Register records an alternative implementation of a cryptographic primitive.// The implementation might be available or not based on CPU support. If// available is false, the implementation is unavailable and can't be tested on// this machine. If available is true, it can be set to false to disable the// implementation. If all alternative implementations but one are disabled, the// remaining one must be used (i.e. disabling one implementation must not// implicitly disable any other). Each package has an implicit base// implementation that is selected when all alternatives are unavailable or// disabled. pkg must be the package name, not path (e.g. "aes" not "crypto/aes").func (, string, *bool) {ifstrings.Contains(, "/") {panic("impl: package name must not contain slashes") }allImplementations = append(allImplementations, implementation{Package: ,Name: ,Available: *,Toggle: , })}// List returns the names of all alternative implementations registered for the// given package, whether available or not. The implicit base implementation is// not included.func ( string) []string {var []stringfor , := rangeallImplementations {if .Package == { = append(, .Name) } }return}func available(, string) bool {for , := rangeallImplementations {if .Package == && .Name == {return .Available } }panic("unknown implementation")}// Select disables all implementations for the given package except the one// with the given name. If name is empty, the base implementation is selected.// It returns whether the selected implementation is available.func (, string) bool {if == "" {for , := rangeallImplementations {if .Package == { *.Toggle = false } }returntrue }if !available(, ) {returnfalse }for , := rangeallImplementations {if .Package == { *.Toggle = .Name == } }returntrue}func ( string) {for , := rangeallImplementations {if .Package == { *.Toggle = .Availablereturn } }}
The pages are generated with Goldsv0.7.3-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.