Code Monkey home page Code Monkey logo

ion-hash-go's Introduction

** 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.

ion-hash-go's People

Contributors

amazon-auto avatar byronlin13 avatar justing-bq avatar therapon avatar zslayton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.