Constructor
new AesFile(realFile, driveopt)
Provides a file handle that can be used to create encrypted files.
Requires a virtual drive that supports the underlying filesystem see IFile.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
realFile |
IFile | The real file | |
drive |
AesDrive |
<optional> |
The file virtual system that will be used with file operations. You usually don't have to set this since it will inherit from its parent. |
Classes
Methods
(async) copy(dir, optionsopt) → {Promise.<AesFile>}
Copy a file to another directory.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dir |
AesFile | Target directory. | |
options |
CopyOptions |
<optional> |
The options. |
Throws:
IOException Thrown if there is an IO error.
Returns:
The encrypted file
- Type
- Promise.<AesFile>
(async) copyRecursively(dest, optionsopt)
Copy a directory recursively
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dest |
AesFile | The destination directory | |
options |
VirtualRecursiveCopyOptions |
<optional> |
The options |
(async) createDirectory(dirName, key, dirNameNonce) → {Promise.<AesFile>}
Creates a directory under this directory
Parameters:
Name | Type | Default | Description |
---|---|---|---|
dirName |
string | The name of the directory to be created | |
key |
Uint8Array | null | null | The key that will be used to encrypt the directory name |
dirNameNonce |
Uint8Array | null | null | The nonce to be used for encrypting the directory name |
Returns:
The file
- Type
- Promise.<AesFile>
(async) createFile(realFilename, key, fileNameNonce, fileNonce) → {Promise.<AesFile>}
Create a file under this directory
Parameters:
Name | Type | Default | Description |
---|---|---|---|
realFilename |
string | The real file name of the file (encrypted) | |
key |
Uint8Array | null | null | The key that will be used for encryption |
fileNameNonce |
Uint8Array | null | null | The nonce for the encrypting the filename |
fileNonce |
Uint8Array | null | null | The nonce for the encrypting the file contents |
Returns:
The new file
- Type
- Promise.<AesFile>
(async) delete()
Delete this file.
(async) deleteRecursively(optionsopt)
Delete a directory recursively
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
VirtualRecursiveDeleteOptions |
<optional> |
The options |
(async) exists() → {Promise.<boolean>}
Returns true if this file exists
Returns:
True if exists
- Type
- Promise.<boolean>
getBlockSize() → {number}
Return the AES block size for encryption / decryption
Returns:
The block size
- Type
- number
(async) getChild(filename) → {Promise.<(AesFile|null)>}
Get a child with this filename.
Parameters:
Name | Type | Description |
---|---|---|
filename |
string | The filename to search for |
Throws:
-
SalmonSecurityException Thrown when error with security
-
IntegrityException Thrown if the data are corrupt or tampered with.
-
IOException Thrown if there is an IO error.
-
SalmonAuthException Thrown when error during authorization
Returns:
The file or directory.
- Type
- Promise.<(AesFile|null)>
(async) getChildrenCount() → {Promise.<number>}
Get the count of files and subdirectories
Returns:
The children count
- Type
- Promise.<number>
(async) getDecryptedFilename(filename, key, nonce)
Return the decrypted filename of a real filename
Parameters:
Name | Type | Default | Description |
---|---|---|---|
filename |
string | The filename of a real file | |
key |
Uint8Array | null | null | The encryption key if the file doesn't belong to a drive |
nonce |
Uint8Array | null | null | The nonce if the file doesn't belong to a drive |
getDrive() → {AesDrive|undefined}
Get the drive.
Returns:
The drive
- Type
- AesDrive | undefined
(async) getEncryptedFilename(filename, key, nonce) → {Promise.<string>}
Return the encrypted filename of a virtual filename
Parameters:
Name | Type | Default | Description |
---|---|---|---|
filename |
string | The virtual filename | |
key |
Uint8Array | null | null | The encryption key if the file doesn't belong to a drive |
nonce |
Uint8Array | null | null | The nonce if the file doesn't belong to a drive |
Returns:
The encrypted filename
- Type
- Promise.<string>
getEncryptionKey() → {Uint8Array|null}
Returns the current encryption key
Returns:
The key
- Type
- Uint8Array | null
(async) getFileChunkSize() → {Promise.<number>}
Get the file chunk size from the header.
Throws:
IOException Throws exceptions if the format is corrupt.
Returns:
The chunk size.
- Type
- Promise.<number>
(async) getFileNonce() → {Promise.<(Uint8Array|null)>}
Returns the initial vector that is used for encryption / decryption
Returns:
The nonce
- Type
- Promise.<(Uint8Array|null)>
getHashKey() → {Uint8Array|null}
Retrieve the current hash key that is used to encrypt / decrypt the file contents.
Returns:
The hash key.
- Type
- Uint8Array | null
(async) getHeader() → {Promise.<(Header|null)>}
Get the custom Header from this file.
Throws:
IOException Thrown if there is an IO error.
Returns:
The header
- Type
- Promise.<(Header|null)>
(async) getInputStream() → {Promise.<AesStream>}
Retrieves a SalmonStream that will be used for decrypting the file contents.
Throws:
-
IOException Thrown if there is an IO error.
-
SalmonSecurityException Thrown when error with security
-
IntegrityException Thrown if the data are corrupt or tampered with.
Returns:
The stream
- Type
- Promise.<AesStream>
(async) getLastDateModified() → {Promise.<number>}
Returns the last date modified in milliseconds
Returns:
The date modified
- Type
- Promise.<number>
(async) getLength() → {Promise.<number>}
Return the virtual size of the file excluding the header and hash signatures.
Returns:
The length
- Type
- Promise.<number>
(async) getMinimumPartSize() → {Promise.<number>}
Returns the minimum part size that can be encrypted / decrypted in parallel
aligning to the integrity chunk size if available.
Returns:
The minimum part size
- Type
- Promise.<number>
(async) getName() → {Promise.<string>}
Returns the name for the file
Returns:
The file name
- Type
- Promise.<string>
(async) getOutputStream(nonce) → {Promise.<AesStream>}
Get a AesStream for encrypting/writing contents to this file.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
nonce |
Uint8Array | null | null | Nonce to be used for encryption. Note that each file should have a unique nonce see AesDrive#getNextNonce(). |
Throws:
Exception
Returns:
The output stream.
- Type
- Promise.<AesStream>
(async) getParent() → {Promise.<(AesFile|null)>}
Get the virtual parent directory
Returns:
The file
- Type
- Promise.<(AesFile|null)>
(async) getPath() → {Promise.<string>}
Return the path of the real file stored
Returns:
The path
- Type
- Promise.<string>
getRealFile() → {IFile}
Return the real file
Returns:
The file
- Type
- IFile
getRealPath() → {Promise.<string>}
Return the path of the real file
Returns:
The real path
- Type
- Promise.<string>
getRequestedChunkSize()
Return the current chunk size requested that will be used for integrity
getRequestedNonce() → {Uint8Array|null}
Get the nonce that is used for encryption/decryption of this file.
Returns:
The nonce
- Type
- Uint8Array | null
getTag() → {object|null}
Get the file tag.
Returns:
The file tag.
- Type
- object | null
(async) isDirectory() → {Promise.<boolean>}
Returns True if this is a directory
Returns:
True if directory
- Type
- Promise.<boolean>
(async) isFile() → {Promise.<boolean>}
Returns true if this is a file
Returns:
True if file
- Type
- Promise.<boolean>
isIntegrityEnabled()
Return if integrity is set
(async) listFiles() → {Promise.<Array.<AesFile>>}
Lists files and directories under this directory
Returns:
The files
- Type
- Promise.<Array.<AesFile>>
(async) mkdir()
Create this directory. Currently Not Supported
(async) move(dir, optionsopt) → {Promise.<AesFile>}
Move file to another directory.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dir |
AesFile | Target directory. | |
options |
MoveOptions |
<optional> |
The options |
Throws:
IOException Thrown if there is an IO error.
Returns:
The encrypted file
- Type
- Promise.<AesFile>
(async) moveRecursively(dest, optionsopt)
Move a directory recursively
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
dest |
AesFile | The destination directory | |
options |
VirtualRecursiveMoveOptions |
<optional> |
The options |
(async) rename(newFilename, nonce)
Rename the virtual file name
Parameters:
Name | Type | Default | Description |
---|---|---|---|
newFilename |
string | The new filename this file will be renamed to | |
nonce |
Uint8Array | null | null | The nonce to use |
setAllowOverwrite(value)
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:
Name | Type | Description |
---|---|---|
value |
boolean | True to allow overwriting operations |
(async) setApplyIntegrity(integrity, hashKey, requestChunkSize)
Appy integrity when writing to file.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
integrity |
boolean | True to apply integrity | |
hashKey |
Uint8Array | null | null | The hash key |
requestChunkSize |
number | 0 | A positive number to specify integrity chunk size. |
setEncryptionKey(encryptionKey)
Sets the encryption key
Parameters:
Name | Type | Description |
---|---|---|
encryptionKey |
Uint8Array | null | The AES encryption key to be used |
setRequestedNonce(nonce)
Set the nonce for encryption/decryption for this file.
Parameters:
Name | Type | Description |
---|---|---|
nonce |
Uint8Array | Nonce to be used. |
Throws:
SalmonSecurityException Thrown when error with security
setTag(tag)
Set the tag for this file.
Parameters:
Name | Type | Description |
---|---|---|
tag |
object | Any object |
(async) setVerifyIntegrity(integrity, hashKey)
Enabled verification of file integrity during read() and write()
Parameters:
Name | Type | Default | Description |
---|---|---|---|
integrity |
boolean | True if enable integrity verification | |
hashKey |
Uint8Array | null | null | The hash key to be used for verification |