diff --git a/CHANGELOG.md b/CHANGELOG.md index c8c9eed1d..7846c777f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ The following emojis are used to highlight certain changes: all the required functionality to work the best as possible with IPNS v2 Records. Please check the [documentation](https://pkg.go.dev/github.com/ipfs/boxo/ipns) for more information, and follow [ipfs/specs#376](https://github.com/ipfs/specs/issues/376) for related IPIP. -* The `verifycid` package has been updated with the new HashValidator interface as part of +* The `verifycid` package has been updated with the new Allowlist interface as part of reducing globals efforts. Still, existing functions are kept for backwards-compatibility. ### Removed diff --git a/verifcid/validate.go b/verifcid/validate.go index 104b8d43b..e889f9f72 100644 --- a/verifcid/validate.go +++ b/verifcid/validate.go @@ -34,11 +34,11 @@ var goodset = map[uint64]bool{ } func IsGoodHash(code uint64) bool { - return DefaultHashValidator.IsGoodHash(code) + return DefaultAllowlist.IsGoodHash(code) } func ValidateCid(c cid.Cid) error { - return DefaultHashValidator.ValidateCid(c) + return DefaultAllowlist.ValidateCid(c) } -var DefaultHashValidator = NewHashValidator(goodset) +var DefaultAllowlist = NewAllowlist(goodset) diff --git a/verifcid/validator.go b/verifcid/validator.go index 7305f51a5..5849a00e0 100644 --- a/verifcid/validator.go +++ b/verifcid/validator.go @@ -5,20 +5,20 @@ import ( mh "github.com/multiformats/go-multihash" ) -type HashValidator interface { +type Allowlist interface { IsGoodHash(code uint64) bool ValidateCid(c cid.Cid) error } -func NewHashValidator(registry map[uint64]bool) HashValidator { - return &hashValidator{registry: registry} +func NewAllowlist(Allowlist map[uint64]bool) Allowlist { + return &allowlist{registry: Allowlist} } -type hashValidator struct { +type allowlist struct { registry map[uint64]bool } -func (ghr *hashValidator) IsGoodHash(code uint64) bool { +func (ghr *allowlist) IsGoodHash(code uint64) bool { good, found := ghr.registry[code] if good { return true @@ -36,7 +36,7 @@ func (ghr *hashValidator) IsGoodHash(code uint64) bool { return false } -func (ghr *hashValidator) ValidateCid(c cid.Cid) error { +func (ghr *allowlist) ValidateCid(c cid.Cid) error { pref := c.Prefix() if !ghr.IsGoodHash(pref.MhType) { return ErrPossiblyInsecureHashFunction