feat(lns): expose verification flag tables
Co-authored-by: Virgil <virgil@lethean.io>
This commit is contained in:
parent
68707da7be
commit
cb7b2bc13e
5 changed files with 147 additions and 0 deletions
40
lns.go
40
lns.go
|
|
@ -277,6 +277,12 @@ var TypesByVal = covenant.TypesByVal
|
|||
// Blacklist mirrors the covenant blacklist used by the verifier.
|
||||
var Blacklist = covenant.Blacklist
|
||||
|
||||
// VerificationFlags mirrors the covenant verification flag lookup table.
|
||||
var VerificationFlags = covenant.VerificationFlags
|
||||
|
||||
// VerificationFlagsByVal mirrors the covenant verification flag reverse table.
|
||||
var VerificationFlagsByVal = covenant.VerificationFlagsByVal
|
||||
|
||||
// GetBlacklist is an alias for Blacklist.
|
||||
//
|
||||
// blacklist := lns.GetBlacklist()
|
||||
|
|
@ -284,6 +290,20 @@ func GetBlacklist() map[string]struct{} {
|
|||
return Blacklist
|
||||
}
|
||||
|
||||
// GetVerificationFlags is an alias for VerificationFlags.
|
||||
//
|
||||
// flags := lns.GetVerificationFlags()
|
||||
func GetVerificationFlags() map[string]NameFlags {
|
||||
return VerificationFlags
|
||||
}
|
||||
|
||||
// GetVerificationFlagsByVal is an alias for VerificationFlagsByVal.
|
||||
//
|
||||
// flags := lns.GetVerificationFlagsByVal()
|
||||
func GetVerificationFlagsByVal() map[NameFlags]string {
|
||||
return VerificationFlagsByVal
|
||||
}
|
||||
|
||||
// CovenantType mirrors the covenant type enum from pkg/covenant.
|
||||
type CovenantType = covenant.CovenantType
|
||||
|
||||
|
|
@ -585,6 +605,26 @@ func (s *Service) GetBlacklist() map[string]struct{} {
|
|||
return s.Blacklist()
|
||||
}
|
||||
|
||||
// VerificationFlags mirrors the covenant verification flag lookup table.
|
||||
func (s *Service) VerificationFlags() map[string]covenant.NameFlags {
|
||||
return covenant.VerificationFlags
|
||||
}
|
||||
|
||||
// GetVerificationFlags is an alias for VerificationFlags.
|
||||
func (s *Service) GetVerificationFlags() map[string]covenant.NameFlags {
|
||||
return s.VerificationFlags()
|
||||
}
|
||||
|
||||
// VerificationFlagsByVal mirrors the covenant verification flag reverse table.
|
||||
func (s *Service) VerificationFlagsByVal() map[covenant.NameFlags]string {
|
||||
return covenant.VerificationFlagsByVal
|
||||
}
|
||||
|
||||
// GetVerificationFlagsByVal is an alias for VerificationFlagsByVal.
|
||||
func (s *Service) GetVerificationFlagsByVal() map[covenant.NameFlags]string {
|
||||
return s.VerificationFlagsByVal()
|
||||
}
|
||||
|
||||
// GetReserved looks up a reserved .lthn name after canonicalisation.
|
||||
//
|
||||
// The lookup accepts the same inputs as Resolve and Verify, then returns the
|
||||
|
|
|
|||
|
|
@ -199,6 +199,32 @@ func TestPackageBlacklistAlias(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPackageVerificationFlagTables(t *testing.T) {
|
||||
if len(VerificationFlags) != 3 {
|
||||
t.Fatalf("VerificationFlags has %d entries, want 3", len(VerificationFlags))
|
||||
}
|
||||
|
||||
if len(GetVerificationFlags()) != len(VerificationFlags) {
|
||||
t.Fatal("GetVerificationFlags should alias VerificationFlags")
|
||||
}
|
||||
|
||||
if len(VerificationFlagsByVal) != len(VerificationFlags) {
|
||||
t.Fatalf("VerificationFlagsByVal has %d entries, want %d", len(VerificationFlagsByVal), len(VerificationFlags))
|
||||
}
|
||||
|
||||
if len(GetVerificationFlagsByVal()) != len(VerificationFlagsByVal) {
|
||||
t.Fatal("GetVerificationFlagsByVal should alias VerificationFlagsByVal")
|
||||
}
|
||||
|
||||
if got, ok := VerificationFlags["VERIFY_COVENANTS_LOCKUP"]; !ok || got != covenant.VerifyCovenantsLockup {
|
||||
t.Fatalf("VerificationFlags[LOCKUP] = %d, want %d", got, covenant.VerifyCovenantsLockup)
|
||||
}
|
||||
|
||||
if got, ok := VerificationFlagsByVal[covenant.VerifyCovenantsNone]; !ok || got != "VERIFY_COVENANTS_NONE" {
|
||||
t.Fatalf("VerificationFlagsByVal[None] = %q, want %q", got, "VERIFY_COVENANTS_NONE")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPackageTypeConstants(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
|
|
|
|||
28
lns_test.go
28
lns_test.go
|
|
@ -243,6 +243,34 @@ func TestServiceRuleTables(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceVerificationFlagTables(t *testing.T) {
|
||||
svc := &Service{}
|
||||
|
||||
if len(svc.VerificationFlags()) != 3 {
|
||||
t.Fatalf("VerificationFlags has %d entries, want 3", len(svc.VerificationFlags()))
|
||||
}
|
||||
|
||||
if len(svc.GetVerificationFlags()) != len(svc.VerificationFlags()) {
|
||||
t.Fatal("GetVerificationFlags should alias VerificationFlags")
|
||||
}
|
||||
|
||||
if len(svc.VerificationFlagsByVal()) != len(svc.VerificationFlags()) {
|
||||
t.Fatalf("VerificationFlagsByVal has %d entries, want %d", len(svc.VerificationFlagsByVal()), len(svc.VerificationFlags()))
|
||||
}
|
||||
|
||||
if len(svc.GetVerificationFlagsByVal()) != len(svc.VerificationFlagsByVal()) {
|
||||
t.Fatal("GetVerificationFlagsByVal should alias VerificationFlagsByVal")
|
||||
}
|
||||
|
||||
if got, ok := svc.VerificationFlags()["VERIFY_COVENANTS_HARDENED"]; !ok || got != covenant.VerifyCovenantsHardened {
|
||||
t.Fatalf("VerificationFlags[HARDENED] = %d, want %d", got, covenant.VerifyCovenantsHardened)
|
||||
}
|
||||
|
||||
if got, ok := svc.VerificationFlagsByVal()[covenant.VerifyCovenantsLockup]; !ok || got != "VERIFY_COVENANTS_LOCKUP" {
|
||||
t.Fatalf("VerificationFlagsByVal[LOCKUP] = %q, want %q", got, "VERIFY_COVENANTS_LOCKUP")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceHashByStringAndBinaryAliases(t *testing.T) {
|
||||
svc := &Service{}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,32 @@ func TestNameFlags(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVerificationFlagTables(t *testing.T) {
|
||||
if len(VerificationFlags) != 3 {
|
||||
t.Fatalf("VerificationFlags has %d entries, want 3", len(VerificationFlags))
|
||||
}
|
||||
|
||||
if len(VerificationFlagsByVal) != len(VerificationFlags) {
|
||||
t.Fatalf("VerificationFlagsByVal has %d entries, want %d", len(VerificationFlagsByVal), len(VerificationFlags))
|
||||
}
|
||||
|
||||
if got, ok := VerificationFlags["VERIFY_COVENANTS_HARDENED"]; !ok || got != VerifyCovenantsHardened {
|
||||
t.Fatalf("VerificationFlags[HARDENED] = %d, want %d", got, VerifyCovenantsHardened)
|
||||
}
|
||||
|
||||
if got, ok := VerificationFlagsByVal[VerifyCovenantsLockup]; !ok || got != "VERIFY_COVENANTS_LOCKUP" {
|
||||
t.Fatalf("VerificationFlagsByVal[LOCKUP] = %q, want %q", got, "VERIFY_COVENANTS_LOCKUP")
|
||||
}
|
||||
|
||||
if GetVerificationFlags()["VERIFY_COVENANTS_NONE"] != VerifyCovenantsNone {
|
||||
t.Fatal("GetVerificationFlags should alias VerificationFlags")
|
||||
}
|
||||
|
||||
if GetVerificationFlagsByVal()[VerifyCovenantsHardened] != "VERIFY_COVENANTS_HARDENED" {
|
||||
t.Fatal("GetVerificationFlagsByVal should alias VerificationFlagsByVal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTypeMaps(t *testing.T) {
|
||||
if len(Types) != len(TypesByVal) {
|
||||
t.Fatalf("Types and TypesByVal should expose the same number of entries: %d vs %d", len(Types), len(TypesByVal))
|
||||
|
|
|
|||
|
|
@ -28,3 +28,30 @@ const (
|
|||
// CovenantMaxSize is an alias for MaxCovenantSize.
|
||||
CovenantMaxSize = MaxCovenantSize
|
||||
)
|
||||
|
||||
// VerificationFlags mirrors the JS rules.nameFlags lookup table.
|
||||
//
|
||||
// The map is exported so callers can discover the named verification masks
|
||||
// without hard-coding the string keys used by the reference implementation.
|
||||
var VerificationFlags = map[string]NameFlags{
|
||||
"VERIFY_COVENANTS_NONE": VerifyCovenantsNone,
|
||||
"VERIFY_COVENANTS_HARDENED": VerifyCovenantsHardened,
|
||||
"VERIFY_COVENANTS_LOCKUP": VerifyCovenantsLockup,
|
||||
}
|
||||
|
||||
// VerificationFlagsByVal mirrors the JS nameFlags lookup table in reverse.
|
||||
var VerificationFlagsByVal = map[NameFlags]string{
|
||||
VerifyCovenantsNone: "VERIFY_COVENANTS_NONE",
|
||||
VerifyCovenantsHardened: "VERIFY_COVENANTS_HARDENED",
|
||||
VerifyCovenantsLockup: "VERIFY_COVENANTS_LOCKUP",
|
||||
}
|
||||
|
||||
// GetVerificationFlags returns the covenant verification flag lookup table.
|
||||
func GetVerificationFlags() map[string]NameFlags {
|
||||
return VerificationFlags
|
||||
}
|
||||
|
||||
// GetVerificationFlagsByVal returns the reverse covenant verification table.
|
||||
func GetVerificationFlagsByVal() map[NameFlags]string {
|
||||
return VerificationFlagsByVal
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue