Skip to content
Snippets Groups Projects
Commit b2ccecfa authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add CMixManagerRestore functor

parent b5ae112e
No related branches found
No related tags found
1 merge request!102Release 1.0.0
......@@ -3,6 +3,7 @@ import Bindings
public struct CMixManager {
public var hasStorage: CMixManagerHasStorage
public var create: CMixManagerCreate
public var restore: CMixManagerRestore
public var load: CMixManagerLoad
public var remove: CMixManagerRemove
}
......@@ -21,7 +22,8 @@ extension CMixManager {
passwordStorage: PasswordStorage,
newCMix: NewCMix = .live,
getCMixParams: GetCMixParams = .liveDefault,
loadCMix: LoadCMix = .live
loadCMix: LoadCMix = .live,
newCMixFromBackup: NewCMixFromBackup = .live
) -> CMixManager {
CMixManager(
hasStorage: .live(
......@@ -39,6 +41,15 @@ extension CMixManager {
getCMixParams: getCMixParams,
loadCMix: loadCMix
),
restore: .live(
environment: environment,
downloadNDF: downloadNDF,
generateSecret: generateSecret,
passwordStorage: passwordStorage,
directoryPath: directoryPath,
fileManager: fileManager,
newCMixFromBackup: newCMixFromBackup
),
load: .live(
directoryPath: directoryPath,
passwordStorage: passwordStorage,
......@@ -57,6 +68,7 @@ extension CMixManager {
public static let unimplemented = CMixManager(
hasStorage: .unimplemented,
create: .unimplemented,
restore: .unimplemented,
load: .unimplemented,
remove: .unimplemented
)
......
import Foundation
import XCTestDynamicOverlay
public struct CMixManagerRestore {
public var run: (Data, String) throws -> BackupReport
public func callAsFunction(
backup: Data,
passphrase: String
) throws -> BackupReport {
try run(backup, passphrase)
}
}
extension CMixManagerRestore {
public static func live(
environment: Environment,
downloadNDF: DownloadAndVerifySignedNdf,
generateSecret: GenerateSecret,
passwordStorage: PasswordStorage,
directoryPath: String,
fileManager: FileManager,
newCMixFromBackup: NewCMixFromBackup
) -> CMixManagerRestore {
CMixManagerRestore { backup, passphrase in
let ndfData = try downloadNDF(environment)
let password = generateSecret()
try passwordStorage.save(password)
try? fileManager.removeItem(atPath: directoryPath)
try? fileManager.createDirectory(atPath: directoryPath, withIntermediateDirectories: true)
return try newCMixFromBackup(
ndfJSON: String(data: ndfData, encoding: .utf8)!,
storageDir: directoryPath,
backupPassphrase: passphrase,
sessionPassword: password,
backupFileContents: backup
)
}
}
}
extension CMixManagerRestore {
public static let unimplemented = CMixManagerRestore(
run: XCTUnimplemented("\(Self.self)")
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment