New returns a new hash.Hash calculating the given bitrot algorithm.
()
| 45 | |
| 46 | // New returns a new hash.Hash calculating the given bitrot algorithm. |
| 47 | func (a BitrotAlgorithm) New() hash.Hash { |
| 48 | switch a { |
| 49 | case SHA256: |
| 50 | return sha256.New() |
| 51 | case BLAKE2b512: |
| 52 | b2, _ := blake2b.New512(nil) // New512 never returns an error if the key is nil |
| 53 | return b2 |
| 54 | case HighwayHash256: |
| 55 | hh, _ := highwayhash.New(magicHighwayHash256Key) // New will never return error since key is 256 bit |
| 56 | return hh |
| 57 | case HighwayHash256S: |
| 58 | hh, _ := highwayhash.New(magicHighwayHash256Key) // New will never return error since key is 256 bit |
| 59 | return hh |
| 60 | default: |
| 61 | logger.CriticalIf(GlobalContext, errors.New("Unsupported bitrot algorithm")) |
| 62 | return nil |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Available reports whether the given algorithm is available. |
| 67 | func (a BitrotAlgorithm) Available() bool { |