mirror of
https://github.com/luxfi/pq.git
synced 2026-10-30 15:22:02 +00:00
Aligns the standalone luxfi/pq library to the same per-primitive model
the geth core/vm gate now uses. One way only: the same eight Forbid*
flags, the same sixteen Op constants, the same family errors.
Profile now has 8 fields (one per cryptographic primitive family)
instead of the prior 7 categorical flags. Op renamed from Op uint16
with mixed-case names to Op uint8 with namespace-qualified names
(OpEcrecover, OpBn256Pairing, etc.). Canonical encoding bumped to
version 2; new pinned hashes:
strict: 9efdbf424085b0557866c22b0a4e0c48e2ed90c8c9e3f699d17a3e0783cb2128
permissive: 256f4daa37543549e06bd101aab7f21a9b9dff46d322a9392e6b035cf4f0f638
API surface (the smallest possible):
type Profile struct { 8 Forbid* fields }
func Strict() / Permissive() *Profile
func (p *Profile) Forbids(op Op) bool
func (p *Profile) Encode() [16]byte
func (p *Profile) Hash() [32]byte
func DecodeProfile([16]byte) (*Profile, bool)
type Op uint8 — 16 stable identifiers
var Err*Forbidden — 8 family errors
func SetActive(*Profile) — package-level state, atomic
func Active() *Profile
func Refuse(Op) error — reads Active
func RefuseUnder(*Profile, Op) — context-free
const EnvVar = "QUASAR_STRICT_PQ"
func FromEnv() *Profile
Dropped concepts: context binding (WithProfile/FromContext), MustRefuse,
Violation type, categorical Forbid* flags, Op uint16 with mixed cases.
20 unit tests; vet clean.
31 lines
683 B
Go
31 lines
683 B
Go
package pq
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// EnvVar is the single environment variable that selects the active
|
|
// profile at startup. Production binaries read it once in main and
|
|
// install the result via [SetActive].
|
|
const EnvVar = "QUASAR_STRICT_PQ"
|
|
|
|
// truthy enumerates the values [FromEnv] accepts as "set".
|
|
var truthy = map[string]bool{
|
|
"1": true,
|
|
"true": true,
|
|
"on": true,
|
|
"yes": true,
|
|
"y": true,
|
|
}
|
|
|
|
// FromEnv returns [Strict] when [EnvVar] is set to a truthy value
|
|
// (case-insensitive) and [Permissive] otherwise.
|
|
func FromEnv() *Profile {
|
|
v := strings.ToLower(strings.TrimSpace(os.Getenv(EnvVar)))
|
|
if truthy[v] {
|
|
return Strict()
|
|
}
|
|
return Permissive()
|
|
}
|