Documentation ¶
Index ¶
Constants ¶
const ( MaxBlobSize = 2097152 // 2mb, or 2 * 2^20 BlobHashSize = sha512.Size384 BlobHashHexLength = BlobHashSize * 2 // in hex, each byte is 2 chars )
Variables ¶
var ErrBlobEmpty = errors.New("blob is empty")
var ErrBlobTooBig = errors.Newf("blob must be at most %d bytes", MaxBlobSize)
Functions ¶
func DecryptBlob ¶
DecryptBlob decrypts a blob
Types ¶
type Blob ¶
type Blob []byte
func (Blob) ValidForSend ¶
ValidForSend returns true if the blob size is within the limits
type BlobInfo ¶
type BlobInfo struct { Length int `json:"length"` BlobNum int `json:"blob_num"` BlobHash []byte `json:"-"` IV []byte `json:"-"` }
BlobInfo is the stream descriptor info for a single blob in a stream Encoding to and from JSON is customized to match existing behavior (see json.go in package)
func (BlobInfo) MarshalJSON ¶
func (*BlobInfo) UnmarshalJSON ¶
type BlobInfoAlias ¶
type BlobInfoAlias BlobInfo
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder reads bytes from a source and returns blobs of the stream
func NewEncoderFromSD ¶
NewEncoderFromSD creates a new encoder that reuses cryptographic material from an sd blob This can be used to reconstruct a stream exactly from a file NOTE: this will assume that all blobs except the last one are at max length. in theory this is not required, but in practice this is always true. if this is false, streams may not match exactly
func NewEncoderWithIVs ¶
NewEncoderWithIVs creates a new encoder that uses preset cryptographic material
func (*Encoder) Next ¶
Next reads the next chunk of data, encodes it into a blob, and adds it to the stream When the source is fully consumed, Next() makes sure the stream is terminated (i.e. the sd blob ends with an empty terminating blob) and returns io.EOF
func (*Encoder) SourceHash ¶
SourceHash returns a hash of the bytes read from source
func (*Encoder) SourceSizeHint ¶
SourceSizeHint sets a hint about the total size of the source This helps allocate RAM more efficiently. If the hint is wrong, it still works fine but there will be a small performance penalty.
type JSONBlobInfo ¶
type JSONBlobInfo struct { BlobInfoAlias BlobHash string `json:"blob_hash,omitempty"` IV string `json:"iv"` }
type JSONSDBlob ¶
type JSONSDBlob struct { StreamName string `json:"stream_name"` SDBlobAlias Key string `json:"key"` SuggestedFileName string `json:"suggested_file_name"` StreamHash string `json:"stream_hash"` }
type SDBlob ¶
type SDBlob struct { StreamName string `json:"-"` BlobInfos []BlobInfo `json:"blobs"` StreamType string `json:"stream_type"` Key []byte `json:"-"` SuggestedFileName string `json:"-"` StreamHash []byte `json:"-"` }
SDBlob contains information about the rest of the blobs in the stream Encoding to and from JSON is customized to match existing behavior (see json.go in package)
func (SDBlob) IsValid ¶
IsValid returns true if the set StreamHash matches the current hash of the stream data
func (SDBlob) MarshalJSON ¶
func (*SDBlob) UnmarshalJSON ¶
type SDBlobAlias ¶
type SDBlobAlias SDBlob