hashutil

package module
v0.0.0-...-8bcc6da Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 6 Imported by: 1

README

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

Usage

type Md5
type Md5 []byte

Md5 type represents Md5 checksum

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

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

func EmptyMd5
func EmptyMd5() Md5

EmptyMd5 return Md5 of empty file

func HashToMd5
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
func StringToMd5(hexString string) (Md5, error)

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

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

Equal return true if is Md5s equal

func (Md5) IsEmpty
func (h Md5) IsEmpty() bool

IsEmpty return true if is Md5 'empty hash'

func (Md5) String
func (h Md5) String() string

String return (hex) string representation of Md5

func (Md5) ToBase64
func (h Md5) ToBase64() string

ToBase64 return base64 representation of Md5

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

ToBytes return []byte of hashutil.Md5

func (Md5) UpperString
func (h Md5) UpperString() string

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

type Sha1
type Sha1 []byte

Sha1 type represents Sha1 checksum

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

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

func EmptySha1
func EmptySha1() Sha1

EmptySha1 return Sha1 of empty file

func HashToSha1
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
func StringToSha1(hexString string) (Sha1, error)

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

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

Equal return true if is Sha1s equal

func (Sha1) IsEmpty
func (h Sha1) IsEmpty() bool

IsEmpty return true if is Sha1 'empty hash'

func (Sha1) String
func (h Sha1) String() string

String return (hex) string representation of Sha1

func (Sha1) ToBase64
func (h Sha1) ToBase64() string

ToBase64 return base64 representation of Sha1

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

ToBytes return []byte of hashutil.Sha1

func (Sha1) UpperString
func (h Sha1) UpperString() string

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

type Sha256
type Sha256 []byte

Sha256 type represents Sha256 checksum

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

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

func EmptySha256
func EmptySha256() Sha256

EmptySha256 return Sha256 of empty file

func HashToSha256
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
func StringToSha256(hexString string) (Sha256, error)

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

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

Equal return true if is Sha256s equal

func (Sha256) IsEmpty
func (h Sha256) IsEmpty() bool

IsEmpty return true if is Sha256 'empty hash'

func (Sha256) String
func (h Sha256) String() string

String return (hex) string representation of Sha256

func (Sha256) ToBase64
func (h Sha256) ToBase64() string

ToBase64 return base64 representation of Sha256

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

ToBytes return []byte of hashutil.Sha256

func (Sha256) UpperString
func (h Sha256) UpperString() string

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

type Sha384
type Sha384 []byte

Sha384 type represents Sha384 checksum

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

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

func EmptySha384
func EmptySha384() Sha384

EmptySha384 return Sha384 of empty file

func HashToSha384
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
func StringToSha384(hexString string) (Sha384, error)

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

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

Equal return true if is Sha384s equal

func (Sha384) IsEmpty
func (h Sha384) IsEmpty() bool

IsEmpty return true if is Sha384 'empty hash'

func (Sha384) String
func (h Sha384) String() string

String return (hex) string representation of Sha384

func (Sha384) ToBase64
func (h Sha384) ToBase64() string

ToBase64 return base64 representation of Sha384

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

ToBytes return []byte of hashutil.Sha384

func (Sha384) UpperString
func (h Sha384) UpperString() string

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

type Sha512
type Sha512 []byte

Sha512 type represents Sha512 checksum

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

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

func EmptySha512
func EmptySha512() Sha512

EmptySha512 return Sha512 of empty file

func HashToSha512
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
func StringToSha512(hexString string) (Sha512, error)

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

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

Equal return true if is Sha512s equal

func (Sha512) IsEmpty
func (h Sha512) IsEmpty() bool

IsEmpty return true if is Sha512 'empty hash'

func (Sha512) String
func (h Sha512) String() string

String return (hex) string representation of Sha512

func (Sha512) ToBase64
func (h Sha512) ToBase64() string

ToBase64 return base64 representation of Sha512

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

ToBytes return []byte of hashutil.Sha512

func (Sha512) UpperString
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.

Documentation

Overview

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

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Md5

type Md5 []byte

Md5 type represents Md5 checksum

func BytesToMd5

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

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

func EmptyMd5

func EmptyMd5() Md5

EmptyMd5 return Md5 of empty file

func HashToMd5

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

func StringToMd5(hexString string) (Md5, error)

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

func (Md5) Equal

func (h Md5) Equal(o Md5) bool

Equal return true if is Md5s equal

func (Md5) IsEmpty

func (h Md5) IsEmpty() bool

IsEmpty return true if is Md5 'empty hash'

func (Md5) String

func (h Md5) String() string

String return (hex) string representation of Md5

func (Md5) ToBase64

func (h Md5) ToBase64() string

ToBase64 return base64 representation of Md5

func (Md5) ToBytes

func (h Md5) ToBytes() []byte

ToBytes return []byte of hashutil.Md5

func (Md5) UpperString

func (h Md5) UpperString() string

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

type Sha1

type Sha1 []byte

Sha1 type represents Sha1 checksum

func BytesToSha1

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

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

func EmptySha1

func EmptySha1() Sha1

EmptySha1 return Sha1 of empty file

func HashToSha1

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

func StringToSha1(hexString string) (Sha1, error)

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

func (Sha1) Equal

func (h Sha1) Equal(o Sha1) bool

Equal return true if is Sha1s equal

func (Sha1) IsEmpty

func (h Sha1) IsEmpty() bool

IsEmpty return true if is Sha1 'empty hash'

func (Sha1) String

func (h Sha1) String() string

String return (hex) string representation of Sha1

func (Sha1) ToBase64

func (h Sha1) ToBase64() string

ToBase64 return base64 representation of Sha1

func (Sha1) ToBytes

func (h Sha1) ToBytes() []byte

ToBytes return []byte of hashutil.Sha1

func (Sha1) UpperString

func (h Sha1) UpperString() string

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

type Sha256

type Sha256 []byte

Sha256 type represents Sha256 checksum

func BytesToSha256

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

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

func EmptySha256

func EmptySha256() Sha256

EmptySha256 return Sha256 of empty file

func HashToSha256

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

func StringToSha256(hexString string) (Sha256, error)

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

func (Sha256) Equal

func (h Sha256) Equal(o Sha256) bool

Equal return true if is Sha256s equal

func (Sha256) IsEmpty

func (h Sha256) IsEmpty() bool

IsEmpty return true if is Sha256 'empty hash'

func (Sha256) String

func (h Sha256) String() string

String return (hex) string representation of Sha256

func (Sha256) ToBase64

func (h Sha256) ToBase64() string

ToBase64 return base64 representation of Sha256

func (Sha256) ToBytes

func (h Sha256) ToBytes() []byte

ToBytes return []byte of hashutil.Sha256

func (Sha256) UpperString

func (h Sha256) UpperString() string

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

type Sha384

type Sha384 []byte

Sha384 type represents Sha384 checksum

func BytesToSha384

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

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

func EmptySha384

func EmptySha384() Sha384

EmptySha384 return Sha384 of empty file

func HashToSha384

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

func StringToSha384(hexString string) (Sha384, error)

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

func (Sha384) Equal

func (h Sha384) Equal(o Sha384) bool

Equal return true if is Sha384s equal

func (Sha384) IsEmpty

func (h Sha384) IsEmpty() bool

IsEmpty return true if is Sha384 'empty hash'

func (Sha384) String

func (h Sha384) String() string

String return (hex) string representation of Sha384

func (Sha384) ToBase64

func (h Sha384) ToBase64() string

ToBase64 return base64 representation of Sha384

func (Sha384) ToBytes

func (h Sha384) ToBytes() []byte

ToBytes return []byte of hashutil.Sha384

func (Sha384) UpperString

func (h Sha384) UpperString() string

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

type Sha512

type Sha512 []byte

Sha512 type represents Sha512 checksum

func BytesToSha512

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

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

func EmptySha512

func EmptySha512() Sha512

EmptySha512 return Sha512 of empty file

func HashToSha512

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

func StringToSha512(hexString string) (Sha512, error)

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

func (Sha512) Equal

func (h Sha512) Equal(o Sha512) bool

Equal return true if is Sha512s equal

func (Sha512) IsEmpty

func (h Sha512) IsEmpty() bool

IsEmpty return true if is Sha512 'empty hash'

func (Sha512) String

func (h Sha512) String() string

String return (hex) string representation of Sha512

func (Sha512) ToBase64

func (h Sha512) ToBase64() string

ToBase64 return base64 representation of Sha512

func (Sha512) ToBytes

func (h Sha512) ToBytes() []byte

ToBytes return []byte of hashutil.Sha512

func (Sha512) UpperString

func (h Sha512) UpperString() string

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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