Skip to content

Commit

Permalink
Reintroduce DefaultLengths; populate during Register.
Browse files Browse the repository at this point in the history
While it was possible to remove all use of this from this repo, when
attempting propagate changes to downstreams consuming it, it became
apparently that other repos also rely on this symbol.

Whether or not those usages are important and intentional, whether
they're actually worth maintaining, and whether they'd be replacable
with other approaches... is not considered at this time.
(Probably we should be asking this!  The first occasions where this
cropped up are in other functions that have been marked "deprecated"
since... 2018!  But... chasing those things down and straightening
them out is becoming problematic.  Perhaps we'll be more ready to
revisit these things at a later date.)
  • Loading branch information
warpfork committed Mar 10, 2021
1 parent 4b5e8aa commit 1a96911
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func Register(indicator uint64, hasherFactory func() hash.Hash) {
panic("not sensible to attempt to register a nil function")
}
registry[indicator] = hasherFactory
DefaultLengths[indicator] = hasherFactory().Size()
}

// GetHasher returns a new hash.Hash according to the indicator code number provided.
Expand All @@ -60,6 +61,12 @@ func GetHasher(indicator uint64) (hash.Hash, error) {
return factory(), nil
}

// DefaultLengths maps a multihash indicator code to the output size for that hash, in units of bytes.
//
// This map is populated when a hash function is registered by the Register function.
// It's effectively a shortcut for asking Size() on the hash.Hash.
var DefaultLengths = map[uint64]int{}

func init() {
Register(IDENTITY, func() hash.Hash { return &identityMultihash{} })
Register(MD5, md5.New)
Expand Down

0 comments on commit 1a96911

Please sign in to comment.