Documentation
¶
Index ¶
- Constants
- Variables
- func DecryptedSize(size int64) (int64, error)
- func EncryptedSize(size int64) int64
- func ExtractPasswordAndSalt(password string) (string, string)
- func GenerateKey(password, salt string) (*key, error)
- func NewNameEncoding(s string) (enc fileNameEncoding, err error)
- func PasswordFromPasswordAndSalt(password, salt string) string
- func ReadFill(r io.Reader, buf []byte) (n int, err error)
- type Cipher
- func (c *Cipher) ChangeGlobalPassword(password, salt string) error
- func (c *Cipher) DecryptData(rc io.ReadCloser, k *key) (io.ReadCloser, error)
- func (c *Cipher) DecryptDataSeek(ctx context.Context, open OpenRangeSeek, offset, limit int64, k *key) (ReadSeekCloser, error)
- func (c *Cipher) DecryptDirName(in string, k *key) (string, error)
- func (c *Cipher) DecryptFileName(in string, k *key) (string, error)
- func (c *Cipher) DecryptedSize(size int64) (int64, error)
- func (c *Cipher) EncryptData(in io.Reader, k *key) (io.Reader, error)
- func (c *Cipher) EncryptDirName(in string, k *key) string
- func (c *Cipher) EncryptFileName(in string, k *key) string
- func (c *Cipher) NameEncryptionMode() NameEncryptionMode
- type NameEncryptionMode
- type OpenRangeSeek
- type RangeSeeker
- type RcloneCrypt
- func (o *RcloneCrypt) DecryptedSize(fileSize int64) (int64, error)
- func (o *RcloneCrypt) EncryptedSize(fileSize int64) int64
- func (o *RcloneCrypt) Open(ctx context.Context, rh *utils.RangeHeader, fileSize int64, password string, ...) (rc io.ReadCloser, err error)
- func (o *RcloneCrypt) OverheadSize(fileSize int64) int64
- type ReadSeekCloser
Constants ¶
const (
EncFileExtension = ".bin"
)
Constants
Variables ¶
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") ErrorTooLongAfterDecode = errors.New("too long 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 - does not match suffix") ErrorBadSeek = errors.New("Seek beyond end of file") ErrorSuffixMissingDot = errors.New("suffix config setting should include a '.'") )
Errors returned by cipher
var ( ErrMissingPassword = errors.New("password is required in metadata") ErrMissingSalt = errors.New("salt is required in metadata") ErrMissingEncryptedFileSize = errors.New("cipher_file_size is required in metadata") )
var ErrInvalidPassword = errors.New("invalid password")
Functions ¶
func DecryptedSize ¶
func EncryptedSize ¶
EncryptedSize calculates the size of the data when encrypted
func ExtractPasswordAndSalt ¶
func GenerateKey ¶
Key creates all the internal keys from the password passed in using scrypt.
If salt is "" we use a fixed salt just to make attackers lives slightly harder than using no salt.
Note that empty password makes all 0x00 keys which is used in the tests.
func NewNameEncoding ¶
NewNameEncoding creates a NameEncoding from a string
Types ¶
type Cipher ¶
type Cipher struct {
// contains filtered or unexported fields
}
Cipher defines an encoding and decoding cipher for the crypt backend
func NewCipher ¶
func NewCipher(mode NameEncryptionMode, password, salt string, dirNameEncrypt bool, enc fileNameEncoding) (*Cipher, error)
newCipher initialises the cipher. If salt is "" then it uses a built in salt val
func (*Cipher) ChangeGlobalPassword ¶
func (*Cipher) DecryptData ¶
func (c *Cipher) DecryptData(rc io.ReadCloser, k *key) (io.ReadCloser, error)
DecryptData decrypts the data stream
func (*Cipher) DecryptDataSeek ¶
func (c *Cipher) DecryptDataSeek(ctx context.Context, open OpenRangeSeek, offset, limit int64, k *key) (ReadSeekCloser, error)
DecryptDataSeek decrypts the data stream from offset
The open function must return a ReadCloser opened to the offset supplied.
You must use this form of DecryptData if you might want to Seek the file handle
func (*Cipher) DecryptDirName ¶
DecryptDirName decrypts a directory path
func (*Cipher) DecryptFileName ¶
DecryptFileName decrypts a file path
func (*Cipher) DecryptedSize ¶
DecryptedSize calculates the size of the data when decrypted
func (*Cipher) EncryptData ¶
EncryptData encrypts the data stream
func (*Cipher) EncryptDirName ¶
EncryptDirName encrypts a directory path
func (*Cipher) EncryptFileName ¶
EncryptFileName encrypts a file path
func (*Cipher) NameEncryptionMode ¶
func (c *Cipher) NameEncryptionMode() NameEncryptionMode
NameEncryptionMode returns the encryption mode in use for names
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 OpenRangeSeek ¶
OpenRangeSeek opens the file handle at the offset with the limit given
type RangeSeeker ¶
type RangeSeeker interface {
// RangeSeek behaves like a call to Seek(offset int64, whence
// int) with the output wrapped in an io.LimitedReader
// limiting the total length to limit.
//
// RangeSeek with a limit of < 0 is equivalent to a regular Seek.
RangeSeek(ctx context.Context, offset int64, whence int, length int64) (int64, error)
}
RangeSeeker is the interface that wraps the RangeSeek method.
Some of the returns from Object.Open() may optionally implement this method for efficiency purposes.
type RcloneCrypt ¶
type RcloneCrypt struct {
// contains filtered or unexported fields
}
RcloneCrypt handles rclone-style file encryption/decryption
func NewRcloneCipher ¶
func NewRcloneCipher( config *encryption.Config, ) (*RcloneCrypt, error)
func (*RcloneCrypt) DecryptedSize ¶
func (o *RcloneCrypt) DecryptedSize(fileSize int64) (int64, error)
func (*RcloneCrypt) EncryptedSize ¶
func (o *RcloneCrypt) EncryptedSize(fileSize int64) int64
func (*RcloneCrypt) Open ¶
func (o *RcloneCrypt) Open( ctx context.Context, rh *utils.RangeHeader, fileSize int64, password string, salt string, getReader func(ctx context.Context, start, end int64) (io.ReadCloser, error), ) (rc io.ReadCloser, err error)
Opens a new crypt session, until read is not called, the underlying usenet reader is not called this way we don't perform reads while fetching the modtime
func (*RcloneCrypt) OverheadSize ¶
func (o *RcloneCrypt) OverheadSize(fileSize int64) int64
type ReadSeekCloser ¶
ReadSeekCloser is the interface of the read handles