crypt

package
v0.0.0-...-bc25190 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2017 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package crypt provides wrappers for Fs and Object which implement encryption

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBadDecryptUTF8          = errors.New("bad decryption - utf-8 invalid")
	ErrorBadDecryptControlChar   = errors.New("bad decryption - contains control chars")
	ErrorNotAMultipleOfBlocksize = errors.New("not a multiple of blocksize")
	ErrorTooShortAfterDecode     = errors.New("too short after base32 decode")
	ErrorEncryptedFileTooShort   = errors.New("file is too short to be encrypted")
	ErrorEncryptedFileBadHeader  = errors.New("file has truncated block header")
	ErrorEncryptedBadMagic       = errors.New("not an encrypted file - bad magic string")
	ErrorEncryptedBadBlock       = errors.New("failed to authenticate decrypted block - bad password?")
	ErrorBadBase32Encoding       = errors.New("bad base32 filename encoding")
	ErrorFileClosed              = errors.New("file already closed")
	ErrorNotAnEncryptedFile      = errors.New("not an encrypted file - no \"" + encryptedSuffix + "\" suffix")
	ErrorBadSeek                 = errors.New("Seek beyond end of file")
)

Errors returned by cipher

Functions

func NewFs

func NewFs(name, rpath string) (fs.Fs, error)

NewFs contstructs an Fs from the path, container:path

Types

type Cipher

type Cipher interface {
	// EncryptFileName encrypts a file path
	EncryptFileName(string) string
	// DecryptFileName decrypts a file path, returns error if decrypt was invalid
	DecryptFileName(string) (string, error)
	// EncryptDirName encrypts a directory path
	EncryptDirName(string) string
	// DecryptDirName decrypts a directory path, returns error if decrypt was invalid
	DecryptDirName(string) (string, error)
	// EncryptData
	EncryptData(io.Reader) (io.Reader, error)
	// DecryptData
	DecryptData(io.ReadCloser) (io.ReadCloser, error)
	// DecryptDataSeek decrypt at a given position
	DecryptDataSeek(open OpenAtOffset, offset int64) (ReadSeekCloser, error)
	// EncryptedSize calculates the size of the data when encrypted
	EncryptedSize(int64) int64
	// DecryptedSize calculates the size of the data when decrypted
	DecryptedSize(int64) (int64, error)
}

Cipher is used to swap out the encryption implementations

type Fs

type Fs struct {
	fs.Fs
	// contains filtered or unexported fields
}

Fs represents a wrapped fs.Fs

func (*Fs) CleanUp

func (f *Fs) CleanUp() error

CleanUp the trash in the Fs

Implement this if you have a way of emptying the trash or otherwise cleaning up old versions of files.

func (*Fs) ComputeHash

func (f *Fs) ComputeHash(o *Object, src fs.Object, hashType fs.HashType) (hash string, err error)

ComputeHash takes the nonce from o, and encrypts the contents of src with it, and calcuates the hash given by HashType on the fly

Note that we break lots of encapsulation in this function.

func (*Fs) Copy

func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error)

Copy src to this remote using server side copy operations.

This is stored with the remote path given

It returns the destination Object and a possible error

Will only be called if src.Fs().Name() == f.Name()

If it isn't possible then return fs.ErrorCantCopy

func (*Fs) DirMove

func (f *Fs) DirMove(src fs.Fs, srcRemote, dstRemote string) error

DirMove moves src, srcRemote to this remote at dstRemote using server side move operations.

Will only be called if src.Fs().Name() == f.Name()

If it isn't possible then return fs.ErrorCantDirMove

If destination exists then return fs.ErrorDirExists

func (*Fs) Features

func (f *Fs) Features() *fs.Features

Features returns the optional features of this Fs

func (*Fs) Hashes

func (f *Fs) Hashes() fs.HashSet

Hashes returns the supported hash sets.

func (*Fs) List

func (f *Fs) List(opts fs.ListOpts, dir string)

List the Fs into a channel

func (*Fs) Mkdir

func (f *Fs) Mkdir(dir string) error

Mkdir makes the directory (container, bucket)

Shouldn't return an error if it already exists

func (*Fs) Move

func (f *Fs) Move(src fs.Object, remote string) (fs.Object, error)

Move src to this remote using server side move operations.

This is stored with the remote path given

It returns the destination Object and a possible error

Will only be called if src.Fs().Name() == f.Name()

If it isn't possible then return fs.ErrorCantMove

func (*Fs) Name

func (f *Fs) Name() string

Name of the remote (as passed into NewFs)

func (*Fs) NewObject

func (f *Fs) NewObject(remote string) (fs.Object, error)

NewObject finds the Object at remote.

func (*Fs) Purge

func (f *Fs) Purge() error

Purge all files in the root and the root directory

Implement this if you have a way of deleting all the files quicker than just running Remove() on the result of List()

Return an error if it doesn't exist

func (*Fs) Put

func (f *Fs) Put(in io.Reader, src fs.ObjectInfo) (fs.Object, error)

Put in to the remote path with the modTime given of the given size

May create the object even if it returns an error - if so will return the object and the error, otherwise will return nil and the error

func (*Fs) PutUnchecked

func (f *Fs) PutUnchecked(in io.Reader, src fs.ObjectInfo) (fs.Object, error)

PutUnchecked uploads the object

This will create a duplicate if we upload a new file without checking to see if there is one already - use Put() for that.

func (*Fs) Rmdir

func (f *Fs) Rmdir(dir string) error

Rmdir removes the directory (container, bucket) if empty

Return an error if it doesn't exist or isn't empty

func (*Fs) Root

func (f *Fs) Root() string

Root of the remote (as passed into NewFs)

func (*Fs) String

func (f *Fs) String() string

String returns a description of the FS

func (*Fs) UnWrap

func (f *Fs) UnWrap() fs.Fs

UnWrap returns the Fs that this Fs is wrapping

type ListOpts

type ListOpts struct {
	fs.ListOpts
	// contains filtered or unexported fields
}

ListOpts wraps a listopts decrypting the directory listing and replacing the Objects

func (*ListOpts) Add

func (lo *ListOpts) Add(obj fs.Object) (abort bool)

Add an object to the output. If the function returns true, the operation has been aborted. Multiple goroutines can safely add objects concurrently.

func (*ListOpts) AddDir

func (lo *ListOpts) AddDir(dir *fs.Dir) (abort bool)

AddDir adds a directory to the output. If the function returns true, the operation has been aborted. Multiple goroutines can safely add objects concurrently.

func (*ListOpts) IncludeDirectory

func (lo *ListOpts) IncludeDirectory(remote string) bool

IncludeDirectory returns whether this directory should be included in the listing (and recursed into or not).

func (*ListOpts) Level

func (lo *ListOpts) Level() int

Level gets the recursion level for this listing.

Fses may ignore this, but should implement it for improved efficiency if possible.

Level 1 means list just the contents of the directory

Each returned item must have less than level `/`s in.

type NameEncryptionMode

type NameEncryptionMode int

NameEncryptionMode is the type of file name encryption in use

const (
	NameEncryptionOff NameEncryptionMode = iota
	NameEncryptionStandard
	NameEncryptionObfuscated
)

NameEncryptionMode levels

func NewNameEncryptionMode

func NewNameEncryptionMode(s string) (mode NameEncryptionMode, err error)

NewNameEncryptionMode turns a string into a NameEncryptionMode

func (NameEncryptionMode) String

func (mode NameEncryptionMode) String() (out string)

String turns mode into a human readable string

type Object

type Object struct {
	fs.Object
	// contains filtered or unexported fields
}

Object describes a wrapped for being read from the Fs

This decrypts the remote name and decrypts the data

func (*Object) Fs

func (o *Object) Fs() fs.Info

Fs returns read only access to the Fs that this object is part of

func (*Object) Hash

func (o *Object) Hash(hash fs.HashType) (string, error)

Hash returns the selected checksum of the file If no checksum is available it returns ""

func (*Object) Open

func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error)

Open opens the file for read. Call Close() on the returned io.ReadCloser

func (*Object) Remote

func (o *Object) Remote() string

Remote returns the remote path

func (*Object) Size

func (o *Object) Size() int64

Size returns the size of the file

func (*Object) String

func (o *Object) String() string

Return a string version

func (*Object) UnWrap

func (o *Object) UnWrap() fs.Object

UnWrap returns the wrapped Object

func (*Object) Update

func (o *Object) Update(in io.Reader, src fs.ObjectInfo) error

Update in to the object with the modTime given of the given size

type ObjectInfo

type ObjectInfo struct {
	fs.ObjectInfo
	// contains filtered or unexported fields
}

ObjectInfo describes a wrapped fs.ObjectInfo for being the source

This encrypts the remote name and adjusts the size

func (*ObjectInfo) Fs

func (o *ObjectInfo) Fs() fs.Info

Fs returns read only access to the Fs that this object is part of

func (*ObjectInfo) Hash

func (o *ObjectInfo) Hash(hash fs.HashType) (string, error)

Hash returns the selected checksum of the file If no checksum is available it returns ""

func (*ObjectInfo) Remote

func (o *ObjectInfo) Remote() string

Remote returns the remote path

func (*ObjectInfo) Size

func (o *ObjectInfo) Size() int64

Size returns the size of the file

type OpenAtOffset

type OpenAtOffset func(offset int64) (io.ReadCloser, error)

OpenAtOffset opens the file handle at the offset given

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

ReadSeekCloser is the interface of the read handles

Directories

Path Synopsis
Package pkcs7 implements PKCS#7 padding
Package pkcs7 implements PKCS#7 padding

Jump to

Keyboard shortcuts

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