attachments

package
v5.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: BSD-3-Clause, BSD-3-Clause Imports: 56 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbortOnPartMismatch = errors.New("local part mismatch, aborting upload")

ErrAbortOnPartMismatch is returned when there is a mismatch between a current part and a previous attempt part. If ErrAbortOnPartMismatch is returned, the caller should abort the upload attempt and start from scratch.

View Source
var ErrPartNotFound = errors.New("part does not exist in stash")

Functions

func AddPendingPreview

func AddPendingPreview(ctx context.Context, g *globals.Context, obr *chat1.OutboxRecord) error

func AssetFromMessage

func AssetFromMessage(ctx context.Context, g *globals.Context, uid gregor1.UID, convID chat1.ConversationID,
	msgID chat1.MessageID, preview bool) (res chat1.Asset, err error)

func DetectMIMEType

func DetectMIMEType(ctx context.Context, src ReadResetter, filename string) (res string, err error)

func Download

func Download(ctx context.Context, g *globals.Context, uid gregor1.UID,
	convID chat1.ConversationID, messageID chat1.MessageID, sink io.WriteCloser, showPreview bool,
	progress func(int64, int64), ri func() chat1.RemoteInterface) (err error)

func GIFToPNG

func GIFToPNG(ctx context.Context, src io.Reader, dest io.Writer) error

func IsFatalImageErr

func IsFatalImageErr(err error) bool

func Quarantine

func Quarantine(ctx context.Context, path string) error

func SinkFromFilename

func SinkFromFilename(ctx context.Context, g *globals.Context, uid gregor1.UID,
	convID chat1.ConversationID, messageID chat1.MessageID,
	parentDir string, useArbitraryName bool) (string, io.WriteCloser, error)

func StatOSOrKbfsFile

func StatOSOrKbfsFile(ctx context.Context, g *libkb.GlobalContext, p string) (
	fi os.FileInfo, err error)

StatOSOrKbfsFile stats the file located at p, using SimpleFSStat if it's a KBFS path, or os.Stat if not.

Types

type AttachmentInfo

type AttachmentInfo struct {
	ObjectKey string                   // s3 destination
	EncKey    signencrypt.SecretboxKey // encryption key
	SignKey   signencrypt.SignKey      // signing key
	VerifyKey signencrypt.VerifyKey    // verification key
	Parts     map[int]string           // map of parts uploaded to S3, key == part number, value == hash of ciphertext
	StartedAt time.Time                // when the upload started
}

type AttachmentStash

type AttachmentStash interface {
	Start(key StashKey, info AttachmentInfo) error
	Lookup(key StashKey) (AttachmentInfo, bool, error)
	RecordPart(key StashKey, partNumber int, hash string) error
	Finish(key StashKey) error
}

type BufReadResetter

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

func NewBufReadResetter

func NewBufReadResetter(buf []byte) *BufReadResetter

func (*BufReadResetter) Read

func (b *BufReadResetter) Read(p []byte) (int, error)

func (*BufReadResetter) Reset

func (b *BufReadResetter) Reset() error

type Decrypter

type Decrypter interface {
	// Decrypt takes a ciphertext reader, encryption and verify keys.
	// It returns a plaintext reader.  It uses the constant nonce.
	Decrypt(ciphertext io.Reader, encKey, verifyKey []byte) (plaintext io.Reader)

	// DecryptWithNonce takes a ciphertext reader, nonce, encryption and verify keys.
	// It returns a plaintext reader.
	DecryptWithNonce(ciphertext io.Reader, nonce signencrypt.Nonce, encKey, verifyKey []byte) (plaintext io.Reader)
}

type Dimension

type Dimension struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

func (*Dimension) Empty

func (d *Dimension) Empty() bool

func (*Dimension) Encode

func (d *Dimension) Encode() string

type Encrypter

type Encrypter interface {
	// EncryptedLen returns the number of bytes that the ciphertext of
	// size plaintext bytes will be.
	EncryptedLen(size int) int

	// Encrypt takes a plaintext reader and returns a ciphertext reader.
	// It generates new keys every time it is called and uses a
	// constant nonce.
	Encrypt(plaintext io.Reader) (ciphertext io.Reader, err error)

	// EncryptWithNonce takes a plaintext reader and returns a ciphertext reader.
	// It generates new keys every time it is called and uses
	// the provided nonce.
	EncryptWithNonce(plaintext io.Reader, nonce signencrypt.Nonce) (ciphertext io.Reader, err error)

	// EncryptResume takes a plaintext reader and a set of keys.  It
	// returns a ciphertext reader.  It *does not* generate new keys
	// but uses the parameter keys.  These keys should *only* be used
	// to encrypt the same plaintext as a previous attempt.
	EncryptResume(r io.Reader, nonce signencrypt.Nonce, encKey signencrypt.SecretboxKey, signKey signencrypt.SignKey, verifyKey signencrypt.VerifyKey) (io.Reader, error)

	// EncryptKey returns the ephemeral key that was used during the
	// last invocation of Encrypt.
	EncryptKey() []byte

	// VerifyKey returns the public portion of the signing key used during
	// the last invocation of Encrypt.  It can be used for signature
	// verification.
	VerifyKey() []byte
}

type ErrorWrapper

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

func NewErrorWrapper

func NewErrorWrapper(prefix string, err error) *ErrorWrapper

func (*ErrorWrapper) Details

func (e *ErrorWrapper) Details() string

func (*ErrorWrapper) Error

func (e *ErrorWrapper) Error() string

type FileReadCloseResetter

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

func (*FileReadCloseResetter) Close

func (f *FileReadCloseResetter) Close() error

func (*FileReadCloseResetter) Read

func (f *FileReadCloseResetter) Read(p []byte) (int, error)

func (*FileReadCloseResetter) Reset

func (f *FileReadCloseResetter) Reset() error

type FileStash

type FileStash struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFileStash

func NewFileStash(dir string) *FileStash

func (*FileStash) Finish

func (f *FileStash) Finish(key StashKey) error

func (*FileStash) Lookup

func (f *FileStash) Lookup(key StashKey) (AttachmentInfo, bool, error)

func (*FileStash) RecordPart

func (f *FileStash) RecordPart(key StashKey, partNumber int, hash string) error

func (*FileStash) Start

func (f *FileStash) Start(key StashKey, info AttachmentInfo) error
type Gallery struct {
	globals.Contextified
	utils.DebugLabeler

	PrevStride, NextStride int
}

func NewGallery

func NewGallery(g *globals.Context) *Gallery

func (*Gallery) NextMessage

func (g *Gallery) NextMessage(ctx context.Context, uid gregor1.UID,
	convID chat1.ConversationID, msgID chat1.MessageID, opts NextMessageOptions) (res *chat1.MessageUnboxed, last bool, err error)

func (*Gallery) NextMessages

func (g *Gallery) NextMessages(ctx context.Context, uid gregor1.UID,
	convID chat1.ConversationID, msgID chat1.MessageID, num int, opts NextMessageOptions,
	uiCh chan chat1.UIMessage) (res []chat1.MessageUnboxed, last bool, err error)

type KbfsReadCloseResetter

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

KbfsReadCloseResetter is an implementation of ReadCloseResetter that uses SimpleFS as source of data.

func (*KbfsReadCloseResetter) Close

func (f *KbfsReadCloseResetter) Close() error

Close implements the ReadCloseResetter interface.

func (*KbfsReadCloseResetter) Read

func (f *KbfsReadCloseResetter) Read(p []byte) (int, error)

Read implements the ReadCloseResetter interface.

func (*KbfsReadCloseResetter) Reset

func (f *KbfsReadCloseResetter) Reset() error

Reset implements the ReadCloseResetter interface.

type NextMessageOptions

type NextMessageOptions struct {
	BackInTime  bool
	MessageType chat1.MessageType
	AssetTypes  []chat1.AssetMetadataType
	UnfurlTypes []chat1.UnfurlType
	FilterLinks bool
}

type PendingPreviews

type PendingPreviews struct {
	globals.Contextified
	utils.DebugLabeler
}

func NewPendingPreviews

func NewPendingPreviews(g *globals.Context) *PendingPreviews

func (*PendingPreviews) Get

func (p *PendingPreviews) Get(ctx context.Context, outboxID chat1.OutboxID) (res Preprocess, err error)

func (*PendingPreviews) Put

func (p *PendingPreviews) Put(ctx context.Context, outboxID chat1.OutboxID, pre Preprocess) (err error)

func (*PendingPreviews) Remove

func (p *PendingPreviews) Remove(ctx context.Context, outboxID chat1.OutboxID)

type Preprocess

type Preprocess struct {
	ContentType        string
	Preview            []byte
	PreviewContentType string
	BaseDim            *Dimension
	BaseDurationMs     int
	BaseIsAudio        bool
	PreviewDim         *Dimension
	PreviewAudioAmps   []float64
	PreviewDurationMs  int
}

func PreprocessAsset

func PreprocessAsset(ctx context.Context, g *globals.Context, log utils.DebugLabeler, src ReadResetter, filename string,
	nvh types.NativeVideoHelper, callerPreview *chat1.MakePreviewRes) (p Preprocess, err error)

func (*Preprocess) BaseMetadata

func (p *Preprocess) BaseMetadata() chat1.AssetMetadata

func (*Preprocess) Export

func (p *Preprocess) Export(getLocation func() *chat1.PreviewLocation) (res chat1.MakePreviewRes, err error)

func (*Preprocess) PreviewMetadata

func (p *Preprocess) PreviewMetadata() chat1.AssetMetadata

type PreviewRes

type PreviewRes struct {
	Source            []byte
	ContentType       string
	BaseWidth         int
	BaseHeight        int
	BaseDurationMs    int
	PreviewWidth      int
	PreviewHeight     int
	PreviewDurationMs int
}

func Preview

func Preview(ctx context.Context, log utils.DebugLabeler, src ReadResetter, contentType,
	basename string, nvh types.NativeVideoHelper) (res *PreviewRes, err error)

Preview creates preview assets from src. It returns an in-memory BufferSource and the content type of the preview asset.

type PutS3Result

type PutS3Result struct {
	Region   string
	Endpoint string
	Bucket   string
	Path     string
	Size     int64
}

PutS3Result is the success result of calling PutS3.

type ReadCloseResetter

type ReadCloseResetter interface {
	io.ReadCloser
	Reset() error
}

ReadCloseResetter is io.ReadCloser plus a Reset method. This is used by attachment uploads.

func NewFileReadCloseResetter

func NewFileReadCloseResetter(name string) (ReadCloseResetter, error)

NewFileReadCloseResetter creates a ReadCloseResetter that uses an on-disk file as source of data.

func NewKbfsReadCloseResetter

func NewKbfsReadCloseResetter(ctx context.Context, g *libkb.GlobalContext,
	kbfsPath string) (ReadCloseResetter, error)

NewKbfsReadCloseResetter creates a ReadCloseResetter that uses SimpleFS as source of data. kbfsPath must start with "/keybase/<tlf-type>/".

func NewReadCloseResetter

func NewReadCloseResetter(ctx context.Context, g *libkb.GlobalContext,
	p string) (ReadCloseResetter, error)

NewReadCloseResetter creates a ReadCloseResetter using either on-disk file or SimpleFS depending on if p is a KBFS path.

type ReadResetter

type ReadResetter interface {
	io.Reader
	Reset() error
}

type S3Signer

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

func NewS3Signer

func NewS3Signer(ri func() chat1.RemoteInterface) *S3Signer

func (*S3Signer) Sign

func (s *S3Signer) Sign(payload []byte) ([]byte, error)

Sign implements github.com/keybase/go/chat/s3.Signer interface.

type S3Store

type S3Store struct {
	globals.Contextified
	utils.DebugLabeler
	// contains filtered or unexported fields
}

func NewS3Store

func NewS3Store(g *globals.Context, runtimeDir string) *S3Store

NewS3Store creates a standard Store that uses a real S3 connection.

func NewStoreTesting

func NewStoreTesting(g *globals.Context, kt func(enc, sig []byte)) *S3Store

NewStoreTesting creates an Store suitable for testing purposes. It is not exposed outside this package. It uses an in-memory s3 interface, reports enc/sig keys, and allows limiting the number of blocks uploaded.

func (*S3Store) DecryptAsset

func (a *S3Store) DecryptAsset(ctx context.Context, w io.Writer, body io.Reader, asset chat1.Asset,
	progressReporter types.ProgressReporter) error

func (*S3Store) DeleteAsset

func (a *S3Store) DeleteAsset(ctx context.Context, params chat1.S3Params, signer s3.Signer, asset chat1.Asset) error

func (*S3Store) DeleteAssets

func (a *S3Store) DeleteAssets(ctx context.Context, params chat1.S3Params, signer s3.Signer, assets []chat1.Asset) error

func (*S3Store) DownloadAsset

func (a *S3Store) DownloadAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	w io.Writer, signer s3.Signer, progress types.ProgressReporter) error

DownloadAsset gets an object from S3 as described in asset.

func (*S3Store) GetAssetReader

func (a *S3Store) GetAssetReader(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	signer s3.Signer) (io.ReadCloser, error)

func (*S3Store) PutS3

func (a *S3Store) PutS3(ctx context.Context, r io.Reader, size int64, task *UploadTask, previous *AttachmentInfo) (res *PutS3Result, err error)

PutS3 uploads the data in Reader r to S3. It chooses whether to use putSingle or putMultiPipeline based on the size of the object.

func (*S3Store) StreamAsset

func (a *S3Store) StreamAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
	signer s3.Signer) (io.ReadSeeker, error)

func (*S3Store) UploadAsset

func (a *S3Store) UploadAsset(ctx context.Context, task *UploadTask, encryptedOut io.Writer) (res chat1.Asset, err error)

type Sender

type Sender struct {
	globals.Contextified
	utils.DebugLabeler
}

func NewSender

func NewSender(g *globals.Context) *Sender

func (*Sender) MakeAudioPreview

func (s *Sender) MakeAudioPreview(ctx context.Context, amps []float64, duration int) (res chat1.MakePreviewRes, err error)

func (*Sender) MakePreview

func (s *Sender) MakePreview(ctx context.Context, filename string, outboxID chat1.OutboxID) (res chat1.MakePreviewRes, err error)

func (*Sender) PostFileAttachment

func (s *Sender) PostFileAttachment(ctx context.Context, sender types.Sender, uid gregor1.UID,
	convID chat1.ConversationID, tlfName string, vis keybase1.TLFVisibility, inOutboxID *chat1.OutboxID,
	filename, title string, md []byte, clientPrev chat1.MessageID, ephemeralLifetime *gregor1.DurationSec,
	callerPreview *chat1.MakePreviewRes) (outboxID chat1.OutboxID, msgID *chat1.MessageID, err error)

func (*Sender) PostFileAttachmentMessage

func (s *Sender) PostFileAttachmentMessage(ctx context.Context, sender types.Sender,
	convID chat1.ConversationID, tlfName string, vis keybase1.TLFVisibility, inOutboxID *chat1.OutboxID,
	filename, title string, md []byte, clientPrev chat1.MessageID, ephemeralLifetime *gregor1.DurationSec,
	callerPreview *chat1.MakePreviewRes) (outboxID chat1.OutboxID, msgID *chat1.MessageID, err error)

type SignDecrypter

type SignDecrypter struct{}

func NewSignDecrypter

func NewSignDecrypter() *SignDecrypter

func (*SignDecrypter) Decrypt

func (s *SignDecrypter) Decrypt(r io.Reader, encKey, verifyKey []byte) io.Reader

func (*SignDecrypter) DecryptWithNonce

func (s *SignDecrypter) DecryptWithNonce(r io.Reader, nonce signencrypt.Nonce, encKey, verifyKey []byte) (plaintext io.Reader)

type SignEncrypter

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

func NewSignEncrypter

func NewSignEncrypter() *SignEncrypter

func (*SignEncrypter) Encrypt

func (s *SignEncrypter) Encrypt(r io.Reader) (io.Reader, error)

func (*SignEncrypter) EncryptKey

func (s *SignEncrypter) EncryptKey() []byte

func (*SignEncrypter) EncryptResume

func (s *SignEncrypter) EncryptResume(r io.Reader, nonce signencrypt.Nonce, encKey signencrypt.SecretboxKey, signKey signencrypt.SignKey, verifyKey signencrypt.VerifyKey) (io.Reader, error)

EncryptResume is used to create a SignEncrypter to resume an interrupted attachment upload. It is *very* important that the keys passed in are not used to encrypt different plaintext than their original usage.

func (*SignEncrypter) EncryptWithNonce

func (s *SignEncrypter) EncryptWithNonce(r io.Reader, nonce signencrypt.Nonce) (io.Reader, error)

func (*SignEncrypter) EncryptedLen

func (s *SignEncrypter) EncryptedLen(size int64) int64

func (*SignEncrypter) SignKey

func (s *SignEncrypter) SignKey() []byte

func (*SignEncrypter) VerifyKey

func (s *SignEncrypter) VerifyKey() []byte

type StashKey

type StashKey struct {
	OutboxID chat1.OutboxID
	Preview  bool
}

func NewStashKey

func NewStashKey(outboxID chat1.OutboxID, preview bool) StashKey

func (StashKey) String

func (s StashKey) String() string

type Store

type Store interface {
	UploadAsset(ctx context.Context, task *UploadTask, encryptedOut io.Writer) (chat1.Asset, error)
	DownloadAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset, w io.Writer,
		signer s3.Signer, progress types.ProgressReporter) error
	GetAssetReader(ctx context.Context, params chat1.S3Params, asset chat1.Asset,
		signer s3.Signer) (io.ReadCloser, error)
	StreamAsset(ctx context.Context, params chat1.S3Params, asset chat1.Asset, signer s3.Signer) (io.ReadSeeker, error)
	DecryptAsset(ctx context.Context, w io.Writer, body io.Reader, asset chat1.Asset,
		progress types.ProgressReporter) error
	DeleteAsset(ctx context.Context, params chat1.S3Params, signer s3.Signer, asset chat1.Asset) error
	DeleteAssets(ctx context.Context, params chat1.S3Params, signer s3.Signer, assets []chat1.Asset) error
}

type UploadTask

type UploadTask struct {
	S3Params  chat1.S3Params
	Filename  string
	FileSize  int64
	Plaintext ReadResetter

	S3Signer       s3.Signer
	ConversationID chat1.ConversationID
	UserID         gregor1.UID
	OutboxID       chat1.OutboxID
	Preview        bool
	Progress       types.ProgressReporter
	// contains filtered or unexported fields
}

func (*UploadTask) Nonce

func (u *UploadTask) Nonce() signencrypt.Nonce

type Uploader

type Uploader struct {
	globals.Contextified
	utils.DebugLabeler
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUploader

func NewUploader(g *globals.Context, store Store, s3signer s3.Signer,
	ri func() chat1.RemoteInterface, size int) *Uploader

func (*Uploader) Cancel

func (u *Uploader) Cancel(ctx context.Context, outboxID chat1.OutboxID) (err error)

func (*Uploader) CancelUploadTempFile

func (u *Uploader) CancelUploadTempFile(ctx context.Context, outboxID chat1.OutboxID) error

func (*Uploader) Complete

func (u *Uploader) Complete(ctx context.Context, outboxID chat1.OutboxID)

func (*Uploader) GetUploadTempFile

func (u *Uploader) GetUploadTempFile(ctx context.Context, outboxID chat1.OutboxID, filename string) (string, error)

func (*Uploader) GetUploadTempSink

func (u *Uploader) GetUploadTempSink(ctx context.Context, filename string) (*os.File, chat1.OutboxID, error)

func (*Uploader) OnDbNuke

func (u *Uploader) OnDbNuke(mctx libkb.MetaContext) error

func (*Uploader) Register

func (u *Uploader) Register(ctx context.Context, uid gregor1.UID, convID chat1.ConversationID,
	outboxID chat1.OutboxID, title, filename string, metadata []byte, callerPreview *chat1.MakePreviewRes) (res types.AttachmentUploaderResultCb, err error)

func (*Uploader) Retry

func (u *Uploader) Retry(ctx context.Context, outboxID chat1.OutboxID) (res types.AttachmentUploaderResultCb, err error)

func (*Uploader) SetPreviewTempDir

func (u *Uploader) SetPreviewTempDir(dir string)

func (*Uploader) Status

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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