OfsProvider
public class OfsProvider : BaseProvider
Provider that sources all data (containers, public keys, key files, users, etc from a local Obfuscating File System (OFS). This provider serves as a user session with the OFS. Use login to start an authenticated session.
-
Gets defauld ofs url for iOs
Declaration
Swift
public static let defaultOfsURL: URL -
Gets defauld ofs url for macOs
-
If True the data in the OFS Is partitioned by user.
Declaration
Swift
public let partitionDataByUser: Bool -
The root OFS directory.
Declaration
Swift
public let ofsRootDirectory: URL
-
Declaration
Swift
public init(ofsRootDirectory: URL = OfsProvider.defaultOfsURL, partitionDataByUser: Bool = false)Parameters
ofsRootDirectoryOptional: The root directory where to store data.
partitionDataByUserIf True the data in the OFS Is partitioned by user. Default: false.
-
Update the header of the secured container with the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerHeader<T>(containerId: UUID, customHeaderObject: T?) throws -> Promise<SecuredContainer> where T : Decodable, T : EncodableParameters
containerIdThe ID of the secured container.
customHeaderObjectOptional. The header to be encrypted in the secured container. If not supplied the header will be null.
Return Value
The updated SecuredContainer.
-
Update the content of the secured container with the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerContent(containerId: UUID, content: Data?) throws -> Promise<SecuredContainer>Parameters
containerIdThe ID of the secured container.
contentOptional. The content to be encrypted in the secured container. If not supplied the content will be null.
Return Value
The updated SecuredContainer.
-
Update the content of the secured container with the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerAccessLevels(containerId: UUID, accessLevels: [AccessLevel] = []) throws -> Promise<Void>Parameters
containerIdThe ID of the secured container.
accessLevelsOptional. This is the defined access for all users. If null, the user updating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
Return Value
The updated SecuredContainer.
-
Update the type of the secured container with the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainerType(containerId: UUID, type: String?) throws -> Promise<Void>Parameters
containerIdThe ID of the secured container.
typeOptional. This is used to categorize the Container. Default: null.
Return Value
The updated SecuredContainer.
-
Gets the decrypted header of the secured container for the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerHeader(containerId: UUID) throws -> Promise<Header?>Parameters
containerIdThe ID of the secured container.
Return Value
The decrypted header of the container.
-
Gets the decrypted content of the secured container for the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerContent(containerId: UUID) throws -> Promise<Data?>Parameters
containerIdThe ID of the secured container.
Return Value
The decrypted content of the secured container.
-
Creates and persists a new SecuredContainer in the OFS and returns it. Use the returned value to learn the assigned ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func createContainer(content: Data?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer>Parameters
contentThe container payload.
accessLevelsOptional. This is the defined access for all users. If null, the user creating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
typeOptional string used to categorize the Container. Default: null.
Return Value
The created SecuredContainer.
-
Creates and persists a new SecuredContainer in the OFS and returns it. Use the returned value to learn the assigned ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func createContainer<T>(content: Data?, customHeaderObject: T?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer> where T : Decodable, T : EncodableParameters
contentThe container payload.
customHeaderObjectThe optional header portion of the container. This Codable object will be serialized as JSON. Default: nil.
accessLevelsOptional. This is the defined access for all users. If null, the user creating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
typeOptional string used to categorize the Container. Default: null.
Return Value
The created SecuredContainer.
-
Persist the SecuredContainer as a new item in the OFS and returns it. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func createContainer(securedContainer: SecuredContainer) throws -> Promise<SecuredContainer>Parameters
securedContainerThe SecuredContainer to persist in the OFS.
Return Value
The SecuredContainer.
-
This is a helper method to persists the SecuredContainer in the OFS. It will determine if the secured container already exists in the OFS (using the id). In that case it will update the existing container. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func createOrUpdateContainer(securedContainer: SecuredContainer) throws -> Promise<SecuredContainer>Parameters
securedContainerThe SecuredContainer to persist in the OFS.
Return Value
The SecuredContainer.
-
Deletes the secured container with the given ID from the OFS. The encrypted content and the record in the encrypted database will be removed. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func deleteContainer(containerId: UUID) throws -> Promise<Void>Parameters
containerIdThe ID of the secured container.
-
Gets the SecuredContainer from the OFS (content, header and metadata), decrypts the content and header and returns the resulting container. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainer(containerId: UUID) throws -> Promise<Container>Parameters
containerIdThe ID of the secured container.
Return Value
Container with decrypted content, decrypted header, and metadata.
-
Gets the ContainerMetadata of the secured container for the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func getContainerMetadata(containerId: UUID) throws -> Promise<Container>Parameters
containerIdThe ID of the secured container.
Return Value
Container with Metadata.
-
Get all available containers IDs Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func getAllContainers() throws -> Promise<[UUID]>Return Value
Container IDs array
-
Update the content, header, access and type of the secured container with the given ID. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public override func updateContainer<T>(containerId: UUID, content: Data?, customHeaderObject: T?, accessLevels: [AccessLevel] = [], type: String? = nil) throws -> Promise<SecuredContainer> where T : Decodable, T : EncodableParameters
containerIdThe ID of the secured container.
contentThe content to be encrypted in the secured container.
customHeaderObjectCustom Codable header object
accessLevelsOptional. This is the defined access for all users. If null, the user updating the container will get full access (ContainerAccessLevel.DefaultOwnerPermissions). If any access is defined then the user creating the container will get the defined access or no access if none is defined. By default this list is null.
typeOptional. This is used to categorize the Container. Default: nil.
Return Value
The updated SecuredContainer.
-
This is used to create or update public key metadata (including the key itself) in the OFS database of the authenticated user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func createOrUpdatePublicKey(publicKey: PublicKey) throws -> Promise<Void>Parameters
publicKeyThe key data to create or update.
-
This gets the latest active public key that match the user ID and type from the encrypted database in the OFS. This calls GetListAsync and processes the list for active keys. It is needed for the IPublicKeySource interface.
Throws
AbsioError
Declaration
Swift
public func getLatestActivePublicKey(userId: UUID, keyType: KeyType, index: Int?) throws -> Promise<PublicKey?>Return Value
The latest active public key metadata (including the key) for the user of the specified type
-
This gets all public keys that match the user ID type and index from the encrypted database in the OFS.
Throws
AbsioError
Declaration
Swift
public func getPublicKeys(userId: UUID?, keyType: KeyType?, index: Int?) throws -> Promise<[PublicKey]>Parameters
userIdThe user’s ID.
keyTypeKey type
indexOptional. Key index
Return Value
A list of public key metadata (including the key) for the user of the specified type.
-
This deletes all public keys that match the user ID, type and index from the encrypted database in the OFS.
Declaration
Swift
public func deletePublicKeys(userId: UUID, keyType: KeyType? = nil, index: Int? = nil) throws -> Promise<Void>Parameters
userIdThe user’s ID.
keyTypeKey type
indexOptional. Key index
-
This will create a new user stored in the OFS. A KeyRing and UserId will be created for the user. The KeyRing will be stored in the OFS as an encrypted KeyFile. All mappers will be created and initialized. NOTE: Both the password and passphrase are required. If they are not supplied an ArgumentException will be thrown. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func register(password: String, passphrase: String) throws -> Promise<Data>Parameters
passwordThe password used to encrypt the KeyRing portion of the KeyFile.
passphraseThe passphrase used to encrypt the password portion of the KeyFile.
Return Value
The encrypted KeyFile data
-
Authenticates the user locally by decrypting the KeyFile to get their KeyRing and then logs into the encrypted database in the OFS. Password and passphrase are both listed as optional parameters, but at least one must be included. If the password is not included, the passphrase will be used to get the password from the KeyFile. If no passphrase was included when the KeyFile was created the operation will fail. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(userId: UUID, password: String? = nil, passphrase: String? = nil) throws -> Promise<Data>Parameters
userIdThe user’s ID.
passwordOptional. The user’s password.
passphraseOptional. The user’s passphrase.
Return Value
The encrypted KeyFile data
-
Authenticates the user locally by logging into the encrypted database in the OFS. If there is no encrypted database in the OFS one will be created. All mappers will be created and initialized. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(keyRing: KeyRing) throws -> Promise<Void>Parameters
keyRingThe user’s private key ring.
-
This is used to change the password and/or passphrase of a user. This will cause the KeyFile to be re-encrypted with the new password (used for the KeyRing portion). If a passphrase is supplied, the user will be allowed to authenticate (see login) with the passphrase in addition to the password. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func changeCredentials(password: String, passphrase: String) throws -> Promise<Data>Parameters
passwordThe password used to encrypt the KeyRing.
passphraseIf not null, used to encrypt the password allowing access to the KeyRing when the password is forgot.
Return Value
The encrypted KeyFile data
-
Deletes all associated data for the authenticated user. NOTE: This cannot be undone. Ensure you really want to perform this operation before doing so. The KeyFile, encrypted database and all secured containers will be removed from the OFS. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioErrorDeclaration
Swift
public override func deleteUser() throws -> Promise<Void> -
Creates or updates the user’s KeyFile bytes in the OFS, possibly creating both directory and file.
Throws
AbsioError
Declaration
Swift
public func createOrUpdateKeyFile(encryptedKeyFileBlob: Data) throws -> Promise<Data>Parameters
encryptedKeyFileBlobThe encrypted KeyFile bytes
Return Value
The encrypted KeyFile bytes
-
This will return the KeyFile for the passed in user from the OFS in its raw form (bytes). NOTE: KeyFiles are always encrypted. Thus, they bytes returned are encrypted. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func getKeyFile() throws -> Promise<Data?>Return Value
The encrypted bytes of the KeyFile
-
Delete the users KeyFile from the OFS.
Throws
AbsioError
Declaration
Swift
public func deleteKeyFile() throws -> Promise<Void>Return Value
The encrypted bytes of the KeyFile
-
This will end an authenticated session.
Throws
AbsioErrorDeclaration
Swift
public override func logout() throws -> Promise<Void>
-
Persist the SecuredContainer as a new item in the OFS and returns it. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func createContainer(securedContainer: SecuredContainer, completionHandler: @escaping (SecuredContainer) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
securedContainerThe SecuredContainer to persist in the OFS.
Return Value
The SecuredContainer.
-
Get all available containers IDs Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func getAllContainers(completionHandler: @escaping ([UUID]) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfReturn Value
Container IDs array
-
This is used to create or update public key metadata (including the key itself) in the OFS database of the authenticated user. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func createOrUpdatePublicKey(publicKey: PublicKey, completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
publicKeyThe key data to create or update.
-
This gets the latest active public key that match the user ID and type from the encrypted database in the OFS. This calls GetListAsync and processes the list for active keys. It is needed for the IPublicKeySource interface.
Throws
AbsioError
Declaration
Swift
public func getLatestActivePublicKey(userId: UUID, keyType: KeyType, index: Int?, completionHandler: @escaping (PublicKey?) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
userIdThe user’s ID.
keyTypeKey type
indexOptional. Key index
Return Value
The latest active public key metadata (including the key) for the user of the specified type
-
This gets all public keys that match the user ID type and index from the encrypted database in the OFS.
Throws
AbsioError
Declaration
Swift
public func getPublicKeys(userId: UUID?, keyType: KeyType?, index: Int?, completionHandler: @escaping ([PublicKey]) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
userIdThe user’s ID.
keyTypeKey type
indexOptional. Key index
Return Value
A list of public key metadata (including the key) for the user of the specified type.
-
This deletes all public keys that match the user ID, type and index from the encrypted database in the OFS.
Declaration
Swift
public func deletePublicKeys(userId: UUID, keyType: KeyType? = nil, index: Int? = nil, completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
userIdThe user’s ID.
keyTypeKey type
indexOptional. Key index
-
This will create a new user stored in the OFS. A KeyRing and UserId will be created for the user. The KeyRing will be stored in the OFS as an encrypted KeyFile. All mappers will be created and initialized. NOTE: Both the password and passphrase are required. If they are not supplied an ArgumentException will be thrown. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func register(password: String, passphrase: String, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
passwordThe password used to encrypt the KeyRing portion of the KeyFile.
passphraseThe passphrase used to encrypt the password portion of the KeyFile.
Return Value
The encrypted KeyFile data
-
Authenticates the user locally by decrypting the KeyFile to get their KeyRing and then logs into the encrypted database in the OFS. Password and passphrase are both listed as optional parameters, but at least one must be included. If the password is not included, the passphrase will be used to get the password from the KeyFile. If no passphrase was included when the KeyFile was created the operation will fail. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(userId: UUID, password: String? = nil, passphrase: String? = nil, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
userIdThe user’s ID.
passwordOptional. The user’s password.
passphraseOptional. The user’s passphrase.
Return Value
The encrypted KeyFile data
-
Authenticates the user locally by logging into the encrypted database in the OFS. If there is no encrypted database in the OFS one will be created. All mappers will be created and initialized. This will throw an error on failure. When successful the session will be authenticated.
Throws
AbsioError
Declaration
Swift
public func logIn(keyRing: KeyRing, completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
keyRingThe user’s private key ring.
-
This is used to change the password and/or passphrase of a user. This will cause the KeyFile to be re-encrypted with the new password (used for the KeyRing portion). If a passphrase is supplied, the user will be allowed to authenticate (see login) with the passphrase in addition to the password. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func changeCredentials(password: String, passphrase: String, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
passwordThe password used to encrypt the KeyRing.
passphraseIf not null, used to encrypt the password allowing access to the KeyRing when the password is forgot.
Return Value
The encrypted KeyFile data
-
This will return the KeyFile for the passed in user from the OFS in its raw form (bytes). NOTE: KeyFiles are always encrypted. Thus, they bytes returned are encrypted. Calling this method requires an authenticated session. See login for authenticating.
Throws
AbsioError
Declaration
Swift
public func getKeyFile(completionHandler: @escaping (Data?) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfReturn Value
The encrypted bytes of the KeyFile
-
Delete the users KeyFile from the OFS.
Throws
AbsioError
Declaration
Swift
public func deleteKeyFile(completionHandler: @escaping () -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfReturn Value
The encrypted bytes of the KeyFile
-
Creates or updates the user’s KeyFile bytes in the OFS, possibly creating both directory and file.
Throws
AbsioError
Declaration
Swift
public func createOrUpdateKeyFile(encryptedKeyFileBlob: Data, completionHandler: @escaping (Data) -> Void, errorHandler: @escaping (Error) -> Void, queue: DispatchQueue? = nil) throws -> SelfParameters
encryptedKeyFileBlobThe encrypted KeyFile bytes
completionHandlerCompletion Handler
errorHandlerError Handler
queueOptional. Custom queue to run callback on. If not specified DispatchQueue.main queue will be used
Return Value
The encrypted KeyFile bytes
View on GitHub
OfsProvider Class Reference