digest

package
v2.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AlgorithmSHA1 is sha1 algorithm name of hash.
	AlgorithmSHA1 = "sha1"

	// AlgorithmSHA256 is sha256 algorithm name of hash.
	AlgorithmSHA256 = "sha256"

	// AlgorithmSHA512 is sha512 algorithm name of hash.
	AlgorithmSHA512 = "sha512"

	// AlgorithmMD5 is md5 algorithm name of hash.
	AlgorithmMD5 = "md5"
)

Variables

This section is empty.

Functions

func HashFile

func HashFile(path string, algorithm string) (string, error)

HashFile computes hash value corresponding to algorithm.

func MD5FromBytes

func MD5FromBytes(bytes []byte) string

MD5FromBytes computes the MD5 checksum with []byte.

func MD5FromReader

func MD5FromReader(reader io.Reader) string

MD5FromReader computes the MD5 checksum with io.Reader.

func SHA256FromBytes added in v2.0.30

func SHA256FromBytes(bytes []byte) string

SHA256FromBytes computes the SHA256 checksum with []byte.

func SHA256FromStrings

func SHA256FromStrings(data ...string) string

SHA256FromStrings computes the SHA256 checksum with multiple strings.

Types

type Digest

type Digest struct {
	// Algorithm is hash algorithm.
	Algorithm string

	// Encoded is hash encode.
	Encoded string
}

Digest provides digest operation function.

func New

func New(algorithm, encoded string) *Digest

New return digest instance.

func Parse

func Parse(digest string) (*Digest, error)

Parse uses to parse digest string to algorithm and encoded.

func (*Digest) String

func (d *Digest) String() string

String return digest string.

type Option

type Option func(reader *reader)

Option is a functional option for digest reader.

func WithEncoded added in v2.0.9

func WithEncoded(encoded string) Option

WithEncoded sets the encoded to be verified.

func WithLogger

func WithLogger(logger *logger.SugaredLoggerOnWith) Option

WithLogger sets the logger for digest reader.

type Reader

type Reader interface {
	io.Reader
	Encoded() string
}

Reader is the interface used for reading resource.

func NewReader

func NewReader(algorithm string, r io.Reader, options ...Option) (Reader, error)

NewReader creates digest reader.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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