stream

package
v2.4.10 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxBlobSize       = 2097152 // 2mb, or 2 * 2^20
	BlobHashSize      = sha512.Size384
	BlobHashHexLength = BlobHashSize * 2 // in hex, each byte is 2 chars
)

Variables

View Source
var ErrBlobEmpty = errors.Base("blob is empty")
View Source
var ErrBlobTooBig = errors.Base("blob must be at most " + strconv.Itoa(MaxBlobSize) + " bytes")

Functions

func DecryptBlob

func DecryptBlob(b Blob, key, iv []byte) ([]byte, error)

DecryptBlob decrypts a blob

func NullIV

func NullIV() []byte

NullIV returns an IV of 0s

Types

type Blob

type Blob []byte

func NewBlob

func NewBlob(data, key, iv []byte) (Blob, error)

func (Blob) Hash

func (b Blob) Hash() []byte

Hash returns a hash of the blob data

func (Blob) HashHex

func (b Blob) HashHex() string

HashHex returns th blob hash as a hex string

func (Blob) Plaintext

func (b Blob) Plaintext(key, iv []byte) ([]byte, error)

func (Blob) Size

func (b Blob) Size() int

func (Blob) ValidForSend

func (b Blob) ValidForSend() error

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) Hash

func (bi BlobInfo) Hash() []byte

Hash returns the hash of the blob info for calculating the stream hash

func (BlobInfo) MarshalJSON

func (bi BlobInfo) MarshalJSON() ([]byte, error)

func (*BlobInfo) UnmarshalJSON

func (bi *BlobInfo) UnmarshalJSON(b []byte) error

type BlobInfoAlias

type BlobInfoAlias BlobInfo

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) FromBlob

func (s *SDBlob) FromBlob(b Blob) error

FromBlob unmarshals a data Blob that should contain SDBlob data

func (SDBlob) IsValid

func (s SDBlob) IsValid() bool

IsValid returns true if the set StreamHash matches the current hash of the stream data

func (SDBlob) MarshalJSON

func (s SDBlob) MarshalJSON() ([]byte, error)

func (SDBlob) ToBlob

func (s SDBlob) ToBlob() (Blob, error)

ToBlob converts the SDBlob to a normal data Blob

func (*SDBlob) UnmarshalJSON

func (s *SDBlob) UnmarshalJSON(b []byte) error

type SDBlobAlias

type SDBlobAlias SDBlob

type Stream

type Stream []Blob

func New

func New(data []byte) (Stream, error)

New creates a new Stream from a byte slice

func NewWithStreamName added in v2.4.10

func NewWithStreamName(data []byte, streamName, suggestedFilename string) (Stream, error)

NewWithStreamName creates a new Stream from a byte slice

func NewWithTitle added in v2.4.8

func NewWithTitle(data []byte, title string) (Stream, error)

NewWithTitle creates a new Stream from a byte slice

func Reconstruct

func Reconstruct(data []byte, sdBlob SDBlob) (Stream, error)

Reconstruct creates a stream from the given data using predetermined IVs and key from the SD blob 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 (Stream) Data

func (s Stream) Data() ([]byte, error)

Jump to

Keyboard shortcuts

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