1
0
mirror of https://github.com/opencontainers/go-digest.git synced 2025-10-23 14:48:27 +03:00

RegisterAlgorithm: skip regex if not needed

No need to validate the format if we previously accepted it to be
registered.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-07-02 13:37:00 +02:00
parent 3d866abde6
commit 38caa322a4

View File

@@ -138,14 +138,14 @@ func RegisterAlgorithm(algorithm Algorithm, implementation CryptoHash) bool {
algorithmsLock.Lock()
defer algorithmsLock.Unlock()
if !algorithmRegexp.MatchString(string(algorithm)) {
panic(fmt.Sprintf("Algorithm %s has a name which does not fit within the allowed grammar", algorithm))
}
if _, ok := algorithms[algorithm]; ok {
return false
}
if !algorithmRegexp.MatchString(string(algorithm)) {
panic(fmt.Sprintf("Algorithm %s has a name which does not fit within the allowed grammar", algorithm))
}
algorithms[algorithm] = implementation
// We can do this since the Digest function below only implements a hex digest. If we open this in the future
// we need to allow for alternative digest algorithms to be implemented and for the user to pass their own