Skip to content

Commit

Permalink
docs and more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jul 9, 2023
1 parent eedc139 commit 5c14093
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ The following emojis are used to highlight certain changes:
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 Allowlist interface as part of
reducing globals efforts. Still, existing global accessor funcs are kept for backwards-compatibility.
reducing globals efforts. Still, existing global accessor funcs are kept for
backwards-compatibility.

### Removed

Expand Down
18 changes: 11 additions & 7 deletions verifcid/validator.go → verifcid/allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ import (
mh "github.com/multiformats/go-multihash"
)

// Allowlist defines an interface containing list of allowed multihashes.
type Allowlist interface {
IsGoodHash(code uint64) bool
// IsAllowed checks for multihash allowance by the code.
IsAllowed(code uint64) bool
// ValidateCid validates multihash allowance behind given CID.
ValidateCid(c cid.Cid) error
}

func NewAllowlist(Allowlist map[uint64]bool) Allowlist {
return &allowlist{registry: Allowlist}
// NewAllowlist constructs new Allowlist from the given map set.
func NewAllowlist(allowset map[uint64]bool) Allowlist {
return &allowlist{allowset: allowset}
}

type allowlist struct {
registry map[uint64]bool
allowset map[uint64]bool
}

func (ghr *allowlist) IsGoodHash(code uint64) bool {
good, found := ghr.registry[code]
func (ghr *allowlist) IsAllowed(code uint64) bool {
good, found := ghr.allowset[code]
if good {
return true
}
Expand All @@ -38,7 +42,7 @@ func (ghr *allowlist) IsGoodHash(code uint64) bool {

func (ghr *allowlist) ValidateCid(c cid.Cid) error {
pref := c.Prefix()
if !ghr.IsGoodHash(pref.MhType) {
if !ghr.IsAllowed(pref.MhType) {
return ErrPossiblyInsecureHashFunction
}

Expand Down
2 changes: 1 addition & 1 deletion verifcid/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var goodset = map[uint64]bool{
}

func IsGoodHash(code uint64) bool {
return DefaultAllowlist.IsGoodHash(code)
return DefaultAllowlist.IsAllowed(code)
}

func ValidateCid(c cid.Cid) error {
Expand Down

0 comments on commit 5c14093

Please sign in to comment.