Hash returns a new hash as used by the algorithm. If not available, the method will panic. Check Algorithm.Available() before calling.
()
| 116 | // Hash returns a new hash as used by the algorithm. If not available, the |
| 117 | // method will panic. Check Algorithm.Available() before calling. |
| 118 | func (a Algorithm) Hash() hash.Hash { |
| 119 | if !a.Available() { |
| 120 | // Empty algorithm string is invalid |
| 121 | if a == "" { |
| 122 | panic(fmt.Sprintf("empty digest algorithm, validate before calling Algorithm.Hash()")) |
| 123 | } |
| 124 | |
| 125 | // NOTE(stevvooe): A missing hash is usually a programming error that |
| 126 | // must be resolved at compile time. We don't import in the digest |
| 127 | // package to allow users to choose their hash implementation (such as |
| 128 | // when using stevvooe/resumable or a hardware accelerated package). |
| 129 | // |
| 130 | // Applications that may want to resolve the hash at runtime should |
| 131 | // call Algorithm.Available before call Algorithm.Hash(). |
| 132 | panic(fmt.Sprintf("%v not available (make sure it is imported)", a)) |
| 133 | } |
| 134 | |
| 135 | return algorithms[a].New() |
| 136 | } |
| 137 | |
| 138 | // Encode encodes the raw bytes of a digest, typically from a hash.Hash, into |
| 139 | // the encoded portion of the digest. |