Categorygithub.com/amzn/ion-hash-go
modulepackage
1.2.0
Repository: https://github.com/amzn/ion-hash-go.git
Documentation: pkg.go.dev

# README

** This package is considered beta. While the API is relatively stable it is still subject to change. **

Amazon Ion Hash Go

An implementation of Amazon Ion Hash in Go.

build license docs

Getting Started

You can start using ion-hash-go by simply importing it, e.g.,


import (
	ionhash "github.com/amzn/ion-hash-go"
)

Generating a hash while reading


// Create a hasher provider, using MD5
hasherProvider := ionhash.NewCryptoHasherProvider("MD5")

// Create an Ion reader over the input [1,2,3]
ionReader := ion.NewReaderString("[1,2,3]")

// Create a hash reader
hashReader, err := ionhash.NewHashReader(ionReader, hasherProvider)
if err != nil {
	panic(err)
}

// Read over the top level value and calculate its hash
hashReader.Next()
hashReader.Next()


// Get the hash value
res, err := hashReader.Sum(nil)
if err != nil {
	panic(err)
}

// Print out the hash in Hex
fmt.Printf("Digest = %x\n", res) // prints: Digest = 8f3bf4b1935cf469c9c10c31524b2625

Generating a hash while writing


// Create a hasher provider, using MD5
hasherProvider := ionhash.NewCryptoHasherProvider("MD5")

// Create an Ion writer
ionWriter := ion.NewTextWriter(new(bytes.Buffer))

// Create a hash writer
hashWriter, err := ionhash.NewHashWriter(ionWriter, hasherProvider)
if err != nil {
	panic(err)
}

// Write the list [1,2,3]
hashWriter.BeginList()
hashWriter.WriteInt(1)
hashWriter.WriteInt(2)
hashWriter.WriteInt(3)
hashWriter.EndList()

// Get the hash value
res, err := hashWriter.Sum(nil)
if err != nil {
	panic(err)
}

// Print out the hash in Hex
fmt.Printf("Digest = %x\n", res) // prints: Digest = 8f3bf4b1935cf469c9c10c31524b2625/

Development

This package uses Go Modules to model its dependencies.

Assuming the go command is in your path, building the module can be done as:

$ go build -v ./...

Running all the tests can be executed with:

$ go test -v ./...

We use goimports to format our imports and files in general. Running this before commit is advised:

$ goimports -w .

It is recommended that you hook this in your favorite IDE (Tools > File Watchers in Goland, for example).

Known Issues

< No current known issues >

License

This library is licensed under the Apache-2.0 License.

# Packages

No description provided by the author

# Functions

NewCryptoHasherProvider returns a new CryptoHasherProvider for the provided algorithm.
NewHashReader takes an Ion reader and a hash provider and returns a new HashReader.
NewHashWriter takes an Ion Writer and a hash provider and returns a new HashWriter.

# Constants

Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.
Constants for each of the algorithm names supported.

# Structs

CryptoHasherProvider struct for crypto hasher provider.
InvalidArgumentError is returned when one of the arguments given to a function was not valid.
InvalidIonTypeError is returned when processing an unexpected Ion type.
An InvalidOperationError is returned when a method call is invalid for the struct's current state.
UnknownSymbolError is returned when processing an unknown field name symbol.

# Interfaces

A HashReader reads a stream of Ion values and calculates its hash.
A HashWriter writes a stream of Ion values and calculates its hash.
IonHasher inherits functions from Ion Writer and adds the Sum function.
IonHasherProvider is used for creating new instances of IonHasher.

# Type aliases

Algorithm is the name of the hash algorithm used to calculate the hash.