digest

package
v2.0.9-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2022 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 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 WithDigest

func WithDigest(digest string) Option

WithDigest sets the digest 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.

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