Skip to content

Commit 1a96911

Browse files
committed
Reintroduce DefaultLengths; populate during Register.
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.)
1 parent 4b5e8aa commit 1a96911

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

registry.go

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func Register(indicator uint64, hasherFactory func() hash.Hash) {
3838
panic("not sensible to attempt to register a nil function")
3939
}
4040
registry[indicator] = hasherFactory
41+
DefaultLengths[indicator] = hasherFactory().Size()
4142
}
4243

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

64+
// DefaultLengths maps a multihash indicator code to the output size for that hash, in units of bytes.
65+
//
66+
// This map is populated when a hash function is registered by the Register function.
67+
// It's effectively a shortcut for asking Size() on the hash.Hash.
68+
var DefaultLengths = map[uint64]int{}
69+
6370
func init() {
6471
Register(IDENTITY, func() hash.Hash { return &identityMultihash{} })
6572
Register(MD5, md5.New)

0 commit comments

Comments
 (0)