| 35 | } |
| 36 | |
| 37 | func checksum(r io.Reader, method string) (string, error) { |
| 38 | b, err := ioutil.ReadAll(r) |
| 39 | |
| 40 | if err != nil { |
| 41 | return "", err |
| 42 | } |
| 43 | |
| 44 | switch method { |
| 45 | case "md5": |
| 46 | return fmt.Sprintf("%x", md5.Sum(b)), nil |
| 47 | case "sha1": |
| 48 | return fmt.Sprintf("%x", sha1.Sum(b)), nil |
| 49 | case "sha256": |
| 50 | return fmt.Sprintf("%x", sha256.Sum256(b)), nil |
| 51 | case "sha512": |
| 52 | return fmt.Sprintf("%x", sha512.Sum512(b)), nil |
| 53 | case "adler32": |
| 54 | return strconv.FormatUint(uint64(adler32.Checksum(b)), 10), nil |
| 55 | case "crc32": |
| 56 | return strconv.FormatUint(uint64(crc32.ChecksumIEEE(b)), 10), nil |
| 57 | } |
| 58 | |
| 59 | return "", fmt.Errorf("Hashing method %s is not supported", method) |
| 60 | } |
| 61 | |
| 62 | func writeChecksums(files, methods []string, format string, flatten bool) ([]string, error) { |
| 63 | checksums := make(map[string][]string) |