crypto

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HmacSha256

func HmacSha256(ctx context.Context, data []byte, cipher wrapping.Wrapper, opt ...wrapping.Option) (string, error)

HmacSha256 the provided data. Supports WithSalt, WithInfo, WithPrefix, WithEd25519, WithPrk, WithMarshaledSigInfo, WithBase64Encoding, WithBase58Encoding options. WithEd25519 is a "legacy" way to complete this operation and should not be used in new operations unless backward compatibility is needed. The WithPrefix option will prepend the prefix to the hmac-sha256 value.

func HmacSha256WithPrk

func HmacSha256WithPrk(ctx context.Context, data, prk []byte, opt ...wrapping.Option) (string, error)

HmacSha256WithPrk will HmacSha256 using the provided prk. See HmacSha256 for options supported.

func NewDerivedReader

func NewDerivedReader(ctx context.Context, wrapper wrapping.Wrapper, lenLimit int64, opt ...wrapping.Option) (*io.LimitedReader, error)

DerivedReader returns a reader from which keys can be read, using the given wrapper, reader length limit, salt and context info. Salt and info can be nil.

Example:

reader, _ := crypto.NewDerivedReader(wrapper, userId, jobId)
key := ed25519.GenerateKey(reader)

func Sha256Sum

func Sha256Sum(ctx context.Context, r io.Reader, opt ...wrapping.Option) ([]byte, error)

Sha256Sum computes SHA256 message digest. Options supported: WithHexEncoding (which is compatible/comparable with GNU sha256sum's output)

func TestHmacSha256

func TestHmacSha256(t *testing.T, key, data []byte, opt ...wrapping.Option) string

TestHmacSha256 produces a test hmac sha256. Supported options: WithBase64Encoding, WithBase58Encoding, WithPrefix

func TestWithBlake2b

func TestWithBlake2b(t *testing.T, data []byte, w wrapping.Wrapper, opt ...wrapping.Option) string

TestWithBlake2b produces a test hmac sha256 using derived blake2b. Supported options: WithPrk, WithBase64Encoding, WithBase58Encoding, WithMarshaledSigInfo

func TestWithEd25519

func TestWithEd25519(t *testing.T, data []byte, w wrapping.Wrapper, opt ...wrapping.Option) string

TestWithEd25519 produces test hmac sha256 using a derived Ed25519 key

func WithBase58Encoding

func WithBase58Encoding() wrapping.Option

WithBase58Encoding allows an optional request to base58 encode the data returned

func WithBase64Encoding

func WithBase64Encoding() wrapping.Option

WithBase64Encoding allows an optional request to base64 encode the data returned

func WithEd25519

func WithEd25519() wrapping.Option

WithEd25519 allows an optional request to use ed25519 during the operation

func WithHexEncoding

func WithHexEncoding(withHexEncoding bool) wrapping.Option

WithHexEncoding allows an optional request to use hex encoding.

func WithInfo

func WithInfo(info []byte) wrapping.Option

WithInfo allows optional info to be specified for an operation.

func WithMarshaledSigInfo

func WithMarshaledSigInfo() wrapping.Option

WithMarshaledSigInfo allows an optional request to wrap the returned data into a marshaled wrapping.SigInfo protobuf

func WithPrefix

func WithPrefix(prefix string) wrapping.Option

WithPrefix allows an optional prefix to be specified for the data returned

func WithPrk

func WithPrk(prk []byte) wrapping.Option

WithPrk allows an optional PRK (pseudorandom key) to be specified for an operation. If you're using this option with HmacSha256, you might consider using HmacSha256WithPrk instead.

func WithSalt

func WithSalt(salt []byte) wrapping.Option

WithSalt allows optional salt to be specified for an operation.

Types

type OptionFunc

type OptionFunc func(*options) error

OptionFunc holds a function with local options

type Sha256SumReader

type Sha256SumReader struct {
	// contains filtered or unexported fields
}

Sha256SumReader provides an io.Reader which can be used to calculate a sum while reading a file. It implements io.ReaderCloser.

func NewSha256SumReader

func NewSha256SumReader(_ context.Context, r io.Reader) (*Sha256SumReader, error)

NewSha256SumReader creates a new Sha256Reader.

func (*Sha256SumReader) Close

func (r *Sha256SumReader) Close() error

Close checks to see if the Sha256SumReader's io.Reader implements the optional io.Closer and if so, then Close() is called; otherwise this is a noop

func (*Sha256SumReader) Read

func (r *Sha256SumReader) Read(b []byte) (int, error)

func (*Sha256SumReader) Sum

func (r *Sha256SumReader) Sum(_ context.Context, opt ...wrapping.Option) ([]byte, error)

Sum will sum the hash. Options supported: WithHexEncoding

type Sha256SumWriter

type Sha256SumWriter struct {
	// contains filtered or unexported fields
}

Sha256SumWriter provides multi-writer which will be used to write to a hash and produce a sum. It implements io.WriterCloser and io.StringWriter.

func NewSha256SumWriter

func NewSha256SumWriter(ctx context.Context, w io.Writer) (*Sha256SumWriter, error)

NewSha256SumWriter creates a new Sha256SumWriter

func (*Sha256SumWriter) Close

func (w *Sha256SumWriter) Close() error

Close checks to see if the Sha256SumWriter implements the optional io.Closer and if so, then Close() is called; otherwise this is a noop

func (*Sha256SumWriter) Sum

func (w *Sha256SumWriter) Sum(_ context.Context, opt ...wrapping.Option) ([]byte, error)

Sum will sum the hash. Options supported: WithHexEncoding

func (*Sha256SumWriter) Write

func (w *Sha256SumWriter) Write(b []byte) (int, error)

Write will write the bytes to the hash. Implements the required io.Writer func.

func (*Sha256SumWriter) WriteString

func (w *Sha256SumWriter) WriteString(s string) (int, error)

WriteString will write the string to hash.

Jump to

Keyboard shortcuts

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