Documentation
¶
Index ¶
- Constants
- func FillRandom(buf []byte)
- func NewReader(kblob io.ReadSeeker, params KCodecParams) (unblob io.Reader, err error)
- func NewWriter(kblob io.WriteSeeker, resistType byte, cipherType byte, params KCodecParams) (unblob io.WriteCloser, err error)
- func ReadAllOf(reader io.Reader, buf []byte, offset int) (n int, err error)
- func ReadConfig(reader io.ReadSeeker, offset int64) (config *Config, resist KCodec, cipher KCodec, err error)
- func WriteAllOf(writer io.Writer, buf []byte, offset int) (n int, err error)
- type AeadConfig
- func (c *AeadConfig) ConfigEquals(other interface{}) bool
- func (c *AeadConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (inner io.Reader, innerLength int64, err error)
- func (c *AeadConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)
- func (c *AeadConfig) WriteConfig(writer io.Writer) (err error)
- type AeadReaderWorker
- type AeadWriterWorker
- type Config
- type KCodec
- type KCodecParams
- type KblobReader
- type KblobWriter
- type NullConfig
- func (c *NullConfig) ConfigEquals(other interface{}) bool
- func (c *NullConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (io.Reader, int64, error)
- func (c *NullConfig) NewWriter(outer io.Writer, params KCodecParams) (io.WriteCloser, error)
- func (c *NullConfig) WriteConfig(writer io.Writer) error
- type NullWriteCloser
- type ReaderWorker
- type RsConfig
- func (c *RsConfig) ConfigEquals(other interface{}) bool
- func (c *RsConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (inner io.Reader, innerLength int64, err error)
- func (c *RsConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)
- func (c *RsConfig) WriteConfig(writer io.Writer) (err error)
- type RsReaderWorker
- type RsWriterWorker
- type WorkerReader
- type WorkerWriter
- type WriterWorker
Constants ¶
View Source
const ( NonceSize = 12 PreludeSize = 16 )
View Source
const ( ResistType_None = byte(0) ResistType_Rs = byte(1) CipherType_None = byte(0) CipherType_Aead = byte(1) )
View Source
const (
ConfigSize = 32 // bytes
)
View Source
const (
CrcSize = 4
)
View Source
const (
CurrentVersion = byte(1)
)
View Source
const ( // The amount by which plaintext expanded into // ciphertext ExpansionAmount = 16 )
Variables ¶
This section is empty.
Functions ¶
func FillRandom ¶
func FillRandom(buf []byte)
func NewReader ¶
func NewReader(kblob io.ReadSeeker, params KCodecParams) (unblob io.Reader, err error)
Given a reader of a kblobbed output, creates a reader of the unblobbed contents. The kblob itself will contain its configuration.
func NewWriter ¶
func NewWriter(kblob io.WriteSeeker, resistType byte, cipherType byte, params KCodecParams) (unblob io.WriteCloser, err error)
Given a writer of where the user wants the kblobbed output to go and a configuration, creates a writer for unblobbed contents.
func ReadAllOf ¶
Reads bytes into buf starting at offset. Returns (count read, error), where the output count will only ever be less than the input buffer length (minus the offset) if we hit an error.
func ReadConfig ¶
Types ¶
type AeadConfig ¶
type AeadConfig struct {
// This is the size of the chunks of actual plaintext that
// we encrypt in one go.
//
// We actually encipher:
// - 16 bytes random
// - plaintext
//
// The data that we write to the
// underlying stream will consist of:
// - 12 bytes nonce
// - ciphertext
ChunkSize int64
Salt [8]byte
}
func NewAeadConfig ¶
func NewAeadConfig(chunkSize int64) (*AeadConfig, error)
func ReadAeadConfig ¶
func ReadAeadConfig(reader io.Reader) (*AeadConfig, error)
func (*AeadConfig) ConfigEquals ¶
func (c *AeadConfig) ConfigEquals(other interface{}) bool
func (*AeadConfig) NewReader ¶
func (c *AeadConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (inner io.Reader, innerLength int64, err error)
func (*AeadConfig) NewWriter ¶
func (c *AeadConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)
func (*AeadConfig) WriteConfig ¶
func (c *AeadConfig) WriteConfig(writer io.Writer) (err error)
type AeadReaderWorker ¶
type AeadWriterWorker ¶
type AeadWriterWorker struct {
Config *AeadConfig
Aead cipher.AEAD
CipherText io.Writer
Nonce, Chunk, Sealed, Ad []byte
}
func (*AeadWriterWorker) ChunkSize ¶
func (a *AeadWriterWorker) ChunkSize() int
func (*AeadWriterWorker) Close ¶
func (a *AeadWriterWorker) Close() error
type Config ¶
func (*Config) ConfigEquals ¶
type KCodec ¶
type KCodec interface {
// Checks for config equality.
ConfigEquals(other interface{}) bool
// This *must* write ConfigSize bytes.
WriteConfig(io.Writer) error
// Wraps a reader in a reader that decodes this kcodec
// and returns it and the expected length of the decoded
// data.
// (reader, length available, parameters).
NewReader(io.Reader, int64, KCodecParams) (io.Reader, int64, error)
// Wraps a writer in a writer that decodes this kcodec.
NewWriter(io.Writer, KCodecParams) (io.WriteCloser, error)
}
type KCodecParams ¶
type KCodecParams interface {
// Returns (data piece size, data piece count, parity piece count).
GetRsParams() (int, int, int)
GetAeadChunkSize() int
GetAeadPassword() string
}
How to fetch the optional parameters for the codecs. We'll only call these if necessary. On read, only parameters not encoded in the file (i.e. GetAeadPassword() ) will be called.
type KblobReader ¶
type KblobReader struct {
Kblob io.ReadSeeker
Length int64
Offset int64
}
func NewKblobReader ¶
func NewKblobReader(kblob io.ReadSeeker, bloblen int64) (*KblobReader, error)
type KblobWriter ¶
type KblobWriter struct {
Config *Config
Resist KCodec
Cipher KCodec
OuterWriter io.WriteSeeker
ResistWriter io.WriteCloser
CipherWriter io.WriteCloser
}
func (*KblobWriter) Close ¶
func (kb *KblobWriter) Close() (err error)
type NullConfig ¶
type NullConfig struct{}
func (*NullConfig) ConfigEquals ¶
func (c *NullConfig) ConfigEquals(other interface{}) bool
func (*NullConfig) NewReader ¶
func (c *NullConfig) NewReader(outer io.Reader, outerLength int64, params KCodecParams) (io.Reader, int64, error)
func (*NullConfig) NewWriter ¶
func (c *NullConfig) NewWriter(outer io.Writer, params KCodecParams) (io.WriteCloser, error)
func (*NullConfig) WriteConfig ¶
func (c *NullConfig) WriteConfig(writer io.Writer) error
type NullWriteCloser ¶
func (*NullWriteCloser) Close ¶
func (w *NullWriteCloser) Close() error
type ReaderWorker ¶
type RsConfig ¶
type RsConfig struct {
// The byte size of each piece, minus the CRC
DataPieceSize int32
// The number of data pieces in each separate
// RS matrix.
DataPieceCount int8
// The number of parity pieces in each separate
// RS matrix.
ParityPieceCount int8
// The total number of data bytes contained inside the
// reed-solomon encoding. (The encoded data may have
// been padded at the end.)
TotalInnerLength int64
}
func (*RsConfig) ConfigEquals ¶
func (*RsConfig) NewWriter ¶
func (c *RsConfig) NewWriter(outer io.Writer, params KCodecParams) (inner io.WriteCloser, err error)
type RsReaderWorker ¶
type RsWriterWorker ¶
type RsWriterWorker struct {
Config *RsConfig
ResistText io.Writer
Chunk []byte
Pieces [][]byte
PieceNum int
CrcTab *crc32.Table
Enc reedsolomon.Encoder
}
func (*RsWriterWorker) ChunkSize ¶
func (r *RsWriterWorker) ChunkSize() int
func (*RsWriterWorker) Close ¶
func (r *RsWriterWorker) Close() (err error)
type WorkerReader ¶
type WorkerReader struct {
Worker ReaderWorker
Bufs [2]bytes.Buffer
CurrentInputBuf int
Ready chan int
Error chan error
}
func NewAeadReader ¶
func NewAeadReader(config *AeadConfig, aead cipher.AEAD, outer io.Reader, outerLength int64) *WorkerReader
func NewRsReader ¶
func NewRsReader(config *RsConfig, outer io.Reader) *WorkerReader
func NewWorkerReader ¶
func NewWorkerReader(worker ReaderWorker) *WorkerReader
func (*WorkerReader) Decode ¶
func (w *WorkerReader) Decode(bufIdx int)
type WorkerWriter ¶
type WorkerWriter struct {
Worker WriterWorker
Bufs [2]bytes.Buffer
CurrentInputBuf int
Ready chan int
Finished chan error
}
func NewAeadWriter ¶
func NewAeadWriter(config *AeadConfig, aead cipher.AEAD, outer io.Writer) *WorkerWriter
func NewRsWriter ¶
func NewRsWriter(config *RsConfig, outer io.Writer) *WorkerWriter
func NewWorkerWriter ¶
func NewWorkerWriter(worker WriterWorker) *WorkerWriter
func (*WorkerWriter) Close ¶
func (w *WorkerWriter) Close() (err error)
func (*WorkerWriter) Encode ¶
func (w *WorkerWriter) Encode()
func (*WorkerWriter) UpdateConfig ¶
func (w *WorkerWriter) UpdateConfig(config KCodec)
type WriterWorker ¶
type WriterWorker interface {
// The chunk size to send to the worker;
// this should be a constant value.
ChunkSize() int
// Called whenever a chunk is ready, with a
// function that reads the chunk into a slice and
// returns how many bytes were read.
Ready(func([]byte) (int, error)) error
// Called at the end of the encode to finish up:
Close() error
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.