Skip to content

Commit

Permalink
Auto update with latest AS Release v96.1.0 (#84)
Browse files Browse the repository at this point in the history
* Updates Package.swift with v96.1.0 release

* Version 96.1.0

Co-authored-by: Firefox Sync Engineering <[email protected]>
  • Loading branch information
github-actions[bot] and Firefox Sync Engineering authored Nov 29, 2022
1 parent 0fef395 commit 7ca10ec
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 96 deletions.
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.4
import PackageDescription

let checksum = "76f4f0d8952075e4190ea5dafc1fe5afb5ce90038a2221bafd3240e8c5cc6e62"
let version = "v96.0.1"
let checksum = "831c36506905fc20d208e76a922c2f6996f857d3500bcf96f1a526e6cdda4bb6"
let version = "v96.1.0"
let url = "https://github.com/mozilla/application-services/releases/download/\(version)/MozillaRustComponents.xcframework.zip"

// Focus xcframework
let focusChecksum = "5d45ea724fd6df09c035c65fdc59006160dadf045aa68ee9df31ed2bb7403bdd"
let focusChecksum = "e2b39a05e7f04e9c4d65a304e8d09d14520ef5d25780bcc7337d838c89428f19"
let focusUrl = "https://github.com/mozilla/application-services/releases/download/\(version)/FocusRustComponents.xcframework.zip"
let package = Package(
name: "MozillaRustComponentsSwift",
Expand Down
10 changes: 10 additions & 0 deletions swift-source/all/FxAClient/FxAccountManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ open class FxAccountManager {
state == .canAutoretryMigration
}

/// Resets the inner Persisted Account based on the persisted state
/// Callers can use this method to refresh the account manager to reflect
/// the latest persisted state.
/// It's possible for the account manager to go out sync with the persisted state
/// in case an extension (Notification Service for example) modifies the persisted state
public func resetPersistedAccount() {
account = accountStorage.read()
account?.registerPersistCallback(statePersistenceCallback)
}

/// Returns true if the account needs re-authentication.
/// Your app should present the option to start a new OAuth flow.
public func accountNeedsReauth() -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,22 @@ public enum MZKeychainItemAccessibility {
case whenUnlockedThisDeviceOnly

static func accessibilityForAttributeValue(_ keychainAttrValue: CFString) -> MZKeychainItemAccessibility? {
for (key, value) in keychainItemAccessibilityLookup {
if value == keychainAttrValue {
return key
}
}
return nil
keychainItemAccessibilityLookup.first { $0.value == keychainAttrValue }?.key
}
}

private let keychainItemAccessibilityLookup: [MZKeychainItemAccessibility: CFString] = {
var lookup: [MZKeychainItemAccessibility: CFString] = [
[
.afterFirstUnlock: kSecAttrAccessibleAfterFirstUnlock,
.afterFirstUnlockThisDeviceOnly: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
.always: kSecAttrAccessibleAlways,
.whenPasscodeSetThisDeviceOnly: kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
.alwaysThisDeviceOnly: kSecAttrAccessibleAlwaysThisDeviceOnly,
.whenUnlocked: kSecAttrAccessibleWhenUnlocked,
.whenUnlockedThisDeviceOnly: kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
]

return lookup
}()

extension MZKeychainItemAccessibility: MZKeychainAttrRepresentable {
internal var keychainAttrValue: CFString {
return keychainItemAccessibilityLookup[self]!
var keychainAttrValue: CFString {
keychainItemAccessibilityLookup[self]!
}
}
123 changes: 51 additions & 72 deletions swift-source/all/FxAClient/MZKeychain/KeychainWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ open class MZKeychainWrapper {
/// AccessGroup is used for the kSecAttrAccessGroup property to identify which Keychain Access Group this entry belongs to. This allows you to use the KeychainWrapper with shared keychain access between different applications.
public private(set) var accessGroup: String?

private static let defaultServiceName: String = {
Bundle.main.bundleIdentifier ?? "SwiftKeychainWrapper"
}()
private static let defaultServiceName = Bundle.main.bundleIdentifier ?? "SwiftKeychainWrapper"

private convenience init() {
self.init(serviceName: MZKeychainWrapper.defaultServiceName)
Expand All @@ -83,11 +81,7 @@ open class MZKeychainWrapper {
/// - parameter isSynchronizable: A bool that describes if the item should be synchronizable, to be synched with the iCloud. If none is provided, will default to false
/// - returns: True if a value exists for the key. False otherwise.
open func hasValue(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
if let _ = data(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) {
return true
} else {
return false
}
data(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) != nil
}

open func accessibilityOfKey(_ key: String) -> MZKeychainItemAccessibility? {
Expand All @@ -109,7 +103,7 @@ open class MZKeychainWrapper {
return nil
}

return MZKeychainItemAccessibility.accessibilityForAttributeValue(accessibilityAttrValue as CFString)
return .accessibilityForAttributeValue(accessibilityAttrValue as CFString)
}

/// Get the keys of all keychain entries matching the current ServiceName and AccessGroup if one is set.
Expand Down Expand Up @@ -150,35 +144,31 @@ open class MZKeychainWrapper {
// MARK: Public Getters

open func integer(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Int? {
guard let numberValue = object(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) as? NSNumber else {
return nil
}

return numberValue.intValue
return object(forKey: key,
ofClass: NSNumber.self,
withAccessibility: accessibility,
isSynchronizable: isSynchronizable)?.intValue
}

open func float(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Float? {
guard let numberValue = object(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) as? NSNumber else {
return nil
}

return numberValue.floatValue
return object(forKey: key,
ofClass: NSNumber.self,
withAccessibility: accessibility,
isSynchronizable: isSynchronizable)?.floatValue
}

open func double(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Double? {
guard let numberValue = object(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) as? NSNumber else {
return nil
}

return numberValue.doubleValue
return object(forKey: key,
ofClass: NSNumber.self,
withAccessibility: accessibility,
isSynchronizable: isSynchronizable)?.doubleValue
}

open func bool(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool? {
guard let numberValue = object(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) as? NSNumber else {
return nil
}

return numberValue.boolValue
return object(forKey: key,
ofClass: NSNumber.self,
withAccessibility: accessibility,
isSynchronizable: isSynchronizable)?.boolValue
}

/// Returns a string value for a specified key.
Expand All @@ -192,21 +182,26 @@ open class MZKeychainWrapper {
return nil
}

return String(data: keychainData, encoding: String.Encoding.utf8) as String?
return String(data: keychainData, encoding: .utf8)
}

/// Returns an object that conforms to NSCoding for a specified key.
///
/// - parameter forKey: The key to lookup data for.
/// - parameter ofClass: The class type of the decoded object.
/// - parameter withAccessibility: Optional accessibility to use when retrieving the keychain item.
/// - parameter isSynchronizable: A bool that describes if the item should be synchronizable, to be synched with the iCloud. If none is provided, will default to false
/// - returns: The decoded object associated with the key if it exists. If no data exists, or the data found cannot be decoded, returns nil.
open func object(forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> NSCoding? {
open func object<DecodedObjectType>(forKey key: String,
ofClass cls: DecodedObjectType.Type,
withAccessibility accessibility: MZKeychainItemAccessibility? = nil,
isSynchronizable: Bool = false
) -> DecodedObjectType? where DecodedObjectType : NSObject, DecodedObjectType : NSCoding {
guard let keychainData = data(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable) else {
return nil
}

return NSKeyedUnarchiver.unarchiveObject(with: keychainData) as? NSCoding
return try? NSKeyedUnarchiver.unarchivedObject(ofClass: cls, from: keychainData)
}

/// Returns a Data object for a specified key.
Expand Down Expand Up @@ -256,19 +251,19 @@ open class MZKeychainWrapper {
// MARK: Public Setters

@discardableResult open func set(_ value: Int, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
return set(Int(NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
return set(Int(truncating: NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}

@discardableResult open func set(_ value: Float, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
return set(Int(NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
return set(Int(truncating: NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}

@discardableResult open func set(_ value: Double, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
return set(Int(NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
return set(Int(truncating: NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}

@discardableResult open func set(_ value: Bool, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
return set(Int(NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
return set(Int(truncating: NSNumber(value: value)), forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}

/// Save a String value to the keychain associated with a specified key. If a String value already exists for the given key, the string will be overwritten with the new value.
Expand All @@ -279,22 +274,25 @@ open class MZKeychainWrapper {
/// - parameter isSynchronizable: A bool that describes if the item should be synchronizable, to be synched with the iCloud. If none is provided, will default to false
/// - returns: True if the save was successful, false otherwise.
@discardableResult open func set(_ value: String, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
if let data = value.data(using: .utf8) {
return set(data, forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
} else {
return false
}
guard let data = value.data(using: .utf8) else { return false }
return set(data, forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}

/// Save an NSCoding compliant object to the keychain associated with a specified key. If an object already exists for the given key, the object will be overwritten with the new value.
///
/// - parameter value: The NSCoding compliant object to save.
/// - parameter value: The NSSecureCoding compliant object to save.
/// - parameter forKey: The key to save the object under.
/// - parameter withAccessibility: Optional accessibility to use when setting the keychain item.
/// - parameter isSynchronizable: A bool that describes if the item should be synchronizable, to be synched with the iCloud. If none is provided, will default to false
/// - returns: True if the save was successful, false otherwise.
@discardableResult open func set(_ value: NSCoding, forKey key: String, withAccessibility accessibility: MZKeychainItemAccessibility? = nil, isSynchronizable: Bool = false) -> Bool {
let data = NSKeyedArchiver.archivedData(withRootObject: value)
@discardableResult open func set<T>(_ value: T,
forKey key: String,
withAccessibility accessibility: MZKeychainItemAccessibility? = nil,
isSynchronizable: Bool = false
) -> Bool where T : NSSecureCoding {
guard let data = try? NSKeyedArchiver.archivedData(withRootObject: value, requiringSecureCoding: true) else {
return false
}

return set(data, forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)
}
Expand All @@ -318,7 +316,7 @@ open class MZKeychainWrapper {
keychainQueryDictionary[SecAttrAccessible] = MZKeychainItemAccessibility.whenUnlocked.keychainAttrValue
}

let status: OSStatus = SecItemAdd(keychainQueryDictionary as CFDictionary, nil)
let status = SecItemAdd(keychainQueryDictionary as CFDictionary, nil)

if status == errSecSuccess {
return true
Expand All @@ -344,13 +342,8 @@ open class MZKeychainWrapper {
let keychainQueryDictionary: [String: Any] = setupKeychainQueryDictionary(forKey: key, withAccessibility: accessibility, isSynchronizable: isSynchronizable)

// Delete
let status: OSStatus = SecItemDelete(keychainQueryDictionary as CFDictionary)

if status == errSecSuccess {
return true
} else {
return false
}
let status = SecItemDelete(keychainQueryDictionary as CFDictionary)
return status == errSecSuccess
}

/// Remove all keychain data added through KeychainWrapper. This will only delete items matching the currnt ServiceName and AccessGroup if one is set.
Expand All @@ -366,13 +359,8 @@ open class MZKeychainWrapper {
keychainQueryDictionary[SecAttrAccessGroup] = accessGroup
}

let status: OSStatus = SecItemDelete(keychainQueryDictionary as CFDictionary)

if status == errSecSuccess {
return true
} else {
return false
}
let status = SecItemDelete(keychainQueryDictionary as CFDictionary)
return status == errSecSuccess
}
/// Remove all keychain data, including data not added through keychain wrapper.
///
Expand All @@ -393,12 +381,8 @@ open class MZKeychainWrapper {
///
@discardableResult private class func deleteKeychainSecClass(_ secClass: AnyObject) -> Bool {
let query = [SecClass: secClass]
let status: OSStatus = SecItemDelete(query as CFDictionary)
if status == errSecSuccess {
return true
} else {
return false
}
let status = SecItemDelete(query as CFDictionary)
return status == errSecSuccess
}

/// Update existing data associated with a specified key name. The existing data will be overwritten by the new data.
Expand All @@ -411,13 +395,8 @@ open class MZKeychainWrapper {
keychainQueryDictionary[SecAttrAccessible] = accessibility.keychainAttrValue
}
// Update
let status: OSStatus = SecItemUpdate(keychainQueryDictionary as CFDictionary, updateDictionary as CFDictionary)

if status == errSecSuccess {
return true
} else {
return false
}
let status = SecItemUpdate(keychainQueryDictionary as CFDictionary, updateDictionary as CFDictionary)
return status == errSecSuccess
}

/// Setup the keychain query dictionary used to access the keychain on iOS for a specified key name. Takes into account the Service Name and Access Group if one is set.
Expand Down
2 changes: 2 additions & 0 deletions swift-source/all/FxAClient/PersistedFirefoxAccount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Foundation
import MozillaRustComponents
#endif

// swiftlint:disable type_body_length

/// This class inherits from the Rust `FirefoxAccount` and adds:
/// - Automatic state persistence through `PersistCallback`.
/// - Auth error signaling through observer notifications.
Expand Down
2 changes: 1 addition & 1 deletion swift-source/all/Generated/Metrics/Metrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension GleanMetrics {
// Intentionally left private, no external user can instantiate a new global object.
}

public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 11, day: 19, hour: 15, minute: 6, second: 46))
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 11, day: 29, hour: 22, minute: 16, second: 46))
}

enum NimbusEvents {
Expand Down
6 changes: 3 additions & 3 deletions swift-source/all/Nimbus/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension UInt8 {
///
/// - parameters:
/// * args: The array of strings to use.
// If `nil` no output array will be allocated and `nil` will be passed to `body`.
/// If `nil` no output array will be allocated and `nil` will be passed to `body`.
/// * body: The closure that gets an array of C-compatible strings
func withArrayOfCStrings<R>(
_ args: [String]?,
Expand Down Expand Up @@ -81,8 +81,8 @@ func timestampNanos() -> UInt64 {
}

/// Gets a gecko-compatible locale string (e.g. "es-ES")
// If the locale can't be determined on the system, the value is "und",
// to indicate "undetermined".
/// If the locale can't be determined on the system, the value is "und",
/// to indicate "undetermined".
///
/// - returns: a locale string that supports custom injected locale/languages.
func getLocaleTag() -> String {
Expand Down
2 changes: 1 addition & 1 deletion swift-source/focus/Generated/Metrics/Metrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension GleanMetrics {
// Intentionally left private, no external user can instantiate a new global object.
}

public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 11, day: 19, hour: 15, minute: 10, second: 1))
public static let info = BuildInfo(buildDate: DateComponents(calendar: Calendar.current, timeZone: TimeZone(abbreviation: "UTC"), year: 2022, month: 11, day: 29, hour: 22, minute: 20, second: 38))
}

enum NimbusEvents {
Expand Down
6 changes: 3 additions & 3 deletions swift-source/focus/Nimbus/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension UInt8 {
///
/// - parameters:
/// * args: The array of strings to use.
// If `nil` no output array will be allocated and `nil` will be passed to `body`.
/// If `nil` no output array will be allocated and `nil` will be passed to `body`.
/// * body: The closure that gets an array of C-compatible strings
func withArrayOfCStrings<R>(
_ args: [String]?,
Expand Down Expand Up @@ -81,8 +81,8 @@ func timestampNanos() -> UInt64 {
}

/// Gets a gecko-compatible locale string (e.g. "es-ES")
// If the locale can't be determined on the system, the value is "und",
// to indicate "undetermined".
/// If the locale can't be determined on the system, the value is "und",
/// to indicate "undetermined".
///
/// - returns: a locale string that supports custom injected locale/languages.
func getLocaleTag() -> String {
Expand Down

0 comments on commit 7ca10ec

Please sign in to comment.