rclone

package
v0.0.1-alpha5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncFileExtension = ".bin"
)

Constants

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

View Source
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")
)
View Source
var ErrInvalidPassword = errors.New("invalid password")

Functions

func DecryptedSize

func DecryptedSize(size int64) (int64, error)

func EncryptedSize

func EncryptedSize(size int64) int64

EncryptedSize calculates the size of the data when encrypted

func ExtractPasswordAndSalt

func ExtractPasswordAndSalt(password string) (string, string)

func GenerateKey

func GenerateKey(password, salt string) (*key, error)

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

func NewNameEncoding(s string) (enc fileNameEncoding, err error)

NewNameEncoding creates a NameEncoding from a string

func PasswordFromPasswordAndSalt

func PasswordFromPasswordAndSalt(password, salt string) string

func ReadFill

func ReadFill(r io.Reader, buf []byte) (n int, err error)

ReadFill reads as much data from r into buf as it can

It reads until the buffer is full or r.Read returned an error.

This is io.ReadFull but when you just want as much data as possible, not an exact size of block.

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 (c *Cipher) ChangeGlobalPassword(password, salt string) error

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

func (c *Cipher) DecryptDirName(in string, k *key) (string, error)

DecryptDirName decrypts a directory path

func (*Cipher) DecryptFileName

func (c *Cipher) DecryptFileName(in string, k *key) (string, error)

DecryptFileName decrypts a file path

func (*Cipher) DecryptedSize

func (c *Cipher) DecryptedSize(size int64) (int64, error)

DecryptedSize calculates the size of the data when decrypted

func (*Cipher) EncryptData

func (c *Cipher) EncryptData(in io.Reader, k *key) (io.Reader, error)

EncryptData encrypts the data stream

func (*Cipher) EncryptDirName

func (c *Cipher) EncryptDirName(in string, k *key) string

EncryptDirName encrypts a directory path

func (*Cipher) EncryptFileName

func (c *Cipher) EncryptFileName(in string, k *key) string

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

type OpenRangeSeek func(ctx context.Context, offset, limit int64) (io.ReadCloser, error)

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

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

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