Salmon
Loading...
Searching...
No Matches
Mku.Salmon.SalmonFile Class Reference

A virtual file backed by an encrypted IRealFile on the real filesystem. Supports operations for retrieving SalmonStream for reading/decrypting and writing/encrypting contents. More...

Inheritance diagram for Mku.Salmon.SalmonFile:
Mku.File.IVirtualFile

Classes

class  FileTaskProgress
 File task progress class. More...
 

Public Member Functions

 SalmonFile (IRealFile realFile, SalmonDrive drive=null)
 Provides a file handle that can be used to create encrypted files. Requires a virtual drive that supports the underlying filesystem, see DotNetFile implementation.
 
override SalmonStream GetInputStream ()
 Opens a SalmonStream that will be used for reading/decrypting the file contents.
 
override SalmonStream GetOutputStream ()
 Opens a SalmonStream for encrypting/writing contents.
 
void SetVerifyIntegrity (bool integrity, byte[] hashKey)
 Enabled verification of file integrity during read() and write()
 
void SetApplyIntegrity (bool integrity, byte[] hashKey, int? requestChunkSize)
 Enable integrity when writing contents.
 
override SalmonFile[] ListFiles ()
 Lists files and directories under this directory.
 
override SalmonFile GetChild (string filename)
 Get a file/subdirectory with this filename.
 
override SalmonFile CreateDirectory (string dirName)
 Creates a directory under this directory.
 
SalmonFile CreateDirectory (string dirName, byte[] key, byte[] dirNameNonce)
 Creates a directory under this directory.
 
override void Delete ()
 Delete this file.
 
override void Mkdir ()
 Create this directory. Currently Not Supported.
 
override SalmonFile CreateFile (string realFilename)
 Create a file under this directory.
 
SalmonFile CreateFile (string realFilename, byte[] key, byte[] fileNameNonce, byte[] fileNonce)
 Create a file under this directory.
 
override void Rename (string newFilename)
 Rename the virtual file name.
 
void Rename (string newFilename, byte[] nonce)
 Rename the virtual file name.
 
override SalmonFile Move (IVirtualFile dir, Action< long, long > OnProgressListener)
 Move file to another directory.
 
override SalmonFile Copy (IVirtualFile dir, Action< long, long > OnProgressListener)
 Copy a file to another directory.
 
override void CopyRecursively (IVirtualFile dest, Action< IVirtualFile, long, long > progressListener, Func< IVirtualFile, string > AutoRename, bool autoRenameFolders, Action< IVirtualFile, Exception > OnFailed)
 Copy a directory recursively.
 
override void MoveRecursively (IVirtualFile dest, Action< IVirtualFile, long, long > progressListener, Func< IVirtualFile, string > AutoRename, bool autoRenameFolders, Action< IVirtualFile, Exception > OnFailed)
 Move a directory recursively.
 
override void DeleteRecursively (Action< IVirtualFile, long, long > progressListener, Action< IVirtualFile, Exception > OnFailed)
 Delete a directory recursively.
 
int GetMinimumPartSize ()
 Returns the minimum part size that can be encrypted / decrypted in parallel aligning to the integrity chunk size if available.
 
- Public Member Functions inherited from Mku.File.IVirtualFile
Stream GetInputStream ()
 Opens a Stream that will be used for reading the file contents.
 
Stream GetOutputStream ()
 Opens a stream for writing contents.
 
IVirtualFile[] ListFiles ()
 Lists files and directories under this directory.
 
IVirtualFile GetChild (string filename)
 Get a file/subdirectory with this filename.
 
void Delete ()
 Delete this file.
 
void Mkdir ()
 Create this directory.
 
IVirtualFile CreateDirectory (string dirName)
 Creates a directory under this directory.
 
IVirtualFile CreateFile (string realFilename)
 Create a file under this directory.
 
void Rename (string newFilename)
 Rename the virtual file name.
 
IVirtualFile Move (IVirtualFile dir, Action< long, long > OnProgressListener)
 Move file to another directory.
 
IVirtualFile Copy (IVirtualFile dir, Action< long, long > OnProgressListener)
 Copy a file to another directory.
 
void MoveRecursively (IVirtualFile dest, Action< IVirtualFile, long, long > progressListener, Func< IVirtualFile, string > AutoRename, bool autoRenameFolders, Action< IVirtualFile, Exception > OnFailed)
 Move a directory recursively.
 
void CopyRecursively (IVirtualFile dest, Action< IVirtualFile, long, long > progressListener, Func< IVirtualFile, string > AutoRename, bool autoRenameFolders, Action< IVirtualFile, Exception > OnFailed)
 Copy a directory recursively.
 
void DeleteRecursively (Action< IVirtualFile, long, long > progressListener, Action< IVirtualFile, Exception > OnFailed)
 Delete a directory recursively.
 

Static Public Member Functions

static string AutoRename (IVirtualFile file)
 Get an auto generated copy of the name for the file.
 

Protected Member Functions

string GetDecryptedFilename (string filename, byte[] key, byte[] nonce)
 Return the decrypted filename of a real filename.
 
string GetEncryptedFilename (string filename, byte[] key, byte[] nonce)
 Return the encrypted filename of a virtual filename.
 

Properties

SalmonDrive Drive [get]
 The drive this file belongs too.
 
override IRealFile RealFile [get, protected set]
 The real encrypted file on the physical disk.
 
override string Path [get]
 The path of the real file stored.
 
override string RealPath [get]
 The path of the real file.
 
override long LastDateTimeModified [get]
 The last date modified in milliseconds.
 
override long Size [get]
 The virtual size of the file excluding the header and hash signatures.
 
override bool IsFile [get]
 True if this is a file.
 
override bool IsDirectory [get]
 True if this is a directory.
 
bool AllowOverwrite [get, set]
 Warning! Allow overwriting on a current stream. Overwriting is not a good idea because it will re-use the same IV. This is not recommended if you use the stream on storing files or generally data if prior version can be inspected by others. You should only use this setting for initial encryption with parallel streams and not for overwriting!
 
bool IsIntegrityEnabled [get]
 Is integrity enabled;.
 
Object Tag [get, set]
 File Tag. You can use to tag this file.
 
int? RequestedChunkSize [get]
 Return the current chunk size requested that will be used for integrity.
 
int? FileChunkSize [get]
 Get the file chunk size from the header.
 
SalmonHeader Header [get]
 The custom SalmonHeader from this file.
 
byte[] EncryptionKey [get, set]
 Returns the current encryption key.
 
byte[] FileNonce [get]
 Returns the initial vector that is used for encryption / decryption.
 
byte[] RequestedNonce [get, set]
 Get the nonce that is used for encryption/decryption of this file.
 
int BlockSize [get]
 Return the AES block size for encryption / decryption.
 
int ChildrenCount [get]
 Get the count of files and subdirectories.
 
override string BaseName [get]
 The base name for the file.
 
override SalmonFile Parent [get]
 Returns the virtual parent directory.
 
override bool Exists [get]
 True if this file/directory exists.
 
- Properties inherited from Mku.File.IVirtualFile
bool IsFile [get]
 True if this is a file.
 
bool IsDirectory [get]
 True if this is a directory.
 
string Path [get]
 The path of the real file stored.
 
string RealPath [get]
 The path of the real file.
 
IRealFile RealFile [get, protected set]
 The real encrypted file on the physical disk.
 
string BaseName [get]
 The base name for the file.
 
IVirtualFile Parent [get]
 Returns the virtual parent directory.
 
long LastDateTimeModified [get]
 The last date modified in milliseconds.
 
long Size [get]
 The virtual size of the file excluding the header and hash signatures.
 
bool Exists [get]
 True if this file/directory exists.
 

Detailed Description

A virtual file backed by an encrypted IRealFile on the real filesystem. Supports operations for retrieving SalmonStream for reading/decrypting and writing/encrypting contents.

Constructor & Destructor Documentation

◆ SalmonFile()

Mku.Salmon.SalmonFile.SalmonFile ( IRealFile realFile,
SalmonDrive drive = null )

Provides a file handle that can be used to create encrypted files. Requires a virtual drive that supports the underlying filesystem, see DotNetFile implementation.

Parameters
driveThe file virtual system that will be used with file operations
realFileThe real file

Member Function Documentation

◆ AutoRename()

static string Mku.Salmon.SalmonFile.AutoRename ( IVirtualFile file)
static

Get an auto generated copy of the name for the file.

Parameters
fileThe file
Returns
The new file name

◆ Copy()

override SalmonFile Mku.Salmon.SalmonFile.Copy ( IVirtualFile dir,
Action< long, long > OnProgressListener )

Copy a file to another directory.

Parameters
dirTarget directory.
OnProgressListenerObserver to notify when copy progress changes.
Returns
The new file
Exceptions
IOExceptionThrown if error during IO

◆ CopyRecursively()

override void Mku.Salmon.SalmonFile.CopyRecursively ( IVirtualFile dest,
Action< IVirtualFile, long, long > progressListener,
Func< IVirtualFile, string > AutoRename,
bool autoRenameFolders,
Action< IVirtualFile, Exception > OnFailed )

Copy a directory recursively.

Parameters
destThe destination directory
progressListenerThe progress listener
AutoRenameThe autorename function to use when renaming files if they exist
autoRenameFoldersApply autorename to folders also (default is true)
OnFailedCallback when copy fails

◆ CreateDirectory() [1/2]

override SalmonFile Mku.Salmon.SalmonFile.CreateDirectory ( string dirName)

Creates a directory under this directory.

Parameters
dirNameThe name of the directory to be created

◆ CreateDirectory() [2/2]

SalmonFile Mku.Salmon.SalmonFile.CreateDirectory ( string dirName,
byte[] key,
byte[] dirNameNonce )

Creates a directory under this directory.

Parameters
dirNameThe name of the directory to be created
keyThe key that will be used to encrypt the directory name
dirNameNonceThe nonce to be used for encrypting the directory name

◆ CreateFile() [1/2]

override SalmonFile Mku.Salmon.SalmonFile.CreateFile ( string realFilename)

Create a file under this directory.

Parameters
realFilenameThe real file name of the file (encrypted)

◆ CreateFile() [2/2]

SalmonFile Mku.Salmon.SalmonFile.CreateFile ( string realFilename,
byte[] key,
byte[] fileNameNonce,
byte[] fileNonce )

Create a file under this directory.

Parameters
realFilenameThe real file name of the file (encrypted)
keyThe key that will be used for encryption
fileNameNonceThe nonce for the encrypting the filename
fileNonceThe nonce for the encrypting the file contents

◆ DeleteRecursively()

override void Mku.Salmon.SalmonFile.DeleteRecursively ( Action< IVirtualFile, long, long > progressListener,
Action< IVirtualFile, Exception > OnFailed )

Delete a directory recursively.

Parameters
progressListenerThe progress listener
OnFailedCallback when delete fails

◆ GetChild()

override SalmonFile Mku.Salmon.SalmonFile.GetChild ( string filename)

Get a file/subdirectory with this filename.

Parameters
filenameThe filename to match
Returns
The file/subdirectory

◆ GetDecryptedFilename()

string Mku.Salmon.SalmonFile.GetDecryptedFilename ( string filename,
byte[] key,
byte[] nonce )
protected

Return the decrypted filename of a real filename.

Parameters
filenameThe filename of a real file
keyThe encryption key if the file doesn't belong to a drive
nonceThe nonce if the file doesn't belong to a drive

◆ GetEncryptedFilename()

string Mku.Salmon.SalmonFile.GetEncryptedFilename ( string filename,
byte[] key,
byte[] nonce )
protected

Return the encrypted filename of a virtual filename.

Parameters
filenameThe virtual filename
keyThe encryption key if the file doesn't belong to a drive
nonceThe nonce if the file doesn't belong to a drive

◆ GetInputStream()

override SalmonStream Mku.Salmon.SalmonFile.GetInputStream ( )

Opens a SalmonStream that will be used for reading/decrypting the file contents.

Returns
The input stream
Exceptions
IOExceptionThrown if error during IO
SalmonSecurityExceptionThrown when error with security
IntegrityExceptionThrown when data are corrupt or tampered with.

◆ GetOutputStream()

override SalmonStream Mku.Salmon.SalmonFile.GetOutputStream ( )

Opens a SalmonStream for encrypting/writing contents.

Returns
The output stream
Exceptions
SalmonSecurityExceptionThrown when error with security
IntegrityExceptionThrown when data are corrupt or tampered with.
SequenceExceptionThrown when there is a failure in the nonce sequencer.

◆ ListFiles()

override SalmonFile[] Mku.Salmon.SalmonFile.ListFiles ( )

Lists files and directories under this directory.

Returns
An array of files and subdirectories

◆ Move()

override SalmonFile Mku.Salmon.SalmonFile.Move ( IVirtualFile dir,
Action< long, long > OnProgressListener )

Move file to another directory.

Parameters
dirTarget directory.
OnProgressListenerObserver to notify when move progress changes.
Returns
The moved file
Exceptions
IOExceptionThrown if error during IO

◆ MoveRecursively()

override void Mku.Salmon.SalmonFile.MoveRecursively ( IVirtualFile dest,
Action< IVirtualFile, long, long > progressListener,
Func< IVirtualFile, string > AutoRename,
bool autoRenameFolders,
Action< IVirtualFile, Exception > OnFailed )

Move a directory recursively.

Parameters
destThe destination directory
progressListenerThe progress listener
AutoRenameThe autorename function to use when renaming files if they exist
autoRenameFoldersApply autorename to folders also (default is true)
OnFailedCallback when move fails

◆ Rename() [1/2]

override void Mku.Salmon.SalmonFile.Rename ( string newFilename)

Rename the virtual file name.

Parameters
newFilenameThe new filename this file will be renamed to

◆ Rename() [2/2]

void Mku.Salmon.SalmonFile.Rename ( string newFilename,
byte[] nonce )

Rename the virtual file name.

Parameters
newFilenameThe new filename this file will be renamed to
nonceThe nonce to be used

◆ SetApplyIntegrity()

void Mku.Salmon.SalmonFile.SetApplyIntegrity ( bool integrity,
byte[] hashKey,
int? requestChunkSize )

Enable integrity when writing contents.

Parameters
hashKeyThe hash key
integrityThe integrity
requestChunkSize0 use default file chunk.

A positive number to specify integrity chunks.

◆ SetVerifyIntegrity()

void Mku.Salmon.SalmonFile.SetVerifyIntegrity ( bool integrity,
byte[] hashKey )

Enabled verification of file integrity during read() and write()

Parameters
integrityTrue if enable integrity verification
hashKeyThe hash key to be used for verification

Property Documentation

◆ AllowOverwrite

bool Mku.Salmon.SalmonFile.AllowOverwrite
getset

Warning! Allow overwriting on a current stream. Overwriting is not a good idea because it will re-use the same IV. This is not recommended if you use the stream on storing files or generally data if prior version can be inspected by others. You should only use this setting for initial encryption with parallel streams and not for overwriting!

Parameters
valueTrue to allow overwriting operations

◆ ChildrenCount

int Mku.Salmon.SalmonFile.ChildrenCount
get

Get the count of files and subdirectories.

Returns
The children count

◆ FileChunkSize

int? Mku.Salmon.SalmonFile.FileChunkSize
get

Get the file chunk size from the header.

Returns
The chunk size.
Exceptions
IOExceptionThrown if the format is corrupt.

◆ Header

SalmonHeader Mku.Salmon.SalmonFile.Header
get

The custom SalmonHeader from this file.

Exceptions
IOExceptionThrown if error during IO

◆ RequestedNonce

byte [] Mku.Salmon.SalmonFile.RequestedNonce
getset

Get the nonce that is used for encryption/decryption of this file.

Returns
The requested nonce

The documentation for this class was generated from the following file: