go-hash

Wrap smaller hash libraries with interfaces similar to those in standard library hash interface.

See the source or godoc for more detailed documentation.

GitHub GitHub release (latest by date)

Background

The Go standard library defines the hash package. This package defines a Hash interface and then specific size interfaces are derived for Hash32 and Hash64. Subdirectories provide implementations of these interfaces for specific hash functions as well as the hashing function used by Go maps.

One nice feature (perhaps the nice feature) of the Hash interface is that it derives from io.Writer. This allows types that implement Hash to be used with io.Copy().

Implementation

This project provides missing interfaces:

  • Hash16
  • Hash8

and wrappers around pre-existing hash libraries that implement these interfaces.

  • github.com/madkins23/go-hash/pkg/sigurn/ccr8
  • github.com/madkins23/go-hash/pkg/sigurn/ccr16

Usage

import (
    crc8hash "github.com/madkins23/go-hash/pkg/sigurn/crc8"
    "github.com/sigurn/crc8" // needed to choose CRC variant
)

const someFile = "someFile.ext"

if file, err := os.Open(someFile); err == nil {
    h8 := crc8hash.New(crc8.CRC8)
    if _, err := io.Copy(h8, file); err == nil {
        fmt.Printf("%03d %s\n", h8.Sum8(), someFile)
    }
    _ = file.Close()
}

GitHub

View Github