Hashutil is collection of common hash (crypto) types. It also contains some helper functions for hash manipulation.
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.
import (
"github.com/avast/hashutil-go",
"crypto/md5"
)
hash, _ := hashutil.StringToMd5("d41d8cd98f00b204e9800998ecf8427e")
otherHash, _ := hashutil.BytesToMd5(md5.New().Sum(nil))
// or
// otherhash := hashutil.EmptyMd5()
if hash.Equal(otherHash) {
// do something
}
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
type Md5 []byte
Md5 type represents Md5 checksum
func BytesToMd5(bytes []byte) (Md5, error)
BytesToMd5 return a new Md5 checksum from bytes (binary) representation
func EmptyMd5() Md5
EmptyMd5 return Md5 of empty file
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(hexString string) (Md5, error)
StringToMd5 return a new Md5 checksum from string (hex) representation
func (h Md5) Equal(o Md5) bool
Equal return true if is Md5s equal
func (h Md5) IsEmpty() bool
IsEmpty return true if is Md5 ‘empty hash’
func (h Md5) String() string
String return (hex) string representation of Md5
func (h Md5) ToBase64() string
ToBase64 return base64 representation of Md5
func (h Md5) ToBytes() []byte
ToBytes return []byte of hashutil.Md5
func (h Md5) UpperString() string
UpperString return (hex) string representation in upper case of Md5
type Sha1 []byte
Sha1 type represents Sha1 checksum
func BytesToSha1(bytes []byte) (Sha1, error)
BytesToSha1 return a new Sha1 checksum from bytes (binary) representation
func EmptySha1() Sha1
EmptySha1 return Sha1 of empty file
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(hexString string) (Sha1, error)
StringToSha1 return a new Sha1 checksum from string (hex) representation
func (h Sha1) Equal(o Sha1) bool
Equal return true if is Sha1s equal
func (h Sha1) IsEmpty() bool
IsEmpty return true if is Sha1 ‘empty hash’
func (h Sha1) String() string
String return (hex) string representation of Sha1
func (h Sha1) ToBase64() string
ToBase64 return base64 representation of Sha1
func (h Sha1) ToBytes() []byte
ToBytes return []byte of hashutil.Sha1
func (h Sha1) UpperString() string
UpperString return (hex) string representation in upper case of Sha1
type Sha256 []byte
Sha256 type represents Sha256 checksum
func BytesToSha256(bytes []byte) (Sha256, error)
BytesToSha256 return a new Sha256 checksum from bytes (binary) representation
func EmptySha256() Sha256
EmptySha256 return Sha256 of empty file
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(hexString string) (Sha256, error)
StringToSha256 return a new Sha256 checksum from string (hex) representation
func (h Sha256) Equal(o Sha256) bool
Equal return true if is Sha256s equal
func (h Sha256) IsEmpty() bool
IsEmpty return true if is Sha256 ‘empty hash’
func (h Sha256) String() string
String return (hex) string representation of Sha256
func (h Sha256) ToBase64() string
ToBase64 return base64 representation of Sha256
func (h Sha256) ToBytes() []byte
ToBytes return []byte of hashutil.Sha256
func (h Sha256) UpperString() string
UpperString return (hex) string representation in upper case of Sha256
type Sha384 []byte
Sha384 type represents Sha384 checksum
func BytesToSha384(bytes []byte) (Sha384, error)
BytesToSha384 return a new Sha384 checksum from bytes (binary) representation
func EmptySha384() Sha384
EmptySha384 return Sha384 of empty file
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(hexString string) (Sha384, error)
StringToSha384 return a new Sha384 checksum from string (hex) representation
func (h Sha384) Equal(o Sha384) bool
Equal return true if is Sha384s equal
func (h Sha384) IsEmpty() bool
IsEmpty return true if is Sha384 ‘empty hash’
func (h Sha384) String() string
String return (hex) string representation of Sha384
func (h Sha384) ToBase64() string
ToBase64 return base64 representation of Sha384
func (h Sha384) ToBytes() []byte
ToBytes return []byte of hashutil.Sha384
func (h Sha384) UpperString() string
UpperString return (hex) string representation in upper case of Sha384
type Sha512 []byte
Sha512 type represents Sha512 checksum
func BytesToSha512(bytes []byte) (Sha512, error)
BytesToSha512 return a new Sha512 checksum from bytes (binary) representation
func EmptySha512() Sha512
EmptySha512 return Sha512 of empty file
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(hexString string) (Sha512, error)
StringToSha512 return a new Sha512 checksum from string (hex) representation
func (h Sha512) Equal(o Sha512) bool
Equal return true if is Sha512s equal
func (h Sha512) IsEmpty() bool
IsEmpty return true if is Sha512 ‘empty hash’
func (h Sha512) String() string
String return (hex) string representation of Sha512
func (h Sha512) ToBase64() string
ToBase64 return base64 representation of Sha512
func (h Sha512) ToBytes() []byte
ToBytes return []byte of hashutil.Sha512
func (h Sha512) UpperString() string
UpperString return (hex) string representation in upper case of Sha512
Contributions are very much welcome.
Makefile provides several handy rules, like README.md generator
, setup
for prepare build/dev environment, test
, cover
, etc…
Try make help
for more information.
please try:
make test
)make lint
)go fmt
, run go fmt
(make fmt
)README.md are generate from template .godocdown.tmpl and code documentation via godocdown.
Never edit README.md direct, because your change will be lost.