项目作者: JaSei

项目描述 :
Hashutil is collection of common hash (crypto) types. It also contains some helper functions for hash manipulation.
高级语言: Go
项目地址: git://github.com/JaSei/hashutil-go.git
创建时间: 2017-09-19T15:34:12Z
项目社区:https://github.com/JaSei/hashutil-go

开源协议:MIT License

下载


hashutil

Release
Software License
Travis
Go Report Card
GoDoc
codecov.io
Sourcegraph
GolangCI

Package hashutil is collection of common hash (crypto) types. It also contains
some helper functions for hash manipulation.

Supports Md5, Sha1, Sha256, Sha384, Sha512.

For support other crypto functions please do PR or issue.

SYNOPSIS

  1. import (
  2. "github.com/avast/hashutil-go",
  3. "crypto/md5"
  4. )
  5. hash, _ := hashutil.StringToMd5("d41d8cd98f00b204e9800998ecf8427e")
  6. otherHash, _ := hashutil.BytesToMd5(md5.New().Sum(nil))
  7. // or
  8. // otherhash := hashutil.EmptyMd5()
  9. if hash.Equal(otherHash) {
  10. // do something
  11. }

Code generated by github.com/jasei/hashutil/generator DO NOT EDIT

Code generated by github.com/jasei/hashutil/generator DO NOT EDIT

Code generated by github.com/jasei/hashutil/generator DO NOT EDIT

Code generated by github.com/jasei/hashutil/generator DO NOT EDIT

Code generated by github.com/jasei/hashutil/generator DO NOT EDIT

Usage

type Md5

  1. type Md5 []byte

Md5 type represents Md5 checksum

func BytesToMd5

  1. func BytesToMd5(bytes []byte) (Md5, error)

BytesToMd5 return a new Md5 checksum from bytes (binary) representation

func EmptyMd5

  1. func EmptyMd5() Md5

EmptyMd5 return Md5 of empty file

func HashToMd5

  1. func HashToMd5(h hash.Hash) (Md5, error)

HashToMd5 return a new Md5 checksum from hash.Hash representation HashToMd5
convert hashutil.Hash to Md5

func StringToMd5

  1. func StringToMd5(hexString string) (Md5, error)

StringToMd5 return a new Md5 checksum from string (hex) representation

func (Md5) Equal

  1. func (h Md5) Equal(o Md5) bool

Equal return true if is Md5s equal

func (Md5) IsEmpty

  1. func (h Md5) IsEmpty() bool

IsEmpty return true if is Md5 ‘empty hash’

func (Md5) String

  1. func (h Md5) String() string

String return (hex) string representation of Md5

func (Md5) ToBase64

  1. func (h Md5) ToBase64() string

ToBase64 return base64 representation of Md5

func (Md5) ToBytes

  1. func (h Md5) ToBytes() []byte

ToBytes return []byte of hashutil.Md5

func (Md5) UpperString

  1. func (h Md5) UpperString() string

UpperString return (hex) string representation in upper case of Md5

type Sha1

  1. type Sha1 []byte

Sha1 type represents Sha1 checksum

func BytesToSha1

  1. func BytesToSha1(bytes []byte) (Sha1, error)

BytesToSha1 return a new Sha1 checksum from bytes (binary) representation

func EmptySha1

  1. func EmptySha1() Sha1

EmptySha1 return Sha1 of empty file

func HashToSha1

  1. func HashToSha1(h hash.Hash) (Sha1, error)

HashToSha1 return a new Sha1 checksum from hash.Hash representation HashToSha1
convert hashutil.Hash to Sha1

func StringToSha1

  1. func StringToSha1(hexString string) (Sha1, error)

StringToSha1 return a new Sha1 checksum from string (hex) representation

func (Sha1) Equal

  1. func (h Sha1) Equal(o Sha1) bool

Equal return true if is Sha1s equal

func (Sha1) IsEmpty

  1. func (h Sha1) IsEmpty() bool

IsEmpty return true if is Sha1 ‘empty hash’

func (Sha1) String

  1. func (h Sha1) String() string

String return (hex) string representation of Sha1

func (Sha1) ToBase64

  1. func (h Sha1) ToBase64() string

ToBase64 return base64 representation of Sha1

func (Sha1) ToBytes

  1. func (h Sha1) ToBytes() []byte

ToBytes return []byte of hashutil.Sha1

func (Sha1) UpperString

  1. func (h Sha1) UpperString() string

UpperString return (hex) string representation in upper case of Sha1

type Sha256

  1. type Sha256 []byte

Sha256 type represents Sha256 checksum

func BytesToSha256

  1. func BytesToSha256(bytes []byte) (Sha256, error)

BytesToSha256 return a new Sha256 checksum from bytes (binary) representation

func EmptySha256

  1. func EmptySha256() Sha256

EmptySha256 return Sha256 of empty file

func HashToSha256

  1. func HashToSha256(h hash.Hash) (Sha256, error)

HashToSha256 return a new Sha256 checksum from hash.Hash representation
HashToSha256 convert hashutil.Hash to Sha256

func StringToSha256

  1. func StringToSha256(hexString string) (Sha256, error)

StringToSha256 return a new Sha256 checksum from string (hex) representation

func (Sha256) Equal

  1. func (h Sha256) Equal(o Sha256) bool

Equal return true if is Sha256s equal

func (Sha256) IsEmpty

  1. func (h Sha256) IsEmpty() bool

IsEmpty return true if is Sha256 ‘empty hash’

func (Sha256) String

  1. func (h Sha256) String() string

String return (hex) string representation of Sha256

func (Sha256) ToBase64

  1. func (h Sha256) ToBase64() string

ToBase64 return base64 representation of Sha256

func (Sha256) ToBytes

  1. func (h Sha256) ToBytes() []byte

ToBytes return []byte of hashutil.Sha256

func (Sha256) UpperString

  1. func (h Sha256) UpperString() string

UpperString return (hex) string representation in upper case of Sha256

type Sha384

  1. type Sha384 []byte

Sha384 type represents Sha384 checksum

func BytesToSha384

  1. func BytesToSha384(bytes []byte) (Sha384, error)

BytesToSha384 return a new Sha384 checksum from bytes (binary) representation

func EmptySha384

  1. func EmptySha384() Sha384

EmptySha384 return Sha384 of empty file

func HashToSha384

  1. func HashToSha384(h hash.Hash) (Sha384, error)

HashToSha384 return a new Sha384 checksum from hash.Hash representation
HashToSha384 convert hashutil.Hash to Sha384

func StringToSha384

  1. func StringToSha384(hexString string) (Sha384, error)

StringToSha384 return a new Sha384 checksum from string (hex) representation

func (Sha384) Equal

  1. func (h Sha384) Equal(o Sha384) bool

Equal return true if is Sha384s equal

func (Sha384) IsEmpty

  1. func (h Sha384) IsEmpty() bool

IsEmpty return true if is Sha384 ‘empty hash’

func (Sha384) String

  1. func (h Sha384) String() string

String return (hex) string representation of Sha384

func (Sha384) ToBase64

  1. func (h Sha384) ToBase64() string

ToBase64 return base64 representation of Sha384

func (Sha384) ToBytes

  1. func (h Sha384) ToBytes() []byte

ToBytes return []byte of hashutil.Sha384

func (Sha384) UpperString

  1. func (h Sha384) UpperString() string

UpperString return (hex) string representation in upper case of Sha384

type Sha512

  1. type Sha512 []byte

Sha512 type represents Sha512 checksum

func BytesToSha512

  1. func BytesToSha512(bytes []byte) (Sha512, error)

BytesToSha512 return a new Sha512 checksum from bytes (binary) representation

func EmptySha512

  1. func EmptySha512() Sha512

EmptySha512 return Sha512 of empty file

func HashToSha512

  1. func HashToSha512(h hash.Hash) (Sha512, error)

HashToSha512 return a new Sha512 checksum from hash.Hash representation
HashToSha512 convert hashutil.Hash to Sha512

func StringToSha512

  1. func StringToSha512(hexString string) (Sha512, error)

StringToSha512 return a new Sha512 checksum from string (hex) representation

func (Sha512) Equal

  1. func (h Sha512) Equal(o Sha512) bool

Equal return true if is Sha512s equal

func (Sha512) IsEmpty

  1. func (h Sha512) IsEmpty() bool

IsEmpty return true if is Sha512 ‘empty hash’

func (Sha512) String

  1. func (h Sha512) String() string

String return (hex) string representation of Sha512

func (Sha512) ToBase64

  1. func (h Sha512) ToBase64() string

ToBase64 return base64 representation of Sha512

func (Sha512) ToBytes

  1. func (h Sha512) ToBytes() []byte

ToBytes return []byte of hashutil.Sha512

func (Sha512) UpperString

  1. func (h Sha512) UpperString() string

UpperString return (hex) string representation in upper case of Sha512

Contributing

Contributions are very much welcome.

Makefile

Makefile provides several handy rules, like README.md generator , setup for prepare build/dev environment, test, cover, etc…

Try make help for more information.

Before pull request

please try:

  • run tests (make test)
  • run linter (make lint)
  • if your IDE don’t automaticaly do go fmt, run go fmt (make fmt)

README

README.md are generate from template .godocdown.tmpl and code documentation via godocdown.

Never edit README.md direct, because your change will be lost.