Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrHashStatesNotMatch = errors.New("hashes and states do not match")
)
Functions ¶
func Sum ¶
func Sum(ctx context.Context, r io.Reader, bufferSize int64, cb CallBack, hashes ...hash.Hash) ([][]byte, int64, error)
Example ¶
package main import ( "context" "crypto/md5" "crypto/sha1" "fmt" "hash" "hash/crc32" "log" "strings" "github.com/northbright/hashelper" ) func main() { var bufferSize int64 = 1 // Hash strings. strs := []string{ "", "Hello World!", } for _, str := range strs { ctx := context.Background() hashes := []hash.Hash{ md5.New(), sha1.New(), crc32.NewIEEE(), } hashFuncNames := []string{ "MD5", "SHA-1", "CRC32", } r := strings.NewReader(str) checksums, summed, err := hashelper.Sum(ctx, r, bufferSize, nil, hashes...) if err != nil { log.Printf("Sum() error: %v", err) return } fmt.Printf("Summed: %v bytes for \"%v\"\n", summed, str) for i, checksum := range checksums { fmt.Printf("%v: %X\n", hashFuncNames[i], checksum) } } }
Output: Summed: 0 bytes for "" MD5: D41D8CD98F00B204E9800998ECF8427E SHA-1: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 CRC32: 00000000 Summed: 12 bytes for "Hello World!" MD5: ED076287532E86365E841E92BFC50D8C SHA-1: 2EF7BDE608CE5404E97D5F042F95F89F1C232871 CRC32: 1C291CA3
func SumString ¶
Example ¶
package main import ( "crypto/md5" "crypto/sha1" "fmt" "hash" "hash/crc32" "log" "github.com/northbright/hashelper" ) func main() { // Hash strings. strs := []string{ "", "Hello World!", } hashes := []hash.Hash{ md5.New(), sha1.New(), crc32.NewIEEE(), } hashFuncNames := []string{ "MD5", "SHA-1", "CRC32", } for _, str := range strs { checksums, summed, err := hashelper.SumString(str, hashes...) if err != nil { log.Printf("Sum() error: %v", err) return } fmt.Printf("Summed: %v bytes for \"%v\"\n", summed, str) for i, checksum := range checksums { fmt.Printf("%v: %X\n", hashFuncNames[i], checksum) } } }
Output: Summed: 0 bytes for "" MD5: D41D8CD98F00B204E9800998ECF8427E SHA-1: DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 CRC32: 00000000 Summed: 12 bytes for "Hello World!" MD5: ED076287532E86365E841E92BFC50D8C SHA-1: 2EF7BDE608CE5404E97D5F042F95F89F1C232871 CRC32: 1C291CA3
Types ¶
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
func (*Task) MarshalBinary ¶
func (*Task) UnmarshalBinary ¶
Click to show internal directories.
Click to hide internal directories.