diff --git a/Sources/ElixxirDAppsSDK/Errors.swift b/Sources/ElixxirDAppsSDK/Errors.swift index acb286921b3942040e35de91cd173827c50f5c03..ae4ae8ae8eb88d81cf516be75899e78f03811062 100644 --- a/Sources/ElixxirDAppsSDK/Errors.swift +++ b/Sources/ElixxirDAppsSDK/Errors.swift @@ -1,3 +1,7 @@ public struct BindingsDownloadAndVerifySignedNdfWithUrlUnknownError: Error, Equatable { public init() {} } + +public struct BindingsGenerateSecretUnknownError: Error, Equatable { + public init() {} +} diff --git a/Sources/ElixxirDAppsSDK/PasswordGenerator.swift b/Sources/ElixxirDAppsSDK/PasswordGenerator.swift new file mode 100644 index 0000000000000000000000000000000000000000..251ea87399bbcd310c56dd78af6908d802f3aaf1 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/PasswordGenerator.swift @@ -0,0 +1,27 @@ +import Bindings + +public struct PasswordGenerator { + public var run: () throws -> Data + + public func callAsFunction() throws -> Data { + try run() + } +} + +extension PasswordGenerator { + public static let live = PasswordGenerator { + guard let secret = BindingsGenerateSecret(32) else { + throw BindingsGenerateSecretUnknownError() + } + return secret + } +} + +#if DEBUG +extension PasswordGenerator { + public static let failing = PasswordGenerator { + struct NotImplemented: Error {} + throw NotImplemented() + } +} +#endif