Validate validates the encoded portion string
(encoded string)
| 177 | |
| 178 | // Validate validates the encoded portion string |
| 179 | func (a Algorithm) Validate(encoded string) error { |
| 180 | r, ok := anchoredEncodedRegexps[a] |
| 181 | if !ok { |
| 182 | return ErrDigestUnsupported |
| 183 | } |
| 184 | // Digests much always be hex-encoded, ensuring that their hex portion will |
| 185 | // always be size*2 |
| 186 | if a.Size()*2 != len(encoded) { |
| 187 | return ErrDigestInvalidLength |
| 188 | } |
| 189 | if r.MatchString(encoded) { |
| 190 | return nil |
| 191 | } |
| 192 | return ErrDigestInvalidFormat |
| 193 | } |