hash

package
v0.0.0-...-015e77e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EncodeToSHA256 = func(buf []byte) (string, error) {
	hash, err := crypto.HashSHA256(buf)
	if err != nil {
		return "", err
	}
	return hex.EncodeToString(hash), nil
}

EncodeToSHA256 returns a sha256 hash of data as string.

Functions

func NewHashEncoder

func NewHashEncoder(name string, hashFn HashingFunction, encoder jsoniter.ValEncoder) jsoniter.ValEncoder

NewHashEncoder returns a string encoder that with encode string value using the supplied hashFn. The hash encoder will run before the other encoders, ensuring that struct fields are hashed first.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a ValEncoder strings that hashes string data with HashingFunction before encoding it to stream.

func (*Encoder) Encode

func (e *Encoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)

Encode writes the value of ptr to stream.

func (*Encoder) IsEmpty

func (e *Encoder) IsEmpty(ptr unsafe.Pointer) bool

IsEmpty returns true is ptr is empty, otherwise false.

func (*Encoder) SetLogger

func (e *Encoder) SetLogger(l log.Logger)

SetLogger changes the logger for the encoder.

type HashingFunction

type HashingFunction func(buf []byte) (hash string, err error)

HashingFunction defines the prototype for the hash callback. Defaults to EncodeToSHA256.

func FunctionForName

func FunctionForName(name tags.Hash) HashingFunction

FunctionForName returns the hash function for a given otherwise nil (passthrough).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL