Skip to content

Commit

Permalink
HashValidator -> Allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jul 9, 2023
1 parent a85caea commit f93b600
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions verifcid/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions verifcid/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f93b600

Please sign in to comment.