class NativeCrypt extends Native

Implements an encryption layer on top of the native filesystem.

Files are divided into chunks, the size of which can be configured. Import and Truncate are not as fast since new data must actually be written.

The crypto key for the filesystem is stored plainly in the database, so this is only useful for off-server untrusted external storages. Client-side crypto should be used for any case where the API is not trusted.

Properties

protected $fsmanager from  FSImpl
protected $masterkey
protected $chunksize

Methods

__construct(FSManager $filesystem, string $masterkey, int $chunksize)

No description

int|null
GetChunkSize()

Returns the preferred byte alignment of the filesystem.

GetFSManager()

Returns a reference to the parent FS manager

from  FSImpl
GetStorage()

Returns the underlying storage

from  FSImpl
GetDatabase()

Returns a database reference

from  FSImpl
RefreshFile(File $file)

no-op

from  Native
RefreshFolder(Folder $folder, bool $doContents = true)

no-op

from  Native
CreateFolder(Folder $folder)

no-op

from  Native
DeleteFolder(Folder $folder)

no-op

from  Native
ImportFile(File $file, InputPath $infile)

Creates a new file and imports its content

CreateFile(File $file)

Creates an empty file on storage

DeleteFile(File $file)

Deletes the given file from storage

string
ReadBytes(File $file, int $start, int $length)

Reads the exact number of desired bytes from the given file

WriteBytes(File $file, int $start, string $data)

Writes to the given file, possibly appending it

Truncate(File $file, int $length)

Truncates (changes size of) a file

RenameFile(File $file, string $name)

no-op

from  Native
RenameFolder(Folder $folder, string $name)

no-op

from  Native
MoveFile(File $file, Folder $parent)

no-op

from  Native
MoveFolder(Folder $folder, Folder $parent)

no-op

from  Native
CopyFile(File $file, File $dest)

Copies a file

CopyFolder(Folder $folder, Folder $dest)

No description

from  Native
string
GetFilePath(File $file)

The path to a file is simply its ID, broken into a prefix

from  Native
ManualCopyFolder(Folder $folder, Folder $dest)

Helper function to emulate copying a folder by copying its contents manually

GetAuthString(File $file, int $index)

Chunk swapping is prevented by signing each with the file ID and chunk index

int
GetChunkIndex(int $byte)

Returns the chunk index storing the given byte offset

int
GetNumChunks(int $bytes)

Returns the number of chunks required to store the given number of bytes

string
ReadChunk(File $file, int $index)

Reads and decrypts the given chunk from the file

WriteChunk(File $file, int $index, string $data)

Encrypts and writes the given data to the given chunk

Details

at line 29
__construct(FSManager $filesystem, string $masterkey, int $chunksize)

No description

Parameters

FSManager $filesystem
string $masterkey
int $chunksize

at line 36
int|null GetChunkSize()

Returns the preferred byte alignment of the filesystem.

Reads and writes should align to these boundaries for performance

Return Value

int|null

FS chunk size

in FSImpl at line 40
protected FSManager GetFSManager()

Returns a reference to the parent FS manager

Return Value

FSManager

in FSImpl at line 43
protected Storage GetStorage()

Returns the underlying storage

Return Value

Storage

in FSImpl at line 46
protected ObjectDatabase GetDatabase()

Returns a database reference

Return Value

ObjectDatabase

in Native at line 77
FSImpl RefreshFile(File $file)

no-op

Parameters

File $file

Return Value

FSImpl

in Native at line 78
FSImpl RefreshFolder(Folder $folder, bool $doContents = true)

no-op

Parameters

Folder $folder
bool $doContents

Return Value

FSImpl

in Native at line 79
FSImpl CreateFolder(Folder $folder)

no-op

Parameters

Folder $folder

Return Value

FSImpl

in Native at line 80
FSImpl DeleteFolder(Folder $folder)

no-op

Parameters

Folder $folder

Return Value

FSImpl

at line 47
FSImpl ImportFile(File $file, InputPath $infile)

Creates a new file and imports its content

Parameters

File $file

the database object

InputPath $infile

the file to import

Return Value

FSImpl

in BaseFileFS at line 19
FSImpl CreateFile(File $file)

Creates an empty file on storage

Parameters

File $file

Return Value

FSImpl

in BaseFileFS at line 49
FSImpl DeleteFile(File $file)

Deletes the given file from storage

Parameters

File $file

Return Value

FSImpl

at line 73
string ReadBytes(File $file, int $start, int $length)

Reads the exact number of desired bytes from the given file

Throws an error if the read goes beyond the end of the file

Parameters

File $file

file to read

int $start

byte offset

int $length

number of bytes

Return Value

string

file data

at line 101
FSImpl WriteBytes(File $file, int $start, string $data)

Writes to the given file, possibly appending it

Parameters

File $file

file to write

int $start

byte offset

string $data

data to write

Return Value

FSImpl

at line 140
FSImpl Truncate(File $file, int $length)

Truncates (changes size of) a file

Parameters

File $file

file to truncate

int $length

desired size in bytes

Return Value

FSImpl

in Native at line 81
FSImpl RenameFile(File $file, string $name)

no-op

Parameters

File $file
string $name

Return Value

FSImpl

in Native at line 82
FSImpl RenameFolder(Folder $folder, string $name)

no-op

Parameters

Folder $folder
string $name

Return Value

FSImpl

in Native at line 83
FSImpl MoveFile(File $file, Folder $parent)

no-op

Parameters

File $file

file to move

Folder $parent

new parent folder

Return Value

FSImpl

in Native at line 84
FSImpl MoveFolder(Folder $folder, Folder $parent)

no-op

Parameters

Folder $folder

folder to move

Folder $parent

new parent folder

Return Value

FSImpl

in BaseFileFS at line 44
FSImpl CopyFile(File $file, File $dest)

Copies a file

Parameters

File $file

file to copy

File $dest

new object for destination

Return Value

FSImpl

in Native at line 87
FSImpl CopyFolder(Folder $folder, Folder $dest)

No description

Parameters

Folder $folder

folder to copy

Folder $dest

new object for destination

Return Value

FSImpl

See also

BaseFileFS::ManualCopyFolder

in Native at line 93
protected string GetFilePath(File $file)

The path to a file is simply its ID, broken into a prefix

Parameters

File $file

Return Value

string

in BaseFileFS at line 60
protected BaseFileFS ManualCopyFolder(Folder $folder, Folder $dest)

Helper function to emulate copying a folder by copying its contents manually

Parameters

Folder $folder

folder to copy

Folder $dest

new folder object to copy to

Return Value

BaseFileFS

at line 39
private GetAuthString(File $file, int $index)

Chunk swapping is prevented by signing each with the file ID and chunk index

Parameters

File $file
int $index

at line 42
protected int GetChunkIndex(int $byte)

Returns the chunk index storing the given byte offset

Parameters

int $byte

Return Value

int

at line 45
protected int GetNumChunks(int $bytes)

Returns the number of chunks required to store the given number of bytes

Parameters

int $bytes

Return Value

int

at line 189
protected string ReadChunk(File $file, int $index)

Reads and decrypts the given chunk from the file

Parameters

File $file

file to read from

int $index

chunk number

Return Value

string

decrypted chunk

at line 223
protected NativeCrypt WriteChunk(File $file, int $index, string $data)

Encrypts and writes the given data to the given chunk

Parameters

File $file

file to write to

int $index

chunk index to write

string $data

plaintext data to write

Return Value

NativeCrypt