algorithm

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeSigningError      errors.GoCode = "signing.signature.error"
	ErrorCodeBadSignature      errors.GoCode = "signing.signature.bad"
	ErrorCodeSignatureMisMatch errors.GoCode = "signing.signature.mismatch"
	ErrorCodeSignatureExpired  errors.GoCode = "signing.signature.expired"
	ErrorSignerAlgorithm       errors.GoCode = "signing.signer.algorithm"
)

Variables

View Source
var (
	ErrSigning = errors.New(
		ErrorCodeSigningError,
		"error signing data",
	)
	ErrBadSignature = errors.New(
		ErrorCodeBadSignature,
		"bad signature",
		ErrSigning,
	)
	ErrSignatureMismatch = errors.New(
		ErrorCodeSignatureMisMatch,
		"signature mismatch",
		ErrBadSignature,
	)
	ErrSignatureExpired = errors.New(
		ErrorCodeSignatureExpired,
		"signature expired",
		ErrBadSignature,
	)

	ErrUnknownSignatureAlgorithm = errors.New(
		ErrorSignerAlgorithm,
		"unknown signature algorithm",
		ErrSigning,
	)
)

Functions

func DecodeString

func DecodeString(s string) ([]byte, error)

func EncodeToString

func EncodeToString(data []byte) string

func RegisterSignatureAlgos

func RegisterSignatureAlgos(algo ...Algorithm)

Types

type Algorithm

type Algorithm interface {
	Name() string
	Signature(ctx context.Context, data, salt, key []byte) ([]byte, error)
	Verify(ctx context.Context, data, signature, salt, key []byte) error
}

func GetSignatureAlgo

func GetSignatureAlgo(name string) (Algorithm, bool)

func NewSignatureAlgorithm

func NewSignatureAlgorithm(name string, hashFunc func() hash.Hash) Algorithm

type SignatureAlgorithm

type SignatureAlgorithm struct {
	Algorithm   string
	SignatureFn func(ctx context.Context, data, salt, key []byte) ([]byte, error)
	VerifyFn    func(ctx context.Context, data, signature []byte, salt, key []byte) error
}

func (*SignatureAlgorithm) Name

func (s *SignatureAlgorithm) Name() string

func (*SignatureAlgorithm) Signature

func (s *SignatureAlgorithm) Signature(ctx context.Context, data, salt, key []byte) ([]byte, error)

func (*SignatureAlgorithm) Verify

func (s *SignatureAlgorithm) Verify(ctx context.Context, data, signature []byte, salt, key []byte) error

Jump to

Keyboard shortcuts

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