encrypted

package
v0.0.0-...-4a8f785 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package encrypted implements an encryption codec which encodes data by encrypting and authenticating with a cipher.AEAD instance.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

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

A Codec implements the encoded.Codec interface and encrypts and authenticates data using a cipher.AEAD instance.

func New

func New(aead cipher.AEAD, opts *Options) *Codec

New constructs an encryption codec that uses the given encryption context. If opts == nil, default options are used. New will panic if aead == nil.

For AES-GCM, you can use the cipher.NewGCM constructor. For ChaCha20-Poly1305 (RFC 8439) see golang.org/x/crypto/chacha20poly1304.

func (*Codec) Decode

func (c *Codec) Decode(w io.Writer, src []byte) error

Decode implements part of the codec interface. It decodes src from a wrapper block, decrypts the message, and writes the result to w. If decryption fails, an error is reported without writing any data to w.

func (*Codec) DecodedLen

func (c *Codec) DecodedLen(src []byte) (int, error)

DecodedLen implements part of the codec interface. It decodes src from a wrapper block, decrypts the original size, and returns it.

func (*Codec) Encode

func (c *Codec) Encode(w io.Writer, src []byte) error

Encode implements part of the codec interface. It encrypts src with the provided cipher in CTR mode and writes it out as an encoded block to w.

type Options

type Options struct {
	// Replace the contents of buf with cryptographically-secure random bytes.
	// If nil, the store uses the crypto/rand package to generate bytes.
	Random func(buf []byte) error
}

Options control the construction of a *Codec.

Jump to

Keyboard shortcuts

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