Documentation
¶
Index ¶
- Constants
- Variables
- func ArmoredEncoder(out io.Writer, blockType string, headers map[string]string) (io.WriteCloser, error)
- func ChainCloser(c io.Closer, wc io.WriteCloser) io.WriteCloser
- func Compress(w io.Writer, c Compressor) (io.WriteCloser, error)
- func Dearmor(in io.Reader) (string, map[string]string, io.Reader, error)
- func DecodeBinary(r io.Reader, v any) error
- func DecodeBinaryNew[T any](r io.Reader) (*T, error)
- func Decompress(r io.Reader, alg Compression, opts DecompressOpts) (io.Reader, error)
- func Decrypt(r io.Reader, passphrase string, iv IV, salt []byte, params Argon2Params) *cipher.StreamReader
- func DetermineArmor(in io.Reader) (bool, io.Reader, error)
- func EncodeBinary(w io.Writer, v any) error
- func Encrypt(w io.Writer, passphrase string, iv IV, salt []byte, params Argon2Params) *cipher.StreamWriter
- func MarshalBinary(v any) ([]byte, error)
- func NewPassphrased(passphrase string, iv IV, salt []byte, params Argon2Params) cipher.Stream
- func NopCloser(w io.Writer) io.WriteCloser
- func Pack(out io.Writer, v Packable, opts ...Option) error
- func RegisterCompression(alg Compression, decompress Decompressor)
- func RegisterPacketType(typ PacketType)
- func UnmarshalBinary(data []byte, v any) error
- func UnmarshalBinaryNew[T any](data []byte) (*T, error)
- func Unpack(in io.Reader, opts ...UnpackOption) (Tag, Packable, error)
- func UnpackExact[T Packable](in io.Reader, opts ...UnpackOption) (val T, err error)
- type Argon2Params
- type ArmoredBlock
- type Compression
- type Compressor
- type CustomDecoder
- type CustomEncoder
- type Decoder
- type DecompressOpts
- type Decompressor
- type Encoder
- type Encryption
- type ErrMismatchType
- type IV
- type Lz4Opts
- type Option
- type Packable
- type Packet
- type PacketType
- type RawMessage
- type Stream
- type Tag
- type UnpackOption
Constants ¶
const ( IVSize = aes.BlockSize TimeRFC = 1 // draft RFC recommended number of rounds MemoryRFC = 64 * 1024 // draft RFC recommended memory cost SaltSizeRFC = 16 // draft RFC recommended salt size for password hashing )
passphrased consts
Variables ¶
var ErrUnknownTag = errors.New("unknown tag")
ErrUnknownTag is returned when a tag is unknown.
var ErrUnsupportedCompression = errors.New("unsupported compression algorithm")
ErrUnsupportedCompression is returned when unsupported compression algorithm is used.
Functions ¶
func ArmoredEncoder ¶
func ArmoredEncoder(out io.Writer, blockType string, headers map[string]string) (io.WriteCloser, error)
ArmoredEncoder returns an OpenPGP armored encoder.
func ChainCloser ¶
func ChainCloser(c io.Closer, wc io.WriteCloser) io.WriteCloser
ChainCloser chains the wc to c.
func Compress ¶
func Compress(w io.Writer, c Compressor) (io.WriteCloser, error)
Compress compresses a writer.
func Dearmor ¶ added in v0.2.0
Dearmor determines if an input is an OpenPGP armored block and decodes it. It does nothing if the input is not an OpenPGP armored block.
func DecodeBinary ¶
DecodeBinary decodes an object from binary MessagePack format.
func DecodeBinaryNew ¶
DecodeBinaryNew allocates and decodes an object from binary MessagePack format.
func Decompress ¶
func Decompress(r io.Reader, alg Compression, opts DecompressOpts) (io.Reader, error)
Decompress decompresses a reader.
func Decrypt ¶
func Decrypt(r io.Reader, passphrase string, iv IV, salt []byte, params Argon2Params) *cipher.StreamReader
Decrypt wraps a NewPassphrased stream cipher with cipher.StreamReader.
func DetermineArmor ¶
DetermineArmor determines if an input is an OpenPGP armored block. It returns multireader with peeked data.
func EncodeBinary ¶
EncodeBinary encodes an object into binary MessagePack format.
func Encrypt ¶
func Encrypt(w io.Writer, passphrase string, iv IV, salt []byte, params Argon2Params) *cipher.StreamWriter
Encrypt wraps a NewPassphrased stream cipher with cipher.StreamWriter.
func MarshalBinary ¶ added in v0.2.0
MarshalBinary encodes an object into binary MessagePack format.
func NewPassphrased ¶
NewPassphrased returns a new stream cipher with derived key. Panics if the passphrase is empty.
func NopCloser ¶
func NopCloser(w io.Writer) io.WriteCloser
NopCloser is analog of io.NopCloser but for io.Writer.
func RegisterCompression ¶ added in v0.1.3
func RegisterCompression(alg Compression, decompress Decompressor)
RegisterCompression registers a compression algorithm.
func RegisterPacketType ¶
func RegisterPacketType(typ PacketType)
RegisterPacketType registers a packet type.
func UnmarshalBinary ¶ added in v0.2.0
UnmarshalBinary decodes an object from binary MessagePack format.
func UnmarshalBinaryNew ¶ added in v0.2.0
UnmarshalBinaryNew allocates and decodes an object from binary MessagePack format.
func UnpackExact ¶
func UnpackExact[T Packable](in io.Reader, opts ...UnpackOption) (val T, err error)
UnpackExact decodes an object from binary format and casts it to specified type.
Types ¶
type Argon2Params ¶
type Argon2Params struct { Time uint32 `msgpack:"time"` // argon2id number of rounds Memory uint32 `msgpack:"memory"` // argon2id memory cost Threads uint8 `msgpack:"threads"` // argon2id parallelism degree }
Argon2Params contains parameters for argon2id.
func Argon2Defaults ¶
func Argon2Defaults() Argon2Params
Argon2Defaults returns recommended parameters for argon2id.
type ArmoredBlock ¶
ArmoredBlock represents an OpenPGP armored block.
func DecodeArmored ¶
func DecodeArmored(in io.Reader) (*ArmoredBlock, error)
DecodeArmored decodes an OpenPGP armored block.
type Compression ¶
type Compression byte
Compression represents compression algorithm.
const ( NoCompression Compression = iota CompressionDeflate CompressionZstd CompressionLz4 )
compression algorithms.
type Compressor ¶ added in v0.1.3
type Compressor interface { Algorithm() Compression Compress(w io.Writer) (io.WriteCloser, error) }
Compressor represents a compressor.
type CustomDecoder ¶
type CustomDecoder = msgpack.CustomDecoder
CustomDecoder is an alias for msgpack.CustomDecoder.
type CustomEncoder ¶
type CustomEncoder = msgpack.CustomEncoder
CustomEncoder is an alias for msgpack.CustomEncoder.
type DecompressOpts ¶ added in v0.1.3
type DecompressOpts interface {
DecompressOpts()
}
DecompressOpts represents decompress options.
type Decompressor ¶ added in v0.1.3
Decompressor represents a decompressor func.
type Encryption ¶
type Encryption struct { IV IV `msgpack:"iv"` Salt []byte `msgpack:"salt"` Argon2ID Argon2Params `msgpack:"argon2"` }
Encryption contains encryption parameters.
type ErrMismatchType ¶ added in v0.1.1
type ErrMismatchType struct {
// contains filtered or unexported fields
}
ErrMismatchType is returned when the object type mismatches the expected one.
func (ErrMismatchType) Error ¶ added in v0.1.1
func (e ErrMismatchType) Error() string
type Lz4Opts ¶ added in v0.1.3
type Lz4Opts struct { // if == 0, runtime.GOMAXPROCS(0) is used Threads uint }
Lz4Opts contains optional parameters for lz4.
func (Lz4Opts) DecompressOpts ¶ added in v0.1.3
func (Lz4Opts) DecompressOpts()
DecompressOpts func.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option represents packing option.
func WithCompression ¶
func WithCompression(c Compressor) Option
WithCompression compresses a packet.
func WithEncryption ¶
func WithEncryption(passphrase string, params *Encryption) Option
WithEncryption encrypts a packet. If params is nil, random values are used.
type Packet ¶
type Packet struct { Tag Tag Header struct { Encryption *Encryption `msgpack:"encryption,omitempty"` Compression Compression `msgpack:"compression,omitempty"` } Object Stream // contains filtered or unexported fields }
Packet is a binary packet.
type PacketType ¶
type PacketType struct { Tag Tag // Must be a settable for the msgpack. // A pointer to this type must implement the Packable interface. Type reflect.Type Name string BlockType string }
PacketType represents a binary packet type.
type RawMessage ¶ added in v0.2.0
type RawMessage[T any] struct { msgpack.RawMessage }
RawMessage represents a raw msgpack message which can be unpacked into specified type.
func (RawMessage[T]) Unpack ¶ added in v0.2.0
func (r RawMessage[T]) Unpack() (*T, error)
type Stream ¶ added in v0.2.0
Stream represents a msgpack bytes stream. It must be the last field in the message.
func (*Stream) DecodeMsgpack ¶ added in v0.2.0
DecodeMsgpack implements msgpack.CustomDecoder.
func (*Stream) EncodeMsgpack ¶ added in v0.2.0
EncodeMsgpack implements msgpack.CustomEncoder.
type Tag ¶
type Tag byte
Tag is used to determine the binary packet type.
const TagInvalid Tag = 0x00
TagInvalid is used to indicate an invalid tag.
type UnpackOption ¶
type UnpackOption interface {
// contains filtered or unexported methods
}
UnpackOption represents unpacking option.
func WithDecompressionOpts ¶
func WithDecompressionOpts(opts map[Compression]DecompressOpts) UnpackOption
WithDecompressionOpts decompresses a packet using provided options.
func WithPassphrase ¶
func WithPassphrase(passphrase func() (string, error)) UnpackOption
WithPassphrase decrypts a packet if it is encrypted. passphrase func called only if the packet is encrypted. Panics if passphrase is nil.