From 0fde703848cc20fa9618c92611f6f9a4621cac54 Mon Sep 17 00:00:00 2001 From: Sammy Khamis Date: Thu, 21 Oct 2021 11:55:47 -1000 Subject: [PATCH] Version 0.0.7 (#17) Cut release version 0.0.7 --- Package.swift | 4 +- generated/logins/Generated/logins.swift | 523 +++++++++++++++----- generated/logins/Generated/loginsFFI.h | 100 ++-- generated/logins/Logins/LoginsStorage.swift | 281 ++++------- generated/nimbus/Nimbus/NimbusCreate.swift | 15 +- generated/push/Generated/push.swift | 36 +- generated/push/Generated/pushFFI.h | 26 +- generated/sync15/SyncUnlockInfo.swift | 4 +- 8 files changed, 590 insertions(+), 399 deletions(-) diff --git a/Package.swift b/Package.swift index 5b64064f..92deeaad 100644 --- a/Package.swift +++ b/Package.swift @@ -41,8 +41,8 @@ let package = Package( // For release artifacts, reference the MozillaRustComponents as a URL with checksum. // IMPORTANT: The checksum has to be on the line directly after the `url` // this is important for our release script so that all values are updated correctly - url: "https://117909-129966583-gh.circle-artifacts.com/0/dist/MozillaRustComponents.xcframework.zip", - checksum: "92a66ee992a3848dae8319be996833120e9a86f2bc08354d181b81197bf79e4e" + url: "https://118551-129966583-gh.circle-artifacts.com/0/dist/MozillaRustComponents.xcframework.zip", + checksum: "2195ff4b9f942cf8dc66461514af57be56e7c663f37e3e5d5b7f9a3adc5cf71f" // For local testing, you can point at an (unzipped) XCFramework that's part of the repo. // Note that you have to actually check it in and make a tag for it to work correctly. diff --git a/generated/logins/Generated/logins.swift b/generated/logins/Generated/logins.swift index b87c3820..343c7744 100644 --- a/generated/logins/Generated/logins.swift +++ b/generated/logins/Generated/logins.swift @@ -14,7 +14,7 @@ private extension RustBuffer { // Allocate a new buffer, copying the contents of a `UInt8` array. init(bytes: [UInt8]) { let rbuf = bytes.withUnsafeBufferPointer { ptr in - try! rustCall { ffi_logins_f90f_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_logins_5236_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) } @@ -22,7 +22,7 @@ private extension RustBuffer { // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_logins_f90f_rustbuffer_free(self, $0) } + try! rustCall { ffi_logins_5236_rustbuffer_free(self, $0) } } } @@ -273,7 +273,7 @@ extension String: ViaFfi { fileprivate static func lift(_ v: FfiType) throws -> Self { defer { - try! rustCall { ffi_logins_f90f_rustbuffer_free(v, $0) } + try! rustCall { ffi_logins_5236_rustbuffer_free(v, $0) } } if v.data == nil { return String() @@ -289,7 +289,7 @@ extension String: ViaFfi { // The swift string gives us a trailing null byte, we don't want it. let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) let bytes = ForeignBytes(bufferPointer: buf) - return try! rustCall { ffi_logins_f90f_rustbuffer_from_bytes(bytes, $0) } + return try! rustCall { ffi_logins_5236_rustbuffer_from_bytes(bytes, $0) } } } } @@ -365,10 +365,10 @@ public enum LoginsStorageError { case NoSuchRecord(message: String) // Simple error enums only carry a message - case IdCollision(message: String) + case InvalidRecord(message: String) // Simple error enums only carry a message - case InvalidRecord(message: String) + case CryptoError(message: String) // Simple error enums only carry a message case InvalidKey(message: String) @@ -400,11 +400,11 @@ extension LoginsStorageError: ViaFfiUsingByteBuffer, ViaFfi { message: try String.read(from: buf) ) - case 5: return .IdCollision( + case 5: return .InvalidRecord( message: try String.read(from: buf) ) - case 6: return .InvalidRecord( + case 6: return .CryptoError( message: try String.read(from: buf) ) @@ -438,10 +438,10 @@ extension LoginsStorageError: ViaFfiUsingByteBuffer, ViaFfi { case let .NoSuchRecord(message): buf.writeInt(Int32(4)) message.write(into: buf) - case let .IdCollision(message): + case let .InvalidRecord(message): buf.writeInt(Int32(5)) message.write(into: buf) - case let .InvalidRecord(message): + case let .CryptoError(message): buf.writeInt(Int32(6)) message.write(into: buf) case let .InvalidKey(message): @@ -498,62 +498,141 @@ private func makeRustCall(_ callback: (UnsafeMutablePointer) } } -public struct Login { - public var id: String - public var hostname: String - public var password: String - public var username: String +public struct LoginFields { + public var origin: String public var httpRealm: String? - public var formSubmitUrl: String? + public var formActionOrigin: String? public var usernameField: String public var passwordField: String - public var timesUsed: Int64 - public var timeCreated: Int64 - public var timeLastUsed: Int64 - public var timePasswordChanged: Int64 // Default memberwise initializers are never public by default, so we // declare one manually. - public init(id: String, hostname: String, password: String, username: String, httpRealm: String?, formSubmitUrl: String?, usernameField: String, passwordField: String, timesUsed: Int64, timeCreated: Int64, timeLastUsed: Int64, timePasswordChanged: Int64) { - self.id = id - self.hostname = hostname - self.password = password - self.username = username + public init(origin: String, httpRealm: String?, formActionOrigin: String?, usernameField: String, passwordField: String) { + self.origin = origin self.httpRealm = httpRealm - self.formSubmitUrl = formSubmitUrl + self.formActionOrigin = formActionOrigin self.usernameField = usernameField self.passwordField = passwordField - self.timesUsed = timesUsed - self.timeCreated = timeCreated - self.timeLastUsed = timeLastUsed - self.timePasswordChanged = timePasswordChanged } } -extension Login: Equatable, Hashable { - public static func == (lhs: Login, rhs: Login) -> Bool { - if lhs.id != rhs.id { +extension LoginFields: Equatable, Hashable { + public static func == (lhs: LoginFields, rhs: LoginFields) -> Bool { + if lhs.origin != rhs.origin { return false } - if lhs.hostname != rhs.hostname { + if lhs.httpRealm != rhs.httpRealm { return false } - if lhs.password != rhs.password { + if lhs.formActionOrigin != rhs.formActionOrigin { return false } - if lhs.username != rhs.username { + if lhs.usernameField != rhs.usernameField { return false } - if lhs.httpRealm != rhs.httpRealm { + if lhs.passwordField != rhs.passwordField { return false } - if lhs.formSubmitUrl != rhs.formSubmitUrl { + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(origin) + hasher.combine(httpRealm) + hasher.combine(formActionOrigin) + hasher.combine(usernameField) + hasher.combine(passwordField) + } +} + +private extension LoginFields { + static func read(from buf: Reader) throws -> LoginFields { + return try LoginFields( + origin: String.read(from: buf), + httpRealm: String?.read(from: buf), + formActionOrigin: String?.read(from: buf), + usernameField: String.read(from: buf), + passwordField: String.read(from: buf) + ) + } + + func write(into buf: Writer) { + origin.write(into: buf) + httpRealm.write(into: buf) + formActionOrigin.write(into: buf) + usernameField.write(into: buf) + passwordField.write(into: buf) + } +} + +extension LoginFields: ViaFfiUsingByteBuffer, ViaFfi {} + +public struct SecureLoginFields { + public var password: String + public var username: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(password: String, username: String) { + self.password = password + self.username = username + } +} + +extension SecureLoginFields: Equatable, Hashable { + public static func == (lhs: SecureLoginFields, rhs: SecureLoginFields) -> Bool { + if lhs.password != rhs.password { return false } - if lhs.usernameField != rhs.usernameField { + if lhs.username != rhs.username { return false } - if lhs.passwordField != rhs.passwordField { + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(password) + hasher.combine(username) + } +} + +private extension SecureLoginFields { + static func read(from buf: Reader) throws -> SecureLoginFields { + return try SecureLoginFields( + password: String.read(from: buf), + username: String.read(from: buf) + ) + } + + func write(into buf: Writer) { + password.write(into: buf) + username.write(into: buf) + } +} + +extension SecureLoginFields: ViaFfiUsingByteBuffer, ViaFfi {} + +public struct RecordFields { + public var id: String + public var timesUsed: Int64 + public var timeCreated: Int64 + public var timeLastUsed: Int64 + public var timePasswordChanged: Int64 + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(id: String, timesUsed: Int64, timeCreated: Int64, timeLastUsed: Int64, timePasswordChanged: Int64) { + self.id = id + self.timesUsed = timesUsed + self.timeCreated = timeCreated + self.timeLastUsed = timeLastUsed + self.timePasswordChanged = timePasswordChanged + } +} + +extension RecordFields: Equatable, Hashable { + public static func == (lhs: RecordFields, rhs: RecordFields) -> Bool { + if lhs.id != rhs.id { return false } if lhs.timesUsed != rhs.timesUsed { @@ -573,13 +652,6 @@ extension Login: Equatable, Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(id) - hasher.combine(hostname) - hasher.combine(password) - hasher.combine(username) - hasher.combine(httpRealm) - hasher.combine(formSubmitUrl) - hasher.combine(usernameField) - hasher.combine(passwordField) hasher.combine(timesUsed) hasher.combine(timeCreated) hasher.combine(timeLastUsed) @@ -587,17 +659,10 @@ extension Login: Equatable, Hashable { } } -private extension Login { - static func read(from buf: Reader) throws -> Login { - return try Login( +private extension RecordFields { + static func read(from buf: Reader) throws -> RecordFields { + return try RecordFields( id: String.read(from: buf), - hostname: String.read(from: buf), - password: String.read(from: buf), - username: String.read(from: buf), - httpRealm: String?.read(from: buf), - formSubmitUrl: String?.read(from: buf), - usernameField: String.read(from: buf), - passwordField: String.read(from: buf), timesUsed: Int64.read(from: buf), timeCreated: Int64.read(from: buf), timeLastUsed: Int64.read(from: buf), @@ -607,13 +672,6 @@ private extension Login { func write(into buf: Writer) { id.write(into: buf) - hostname.write(into: buf) - password.write(into: buf) - username.write(into: buf) - httpRealm.write(into: buf) - formSubmitUrl.write(into: buf) - usernameField.write(into: buf) - passwordField.write(into: buf) timesUsed.write(into: buf) timeCreated.write(into: buf) timeLastUsed.write(into: buf) @@ -621,43 +679,249 @@ private extension Login { } } +extension RecordFields: ViaFfiUsingByteBuffer, ViaFfi {} + +public struct LoginEntry { + public var fields: LoginFields + public var secFields: SecureLoginFields + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(fields: LoginFields, secFields: SecureLoginFields) { + self.fields = fields + self.secFields = secFields + } +} + +extension LoginEntry: Equatable, Hashable { + public static func == (lhs: LoginEntry, rhs: LoginEntry) -> Bool { + if lhs.fields != rhs.fields { + return false + } + if lhs.secFields != rhs.secFields { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(fields) + hasher.combine(secFields) + } +} + +private extension LoginEntry { + static func read(from buf: Reader) throws -> LoginEntry { + return try LoginEntry( + fields: LoginFields.read(from: buf), + secFields: SecureLoginFields.read(from: buf) + ) + } + + func write(into buf: Writer) { + fields.write(into: buf) + secFields.write(into: buf) + } +} + +extension LoginEntry: ViaFfiUsingByteBuffer, ViaFfi {} + +public struct Login { + public var record: RecordFields + public var fields: LoginFields + public var secFields: SecureLoginFields + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(record: RecordFields, fields: LoginFields, secFields: SecureLoginFields) { + self.record = record + self.fields = fields + self.secFields = secFields + } +} + +extension Login: Equatable, Hashable { + public static func == (lhs: Login, rhs: Login) -> Bool { + if lhs.record != rhs.record { + return false + } + if lhs.fields != rhs.fields { + return false + } + if lhs.secFields != rhs.secFields { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(record) + hasher.combine(fields) + hasher.combine(secFields) + } +} + +private extension Login { + static func read(from buf: Reader) throws -> Login { + return try Login( + record: RecordFields.read(from: buf), + fields: LoginFields.read(from: buf), + secFields: SecureLoginFields.read(from: buf) + ) + } + + func write(into buf: Writer) { + record.write(into: buf) + fields.write(into: buf) + secFields.write(into: buf) + } +} + extension Login: ViaFfiUsingByteBuffer, ViaFfi {} -public func openAndGetSalt(path: String, encryptionKey: String) throws -> String { +public struct EncryptedLogin { + public var record: RecordFields + public var fields: LoginFields + public var secFields: String + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(record: RecordFields, fields: LoginFields, secFields: String) { + self.record = record + self.fields = fields + self.secFields = secFields + } +} + +extension EncryptedLogin: Equatable, Hashable { + public static func == (lhs: EncryptedLogin, rhs: EncryptedLogin) -> Bool { + if lhs.record != rhs.record { + return false + } + if lhs.fields != rhs.fields { + return false + } + if lhs.secFields != rhs.secFields { + return false + } + return true + } + + public func hash(into hasher: inout Hasher) { + hasher.combine(record) + hasher.combine(fields) + hasher.combine(secFields) + } +} + +private extension EncryptedLogin { + static func read(from buf: Reader) throws -> EncryptedLogin { + return try EncryptedLogin( + record: RecordFields.read(from: buf), + fields: LoginFields.read(from: buf), + secFields: String.read(from: buf) + ) + } + + func write(into buf: Writer) { + record.write(into: buf) + fields.write(into: buf) + secFields.write(into: buf) + } +} + +extension EncryptedLogin: ViaFfiUsingByteBuffer, ViaFfi {} + +public func createKey() throws -> String { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_create_key($0) + } + return try String.lift(_retval) +} + +public func decryptLogin(login: EncryptedLogin, encryptionKey: String) throws -> Login { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_decrypt_login(login.lower(), encryptionKey.lower(), $0) + } + return try Login.lift(_retval) +} + +public func encryptLogin(login: Login, encryptionKey: String) throws -> EncryptedLogin { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_encrypt_login(login.lower(), encryptionKey.lower(), $0) + } + return try EncryptedLogin.lift(_retval) +} + +public func decryptFields(secFields: String, encryptionKey: String) throws -> SecureLoginFields { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_decrypt_fields(secFields.lower(), encryptionKey.lower(), $0) + } + return try SecureLoginFields.lift(_retval) +} + +public func encryptFields(secFields: SecureLoginFields, encryptionKey: String) throws -> String { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_encrypt_fields(secFields.lower(), encryptionKey.lower(), $0) + } + return try String.lift(_retval) +} + +public func createCanary(text: String, encryptionKey: String) throws -> String { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_open_and_get_salt(path.lower(), encryptionKey.lower(), $0) + logins_5236_create_canary(text.lower(), encryptionKey.lower(), $0) } return try String.lift(_retval) } -public func openAndMigrateToPlaintextHeader(path: String, encryptionKey: String, salt: String) throws { - try +public func checkCanary(canary: String, text: String, encryptionKey: String) throws -> Bool { + let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_open_and_migrate_to_plaintext_header(path.lower(), encryptionKey.lower(), salt.lower(), $0) + logins_5236_check_canary(canary.lower(), text.lower(), encryptionKey.lower(), $0) } + return try Bool.lift(_retval) +} + +public func migrateLogins(path: String, newEncryptionKey: String, sqlcipherPath: String, sqlcipherKey: String, salt: String?) throws -> String { + let _retval = try + + rustCallWithError(LoginsStorageError.self) { + logins_5236_migrate_logins(path.lower(), newEncryptionKey.lower(), sqlcipherPath.lower(), sqlcipherKey.lower(), salt.lower(), $0) + } + return try String.lift(_retval) } public protocol LoginStoreProtocol { - func checkValidWithNoDupes(login: Login) throws - func add(login: Login) throws -> String + func checkValidWithNoDupes(id: String, login: LoginEntry, encryptionKey: String) throws + func add(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin + func update(id: String, login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin + func addOrUpdate(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin func delete(id: String) throws -> Bool func wipe() throws func wipeLocal() throws func reset() throws - func disableMemSecurity() throws - func rekeyDatabase(newEncryptionKey: String) throws func touch(id: String) throws - func list() throws -> [Login] - func getByBaseDomain(baseDomain: String) throws -> [Login] - func potentialDupesIgnoringUsername(login: Login) throws -> [Login] - func get(id: String) throws -> Login? - func update(login: Login) throws - func importMultiple(login: [Login]) throws -> String + func list() throws -> [EncryptedLogin] + func getByBaseDomain(baseDomain: String) throws -> [EncryptedLogin] + func findLoginToUpdate(look: LoginEntry, encryptionKey: String) throws -> Login? + func potentialDupesIgnoringUsername(id: String, login: LoginEntry) throws -> [EncryptedLogin] + func get(id: String) throws -> EncryptedLogin? + func importMultiple(login: [Login], encryptionKey: String) throws -> String func registerWithSyncManager() - func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String + func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String, localEncryptionKey: String) throws -> String } public class LoginStore: LoginStoreProtocol { @@ -670,134 +934,129 @@ public class LoginStore: LoginStoreProtocol { self.pointer = pointer } - public convenience init(path: String, encryptionKey: String) throws { + public convenience init(path: String) throws { self.init(unsafeFromRawPointer: try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_new(path.lower(), encryptionKey.lower(), $0) + logins_5236_LoginStore_new(path.lower(), $0) }) } deinit { - try! rustCall { ffi_logins_f90f_LoginStore_object_free(pointer, $0) } + try! rustCall { ffi_logins_5236_LoginStore_object_free(pointer, $0) } } - public static func newWithSalt(path: String, encryptionKey: String, salt: String) throws -> LoginStore { - return LoginStore(unsafeFromRawPointer: try - - rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_new_with_salt(path.lower(), encryptionKey.lower(), salt.lower(), $0) - }) - } - - public func checkValidWithNoDupes(login: Login) throws { + public func checkValidWithNoDupes(id: String, login: LoginEntry, encryptionKey: String) throws { try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_check_valid_with_no_dupes(self.pointer, login.lower(), $0) + logins_5236_LoginStore_check_valid_with_no_dupes(self.pointer, id.lower(), login.lower(), encryptionKey.lower(), $0) } } - public func add(login: Login) throws -> String { + public func add(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_add(self.pointer, login.lower(), $0) + logins_5236_LoginStore_add(self.pointer, login.lower(), encryptionKey.lower(), $0) } - return try String.lift(_retval) + return try EncryptedLogin.lift(_retval) } - public func delete(id: String) throws -> Bool { + public func update(id: String, login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_delete(self.pointer, id.lower(), $0) + logins_5236_LoginStore_update(self.pointer, id.lower(), login.lower(), encryptionKey.lower(), $0) } - return try Bool.lift(_retval) + return try EncryptedLogin.lift(_retval) } - public func wipe() throws { - try + public func addOrUpdate(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { + let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_wipe(self.pointer, $0) + logins_5236_LoginStore_add_or_update(self.pointer, login.lower(), encryptionKey.lower(), $0) } + return try EncryptedLogin.lift(_retval) } - public func wipeLocal() throws { - try + public func delete(id: String) throws -> Bool { + let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_wipe_local(self.pointer, $0) + logins_5236_LoginStore_delete(self.pointer, id.lower(), $0) } + return try Bool.lift(_retval) } - public func reset() throws { + public func wipe() throws { try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_reset(self.pointer, $0) + logins_5236_LoginStore_wipe(self.pointer, $0) } } - public func disableMemSecurity() throws { + public func wipeLocal() throws { try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_disable_mem_security(self.pointer, $0) + logins_5236_LoginStore_wipe_local(self.pointer, $0) } } - public func rekeyDatabase(newEncryptionKey: String) throws { + public func reset() throws { try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_rekey_database(self.pointer, newEncryptionKey.lower(), $0) + logins_5236_LoginStore_reset(self.pointer, $0) } } public func touch(id: String) throws { try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_touch(self.pointer, id.lower(), $0) + logins_5236_LoginStore_touch(self.pointer, id.lower(), $0) } } - public func list() throws -> [Login] { + public func list() throws -> [EncryptedLogin] { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_list(self.pointer, $0) + logins_5236_LoginStore_list(self.pointer, $0) } - return try [Login].lift(_retval) + return try [EncryptedLogin].lift(_retval) } - public func getByBaseDomain(baseDomain: String) throws -> [Login] { + public func getByBaseDomain(baseDomain: String) throws -> [EncryptedLogin] { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_get_by_base_domain(self.pointer, baseDomain.lower(), $0) + logins_5236_LoginStore_get_by_base_domain(self.pointer, baseDomain.lower(), $0) } - return try [Login].lift(_retval) + return try [EncryptedLogin].lift(_retval) } - public func potentialDupesIgnoringUsername(login: Login) throws -> [Login] { + public func findLoginToUpdate(look: LoginEntry, encryptionKey: String) throws -> Login? { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_potential_dupes_ignoring_username(self.pointer, login.lower(), $0) + logins_5236_LoginStore_find_login_to_update(self.pointer, look.lower(), encryptionKey.lower(), $0) } - return try [Login].lift(_retval) + return try Login?.lift(_retval) } - public func get(id: String) throws -> Login? { + public func potentialDupesIgnoringUsername(id: String, login: LoginEntry) throws -> [EncryptedLogin] { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_get(self.pointer, id.lower(), $0) + logins_5236_LoginStore_potential_dupes_ignoring_username(self.pointer, id.lower(), login.lower(), $0) } - return try Login?.lift(_retval) + return try [EncryptedLogin].lift(_retval) } - public func update(login: Login) throws { - try + public func get(id: String) throws -> EncryptedLogin? { + let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_update(self.pointer, login.lower(), $0) + logins_5236_LoginStore_get(self.pointer, id.lower(), $0) } + return try EncryptedLogin?.lift(_retval) } - public func importMultiple(login: [Login]) throws -> String { + public func importMultiple(login: [Login], encryptionKey: String) throws -> String { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_import_multiple(self.pointer, login.lower(), $0) + logins_5236_LoginStore_import_multiple(self.pointer, login.lower(), encryptionKey.lower(), $0) } return try String.lift(_retval) } @@ -805,14 +1064,14 @@ public class LoginStore: LoginStoreProtocol { public func registerWithSyncManager() { try! rustCall { - logins_f90f_LoginStore_register_with_sync_manager(self.pointer, $0) + logins_5236_LoginStore_register_with_sync_manager(self.pointer, $0) } } - public func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String) throws -> String { + public func sync(keyId: String, accessToken: String, syncKey: String, tokenserverUrl: String, localEncryptionKey: String) throws -> String { let _retval = try rustCallWithError(LoginsStorageError.self) { - logins_f90f_LoginStore_sync(self.pointer, keyId.lower(), accessToken.lower(), syncKey.lower(), tokenserverUrl.lower(), $0) + logins_5236_LoginStore_sync(self.pointer, keyId.lower(), accessToken.lower(), syncKey.lower(), tokenserverUrl.lower(), localEncryptionKey.lower(), $0) } return try String.lift(_retval) } diff --git a/generated/logins/Generated/loginsFFI.h b/generated/logins/Generated/loginsFFI.h index 023130a6..691db7f4 100644 --- a/generated/logins/Generated/loginsFFI.h +++ b/generated/logins/Generated/loginsFFI.h @@ -44,107 +44,127 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V3 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_logins_f90f_LoginStore_object_free( +void ffi_logins_5236_LoginStore_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull logins_f90f_LoginStore_new( - RustBuffer path,RustBuffer encryption_key, +void*_Nonnull logins_5236_LoginStore_new( + RustBuffer path, RustCallStatus *_Nonnull out_status ); -void*_Nonnull logins_f90f_LoginStore_new_with_salt( - RustBuffer path,RustBuffer encryption_key,RustBuffer salt, +void logins_5236_LoginStore_check_valid_with_no_dupes( + void*_Nonnull ptr,RustBuffer id,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_check_valid_with_no_dupes( - void*_Nonnull ptr,RustBuffer login, +RustBuffer logins_5236_LoginStore_add( + void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_add( - void*_Nonnull ptr,RustBuffer login, +RustBuffer logins_5236_LoginStore_update( + void*_Nonnull ptr,RustBuffer id,RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -int8_t logins_f90f_LoginStore_delete( +RustBuffer logins_5236_LoginStore_add_or_update( + void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, + RustCallStatus *_Nonnull out_status + ); +int8_t logins_5236_LoginStore_delete( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_wipe( +void logins_5236_LoginStore_wipe( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_wipe_local( +void logins_5236_LoginStore_wipe_local( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_reset( +void logins_5236_LoginStore_reset( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_disable_mem_security( +void logins_5236_LoginStore_touch( + void*_Nonnull ptr,RustBuffer id, + RustCallStatus *_Nonnull out_status + ); +RustBuffer logins_5236_LoginStore_list( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_rekey_database( - void*_Nonnull ptr,RustBuffer new_encryption_key, +RustBuffer logins_5236_LoginStore_get_by_base_domain( + void*_Nonnull ptr,RustBuffer base_domain, + RustCallStatus *_Nonnull out_status + ); +RustBuffer logins_5236_LoginStore_find_login_to_update( + void*_Nonnull ptr,RustBuffer look,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_touch( +RustBuffer logins_5236_LoginStore_potential_dupes_ignoring_username( + void*_Nonnull ptr,RustBuffer id,RustBuffer login, + RustCallStatus *_Nonnull out_status + ); +RustBuffer logins_5236_LoginStore_get( void*_Nonnull ptr,RustBuffer id, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_list( +RustBuffer logins_5236_LoginStore_import_multiple( + void*_Nonnull ptr,RustBuffer login,RustBuffer encryption_key, + RustCallStatus *_Nonnull out_status + ); +void logins_5236_LoginStore_register_with_sync_manager( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_get_by_base_domain( - void*_Nonnull ptr,RustBuffer base_domain, +RustBuffer logins_5236_LoginStore_sync( + void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url,RustBuffer local_encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_potential_dupes_ignoring_username( - void*_Nonnull ptr,RustBuffer login, +RustBuffer logins_5236_create_key( + RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_get( - void*_Nonnull ptr,RustBuffer id, +RustBuffer logins_5236_decrypt_login( + RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_update( - void*_Nonnull ptr,RustBuffer login, +RustBuffer logins_5236_encrypt_login( + RustBuffer login,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_import_multiple( - void*_Nonnull ptr,RustBuffer login, +RustBuffer logins_5236_decrypt_fields( + RustBuffer sec_fields,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_f90f_LoginStore_register_with_sync_manager( - void*_Nonnull ptr, +RustBuffer logins_5236_encrypt_fields( + RustBuffer sec_fields,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_LoginStore_sync( - void*_Nonnull ptr,RustBuffer key_id,RustBuffer access_token,RustBuffer sync_key,RustBuffer tokenserver_url, +RustBuffer logins_5236_create_canary( + RustBuffer text,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -RustBuffer logins_f90f_open_and_get_salt( - RustBuffer path,RustBuffer encryption_key, +int8_t logins_5236_check_canary( + RustBuffer canary,RustBuffer text,RustBuffer encryption_key, RustCallStatus *_Nonnull out_status ); -void logins_f90f_open_and_migrate_to_plaintext_header( - RustBuffer path,RustBuffer encryption_key,RustBuffer salt, +RustBuffer logins_5236_migrate_logins( + RustBuffer path,RustBuffer new_encryption_key,RustBuffer sqlcipher_path,RustBuffer sqlcipher_key,RustBuffer salt, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_f90f_rustbuffer_alloc( +RustBuffer ffi_logins_5236_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_f90f_rustbuffer_from_bytes( +RustBuffer ffi_logins_5236_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_logins_f90f_rustbuffer_free( +void ffi_logins_5236_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_logins_f90f_rustbuffer_reserve( +RustBuffer ffi_logins_5236_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/generated/logins/Logins/LoginsStorage.swift b/generated/logins/Logins/LoginsStorage.swift index ee973d9b..4d844270 100644 --- a/generated/logins/Logins/LoginsStorage.swift +++ b/generated/logins/Logins/LoginsStorage.swift @@ -10,6 +10,9 @@ import UIKit #if canImport(MozillaRustComponents) import MozillaRustComponents #endif +#if canImport(Glean) + @_exported import Glean +#endif typealias LoginsStoreError = LoginsStorageError @@ -19,204 +22,38 @@ typealias LoginsStoreError = LoginsStorageError * the queue.sync which we should be moved over to the consumer side of things */ open class LoginsStorage { - private var store: LoginStore? - let dbPath: String + private var store: LoginStore private let queue = DispatchQueue(label: "com.mozilla.logins-storage") - public init(databasePath: String) { - dbPath = databasePath - } - - deinit { - self.close() - } - - private func doDestroy() { - store = nil - } - - /// Manually close the database (this is automatically called from deinit(), so - /// manually calling it is usually unnecessary). - open func close() { - queue.sync { - self.doDestroy() - } - } - - /// Test if the database is locked. - open func isLocked() -> Bool { - return queue.sync { - self.store == nil - } - } - - // helper to reduce boilerplate, we don't use queue.sync - // since we expect the caller to do so. - private func getUnlockedStore() throws -> LoginStore { - if store == nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - return store! - } - - /// Unlock the database and reads the salt. - /// - /// Throws `LockError.mismatched` if the database is already unlocked. - /// - /// Throws a `LoginStoreError.InvalidKey` if the key is incorrect, or if dbPath does not point - /// to a database, (may also throw `LoginStoreError.Unspecified` or `.Panic`). - open func getDbSaltForKey(key: String) throws -> String { - try queue.sync { - if self.store != nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - return try openAndGetSalt(path: self.dbPath, encryptionKey: key) - } - } - - /// Migrate an existing database to a sqlcipher plaintext header. - /// If your application calls this method without reading and persisting - /// the salt, the database will be rendered un-usable. - /// - /// Throws `LockError.mismatched` if the database is already unlocked. - /// - /// Throws a `LoginStoreError.InvalidKey` if the key is incorrect, or if dbPath does not point - /// to a database, (may also throw `LoginStoreError.Unspecified` or `.Panic`). - open func migrateToPlaintextHeader(key: String, salt: String) throws { - try queue.sync { - if self.store != nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - try openAndMigrateToPlaintextHeader(path: self.dbPath, encryptionKey: key, salt: salt) - } - } - - private func doOpen(_ key: String, salt: String?) throws { - if store != nil { - return - } - if let salt = salt { - store = try LoginStore.newWithSalt(path: dbPath, encryptionKey: key, salt: salt) - } else { - store = try LoginStore(path: dbPath, encryptionKey: key) - } - } - - /// Unlock the database. - /// `key` must be a random string. - /// `salt` must be an hex-encoded string of 32 characters (e.g. `a6a97a03ac3e5a20617175355ea2da5c`). - /// - /// Throws `LockError.mismatched` if the database is already unlocked. - /// - /// Throws a `LoginStoreError.InvalidKey` if the key is incorrect, or if dbPath does not point - /// to a database, (may also throw `LoginStoreError.Unspecified` or `.Panic`). - open func unlockWithKeyAndSalt(key: String, salt: String) throws { - try queue.sync { - if self.store != nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - try self.doOpen(key, salt: salt) - } - } - - /// Equivalent to `unlockWithKeyAndSalt(key:, salt:)`, but does not throw if the - /// database is already unlocked. - open func ensureUnlockedWithKeyAndSalt(key: String, salt: String) throws { - try queue.sync { - try self.doOpen(key, salt: salt) - } - } - - /// Unlock the database. - /// - /// Throws `LockError.mismatched` if the database is already unlocked. - /// - /// Throws a `LoginStoreError.InvalidKey` if the key is incorrect, or if dbPath does not point - /// to a database, (may also throw `LoginStoreError.Unspecified` or `.Panic`). - @available(*, deprecated, message: "Use unlockWithKeyAndSalt instead.") - open func unlock(withEncryptionKey key: String) throws { - try queue.sync { - if self.store != nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - try self.doOpen(key, salt: nil) - } - } - - /// equivalent to `unlock(withEncryptionKey:)`, but does not throw if the - /// database is already unlocked. - @available(*, deprecated, message: "Use ensureUnlockedWithKeyAndSalt instead.") - open func ensureUnlocked(withEncryptionKey key: String) throws { - try queue.sync { - try self.doOpen(key, salt: nil) - } - } - - /// Lock the database. - /// - /// Throws `LockError.mismatched` if the database is already locked. - open func lock() throws { - try queue.sync { - if self.store == nil { - throw LoginsStoreError.MismatchedLock(message: "Mismatched Lock") - } - self.doDestroy() - } - } - - /// Locks the database, but does not throw in the case that the database is - /// already locked. This is an alias for `close()`, provided for convenience - /// (and consistency with Android) - open func ensureLocked() { - close() + public init(databasePath: String) throws { + store = try LoginStore(path: databasePath) } /// Delete all locally stored login sync metadata. It's unclear if /// there's ever a reason for users to call this open func reset() throws { try queue.sync { - try getUnlockedStore().reset() - } - } - - /// Disable memory security, which prevents keys from being swapped to disk. - /// This allows some esoteric attacks, but can have a performance benefit. - open func disableMemSecurity() throws { - try queue.sync { - try getUnlockedStore().disableMemSecurity() - } - } - - open func rekeyDatabase(withNewEncryptionKey newKey: String) throws { - try queue.sync { - try self.getUnlockedStore().rekeyDatabase(newEncryptionKey: newKey) + try self.store.reset() } } /// Delete all locally stored login data. open func wipe() throws { try queue.sync { - try self.getUnlockedStore().wipe() + try self.store.wipe() } } open func wipeLocal() throws { try queue.sync { - try self.getUnlockedStore().wipeLocal() + try self.store.wipeLocal() } } /// Delete the record with the given ID. Returns false if no such record existed. open func delete(id: String) throws -> Bool { return try queue.sync { - return try self.getUnlockedStore().delete(id: id) - } - } - - /// Ensure that the record is valid and a duplicate record doesn't exist. - open func ensureValid(login: Login) throws { - try queue.sync { - try self.getUnlockedStore().checkValidWithNoDupes(login: login) + return try self.store.delete(id: id) } } @@ -225,7 +62,7 @@ open class LoginsStorage { /// Throws `LoginStoreError.NoSuchRecord` if there was no such record. open func touch(id: String) throws { try queue.sync { - try self.getUnlockedStore().touch(id: id) + try self.store.touch(id: id) } } @@ -233,64 +70,116 @@ open class LoginsStorage { /// then this throws `LoginStoreError.DuplicateGuid` if there is a collision /// /// Returns the `id` of the newly inserted record. - open func add(login: Login) throws -> String { + open func add(login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { return try queue.sync { - return try self.getUnlockedStore().add(login: login) + return try self.store.add(login: login, encryptionKey: encryptionKey) } } /// Update `login` in the database. If `login.id` does not refer to a known /// login, then this throws `LoginStoreError.NoSuchRecord`. - open func update(login: Login) throws { - try queue.sync { - try self.getUnlockedStore().update(login: login) + open func update(id: String, login: LoginEntry, encryptionKey: String) throws -> EncryptedLogin { + return try queue.sync { + return try self.store.update(id: id, login: login, encryptionKey: encryptionKey) } } /// Get the record with the given id. Returns nil if there is no such record. - open func get(id: String) throws -> Login? { + open func get(id: String) throws -> EncryptedLogin? { return try queue.sync { - return try self.getUnlockedStore().get(id: id) + return try self.store.get(id: id) } } /// Get the entire list of records. - open func list() throws -> [Login] { - return try queue.sync { - return try self.getUnlockedStore().list() - } - } - - /// Get the set of potential duplicates ignoring the username of `login`. - open func potentialDupesIgnoringUsername(to login: Login) throws -> [Login] { + open func list() throws -> [EncryptedLogin] { return try queue.sync { - return try self.getUnlockedStore().potentialDupesIgnoringUsername(login: login) + return try self.store.list() } } /// Get the list of records for some base domain. - open func getByBaseDomain(baseDomain: String) throws -> [Login] { + open func getByBaseDomain(baseDomain: String) throws -> [EncryptedLogin] { return try queue.sync { - return try self.getUnlockedStore().getByBaseDomain(baseDomain: baseDomain) + return try self.store.getByBaseDomain(baseDomain: baseDomain) } } /// Register with the sync manager open func registerWithSyncManager() throws { - return try queue.sync { - return try self.getUnlockedStore().registerWithSyncManager() + return queue.sync { + return self.store.registerWithSyncManager() } } open func sync(unlockInfo: SyncUnlockInfo) throws -> String { return try queue.sync { - return try self.getUnlockedStore() + return try self.store .sync( keyId: unlockInfo.kid, accessToken: unlockInfo.fxaAccessToken, syncKey: unlockInfo.syncKey, - tokenserverUrl: unlockInfo.tokenserverURL + tokenserverUrl: unlockInfo.tokenserverURL, + localEncryptionKey: unlockInfo.loginEncryptionKey ) } } } + +public func migrateLoginsWithMetrics( + path: String, + newEncryptionKey: String, + sqlcipherPath: String, + sqlcipherKey: String, + salt: String +) -> Bool { + var didMigrationSucceed = false + + do { + let metrics = try migrateLogins( + path: path, + newEncryptionKey: newEncryptionKey, + sqlcipherPath: sqlcipherPath, + sqlcipherKey: sqlcipherKey, + salt: salt + ) + didMigrationSucceed = true + + recordMigrationMetrics(jsonString: metrics) + } catch let err as NSError { + GleanMetrics.LoginsStoreMigration.errors.add(err.localizedDescription) + } + return didMigrationSucceed +} + +func recordMigrationMetrics(jsonString: String) { + guard + let data = jsonString.data(using: .utf8), + let json = try? JSONSerialization.jsonObject(with: data, options: []), + let metrics = json as? [String: Any] + else { + return + } + + if let processed = metrics["num_processed"] as? Int32 { + GleanMetrics.LoginsStoreMigration.numProcessed.add(processed) + } + + if let succeeded = metrics["num_succeeded"] as? Int32 { + GleanMetrics.LoginsStoreMigration.numSucceeded.add(succeeded) + } + + if let failed = metrics["num_failed"] as? Int32 { + GleanMetrics.LoginsStoreMigration.numFailed.add(failed) + } + + if let duration = metrics["total_duration"] as? UInt64 { + GleanMetrics.LoginsStoreMigration.totalDuration.setRawNanos(duration * 1_000_000) + } + + if let errors = metrics["errors"] as? [String] { + for error in errors { + GleanMetrics.LoginsStoreMigration.errors.add(error) + } + } +} diff --git a/generated/nimbus/Nimbus/NimbusCreate.swift b/generated/nimbus/Nimbus/NimbusCreate.swift index 7d94dee8..6ac0b4e5 100644 --- a/generated/nimbus/Nimbus/NimbusCreate.swift +++ b/generated/nimbus/Nimbus/NimbusCreate.swift @@ -67,6 +67,17 @@ public extension Nimbus { device: UIDevice = .current ) -> AppContext { let info = bundle.infoDictionary ?? [:] + var inferredDateInstalledOn: Date? { + guard + let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last, + let attributes = try? FileManager.default.attributesOfItem(atPath: documentsURL.path) + else { return nil } + return attributes[.creationDate] as? Date + } + let installationDateSinceEpoch = inferredDateInstalledOn.map { + Int64(($0.timeIntervalSince1970 * 1000).rounded()) + } + return AppContext( appName: appSettings.appName, appId: info["CFBundleIdentifier"] as? String ?? "unknown", @@ -81,8 +92,8 @@ public extension Nimbus { osVersion: device.systemVersion, androidSdkVersion: nil, debugTag: "Nimbus.rs", - installationDate: nil, - homeDirectory: NSHomeDirectory(), + installationDate: installationDateSinceEpoch, + homeDirectory: nil, customTargetingAttributes: appSettings.customTargetingAttributes ) } diff --git a/generated/push/Generated/push.swift b/generated/push/Generated/push.swift index 33574272..3b3439d3 100644 --- a/generated/push/Generated/push.swift +++ b/generated/push/Generated/push.swift @@ -14,7 +14,7 @@ private extension RustBuffer { // Allocate a new buffer, copying the contents of a `UInt8` array. init(bytes: [UInt8]) { let rbuf = bytes.withUnsafeBufferPointer { ptr in - try! rustCall { ffi_push_9ca4_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + try! rustCall { ffi_push_b1b4_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } } self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) } @@ -22,7 +22,7 @@ private extension RustBuffer { // Frees the buffer in place. // The buffer must not be used after this is called. func deallocate() { - try! rustCall { ffi_push_9ca4_rustbuffer_free(self, $0) } + try! rustCall { ffi_push_b1b4_rustbuffer_free(self, $0) } } } @@ -273,7 +273,7 @@ extension String: ViaFfi { fileprivate static func lift(_ v: FfiType) throws -> Self { defer { - try! rustCall { ffi_push_9ca4_rustbuffer_free(v, $0) } + try! rustCall { ffi_push_b1b4_rustbuffer_free(v, $0) } } if v.data == nil { return String() @@ -289,7 +289,7 @@ extension String: ViaFfi { // The swift string gives us a trailing null byte, we don't want it. let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) let bytes = ForeignBytes(bufferPointer: buf) - return try! rustCall { ffi_push_9ca4_rustbuffer_from_bytes(bytes, $0) } + return try! rustCall { ffi_push_b1b4_rustbuffer_from_bytes(bytes, $0) } } } } @@ -432,6 +432,9 @@ public enum PushError { // Simple error enums only carry a message case RequestError(message: String) + + // Simple error enums only carry a message + case OpenDatabaseError(message: String) } extension PushError: ViaFfiUsingByteBuffer, ViaFfi { @@ -494,6 +497,10 @@ extension PushError: ViaFfiUsingByteBuffer, ViaFfi { message: try String.read(from: buf) ) + case 15: return .OpenDatabaseError( + message: try String.read(from: buf) + ) + default: throw UniffiInternalError.unexpectedEnumCase } } @@ -542,6 +549,9 @@ extension PushError: ViaFfiUsingByteBuffer, ViaFfi { case let .RequestError(message): buf.writeInt(Int32(14)) message.write(into: buf) + case let .OpenDatabaseError(message): + buf.writeInt(Int32(15)) + message.write(into: buf) } } } @@ -852,18 +862,18 @@ public class PushManager: PushManagerProtocol { self.init(unsafeFromRawPointer: try rustCallWithError(PushError.self) { - push_9ca4_PushManager_new(senderId.lower(), serverHost.lower(), httpProtocol.lower(), bridgeType.lower(), registrationId.lower(), databasePath.lower(), $0) + push_b1b4_PushManager_new(senderId.lower(), serverHost.lower(), httpProtocol.lower(), bridgeType.lower(), registrationId.lower(), databasePath.lower(), $0) }) } deinit { - try! rustCall { ffi_push_9ca4_PushManager_object_free(pointer, $0) } + try! rustCall { ffi_push_b1b4_PushManager_object_free(pointer, $0) } } public func subscribe(channelId: String = "", scope: String = "", appServerSey: String? = nil) throws -> SubscriptionResponse { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_subscribe(self.pointer, channelId.lower(), scope.lower(), appServerSey.lower(), $0) + push_b1b4_PushManager_subscribe(self.pointer, channelId.lower(), scope.lower(), appServerSey.lower(), $0) } return try SubscriptionResponse.lift(_retval) } @@ -871,7 +881,7 @@ public class PushManager: PushManagerProtocol { public func unsubscribe(channelId: String) throws -> Bool { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_unsubscribe(self.pointer, channelId.lower(), $0) + push_b1b4_PushManager_unsubscribe(self.pointer, channelId.lower(), $0) } return try Bool.lift(_retval) } @@ -879,14 +889,14 @@ public class PushManager: PushManagerProtocol { public func unsubscribeAll() throws { try rustCallWithError(PushError.self) { - push_9ca4_PushManager_unsubscribe_all(self.pointer, $0) + push_b1b4_PushManager_unsubscribe_all(self.pointer, $0) } } public func update(registrationToken: String) throws -> Bool { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_update(self.pointer, registrationToken.lower(), $0) + push_b1b4_PushManager_update(self.pointer, registrationToken.lower(), $0) } return try Bool.lift(_retval) } @@ -894,7 +904,7 @@ public class PushManager: PushManagerProtocol { public func verifyConnection() throws -> [PushSubscriptionChanged] { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_verify_connection(self.pointer, $0) + push_b1b4_PushManager_verify_connection(self.pointer, $0) } return try [PushSubscriptionChanged].lift(_retval) } @@ -902,7 +912,7 @@ public class PushManager: PushManagerProtocol { public func decrypt(channelId: String, body: String, encoding: String = "aes128gcm", salt: String = "", dh: String = "") throws -> [Int8] { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_decrypt(self.pointer, channelId.lower(), body.lower(), encoding.lower(), salt.lower(), dh.lower(), $0) + push_b1b4_PushManager_decrypt(self.pointer, channelId.lower(), body.lower(), encoding.lower(), salt.lower(), dh.lower(), $0) } return try [Int8].lift(_retval) } @@ -910,7 +920,7 @@ public class PushManager: PushManagerProtocol { public func dispatchInfoForChid(channelId: String) throws -> DispatchInfo? { let _retval = try rustCallWithError(PushError.self) { - push_9ca4_PushManager_dispatch_info_for_chid(self.pointer, channelId.lower(), $0) + push_b1b4_PushManager_dispatch_info_for_chid(self.pointer, channelId.lower(), $0) } return try DispatchInfo?.lift(_retval) } diff --git a/generated/push/Generated/pushFFI.h b/generated/push/Generated/pushFFI.h index 438635d1..da199a35 100644 --- a/generated/push/Generated/pushFFI.h +++ b/generated/push/Generated/pushFFI.h @@ -44,55 +44,55 @@ typedef struct RustCallStatus { // ⚠️ increment the version suffix in all instances of UNIFFI_SHARED_HEADER_V3 in this file. ⚠️ #endif // def UNIFFI_SHARED_H -void ffi_push_9ca4_PushManager_object_free( +void ffi_push_b1b4_PushManager_object_free( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -void*_Nonnull push_9ca4_PushManager_new( +void*_Nonnull push_b1b4_PushManager_new( RustBuffer sender_id,RustBuffer server_host,RustBuffer http_protocol,RustBuffer bridge_type,RustBuffer registration_id,RustBuffer database_path, RustCallStatus *_Nonnull out_status ); -RustBuffer push_9ca4_PushManager_subscribe( +RustBuffer push_b1b4_PushManager_subscribe( void*_Nonnull ptr,RustBuffer channel_id,RustBuffer scope,RustBuffer app_server_sey, RustCallStatus *_Nonnull out_status ); -int8_t push_9ca4_PushManager_unsubscribe( +int8_t push_b1b4_PushManager_unsubscribe( void*_Nonnull ptr,RustBuffer channel_id, RustCallStatus *_Nonnull out_status ); -void push_9ca4_PushManager_unsubscribe_all( +void push_b1b4_PushManager_unsubscribe_all( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -int8_t push_9ca4_PushManager_update( +int8_t push_b1b4_PushManager_update( void*_Nonnull ptr,RustBuffer registration_token, RustCallStatus *_Nonnull out_status ); -RustBuffer push_9ca4_PushManager_verify_connection( +RustBuffer push_b1b4_PushManager_verify_connection( void*_Nonnull ptr, RustCallStatus *_Nonnull out_status ); -RustBuffer push_9ca4_PushManager_decrypt( +RustBuffer push_b1b4_PushManager_decrypt( void*_Nonnull ptr,RustBuffer channel_id,RustBuffer body,RustBuffer encoding,RustBuffer salt,RustBuffer dh, RustCallStatus *_Nonnull out_status ); -RustBuffer push_9ca4_PushManager_dispatch_info_for_chid( +RustBuffer push_b1b4_PushManager_dispatch_info_for_chid( void*_Nonnull ptr,RustBuffer channel_id, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_9ca4_rustbuffer_alloc( +RustBuffer ffi_push_b1b4_rustbuffer_alloc( int32_t size, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_9ca4_rustbuffer_from_bytes( +RustBuffer ffi_push_b1b4_rustbuffer_from_bytes( ForeignBytes bytes, RustCallStatus *_Nonnull out_status ); -void ffi_push_9ca4_rustbuffer_free( +void ffi_push_b1b4_rustbuffer_free( RustBuffer buf, RustCallStatus *_Nonnull out_status ); -RustBuffer ffi_push_9ca4_rustbuffer_reserve( +RustBuffer ffi_push_b1b4_rustbuffer_reserve( RustBuffer buf,int32_t additional, RustCallStatus *_Nonnull out_status ); diff --git a/generated/sync15/SyncUnlockInfo.swift b/generated/sync15/SyncUnlockInfo.swift index ca479ceb..26f86a0a 100644 --- a/generated/sync15/SyncUnlockInfo.swift +++ b/generated/sync15/SyncUnlockInfo.swift @@ -11,11 +11,13 @@ open class SyncUnlockInfo { public var fxaAccessToken: String public var syncKey: String public var tokenserverURL: String + public var loginEncryptionKey: String - public init(kid: String, fxaAccessToken: String, syncKey: String, tokenserverURL: String) { + public init(kid: String, fxaAccessToken: String, syncKey: String, tokenserverURL: String, loginEncryptionKey: String) { self.kid = kid self.fxaAccessToken = fxaAccessToken self.syncKey = syncKey self.tokenserverURL = tokenserverURL + self.loginEncryptionKey = loginEncryptionKey } }