crypto

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package crypto contains cryptographic utilities.

Index

Constants

View Source
const DefaultPSKLength = 32

DefaultPSKLength is the default length of a PSK.

Variables

View Source
var ErrInvalidSignature = fmt.Errorf("invalid signature")

ErrInvalidSignature is returned when a signature is invalid.

View Source
var ValidPSKChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

ValidPSKChars is the set of valid characters for a PSK.

Functions

func IsValidDefaultPSK added in v0.4.1

func IsValidDefaultPSK(s string) bool

IsValidDefaultPSK returns true if the given string is a valid PSK.

func IsValidPSK added in v0.4.1

func IsValidPSK(s string, length int) bool

IsValidPSK returns true if the given string is a valid PSK.

func IsValidPSKBytes added in v0.4.1

func IsValidPSKBytes(b []byte, length int) bool

IsValidPSKBytes returns true if the given byte slice is a valid PSK.

func Sign added in v0.4.1

func Sign(data []byte, psk PSK) ([]byte, error)

Sign signs the given data using the given PSK.

func Verify added in v0.4.1

func Verify(data, signature []byte, psk PSK) error

Verify verifies the given signature against the given data using the given PSK.

Types

type PSK

type PSK []byte

PSK is a pre-shared key.

func GeneratePSK

func GeneratePSK() (PSK, error)

GeneratePSK generates a PSK.

func GeneratePSKWithLength

func GeneratePSKWithLength(length int) (PSK, error)

GeneratePSKWithLength generates a PSK with a given length.

func MustGeneratePSK

func MustGeneratePSK() PSK

MustGeneratePSK generates a PSK and panics on error.

func (PSK) DeterministicSign added in v0.4.1

func (p PSK) DeterministicSign(data []byte) ([]byte, error)

DeterministicSign creates a signature of the given data using this PSK.

func (PSK) DeterministicSignatureSize added in v0.4.1

func (p PSK) DeterministicSignatureSize() int

func (PSK) DeterministicVerify added in v0.4.1

func (p PSK) DeterministicVerify(data, signature []byte) error

DeterministicVerify verifies the given signature against the given data using this PSK.

func (PSK) IsValid added in v0.4.1

func (p PSK) IsValid() bool

func (PSK) Sign added in v0.4.1

func (p PSK) Sign(data []byte) ([]byte, error)

Sign creates a signature of the given data using this PSK.

func (PSK) SignatureSize added in v0.4.1

func (p PSK) SignatureSize() int

func (PSK) String

func (p PSK) String() string

func (PSK) Verify added in v0.4.1

func (p PSK) Verify(data, signature []byte) error

Verify verifies the given signature against the given data using this PSK.

type Signer added in v0.4.1

type Signer interface {
	// Sign signs the given data.
	Sign(data []byte) ([]byte, error)
	// Verify verifies the given signature against the given data.
	Verify(data, signature []byte) error
	// SignatureSize returns the size of the signature.
	SignatureSize() int
}

Signer is a type that can sign data.

Jump to

Keyboard shortcuts

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