PhoneMultiFactorInfo.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. #if os(iOS)
  16. /// Extends the MultiFactorInfo class for phone number second factors.
  17. ///
  18. /// The identifier of this second factor is "phone".
  19. ///
  20. /// This class is available on iOS only.
  21. @objc(FIRPhoneMultiFactorInfo) public final class PhoneMultiFactorInfo: MultiFactorInfo,
  22. @unchecked Sendable {
  23. // In order for this class to remain safely Sendable, all of its parameters must be immutable
  24. // Sendable types. If you add a parameter here that is either mutable or not Sendable, please
  25. // update the unchecked Sendable above.
  26. /// The string identifier for using phone as a second factor.
  27. @objc(FIRPhoneMultiFactorID) public static let PhoneMultiFactorID = "phone"
  28. /// The string identifier for using TOTP as a second factor.
  29. @objc(FIRTOTPMultiFactorID) public static let TOTPMultiFactorID = "totp"
  30. /// This is the phone number associated with the current second factor.
  31. @objc final let phoneNumber: String
  32. init(proto: AuthProtoMFAEnrollment) {
  33. guard let phoneInfo = proto.phoneInfo else {
  34. fatalError("Internal Auth Error: Missing phone number in Multi Factor Enrollment")
  35. }
  36. phoneNumber = phoneInfo
  37. super.init(proto: proto, factorID: Self.PhoneMultiFactorID)
  38. }
  39. // MARK: NSSecureCoding
  40. private let kPhoneNumberCodingKey = "phoneNumber"
  41. override public class var supportsSecureCoding: Bool { return true }
  42. public required init?(coder: NSCoder) {
  43. guard let phoneNumber = coder.decodeObject(of: NSString.self,
  44. forKey: kPhoneNumberCodingKey) else {
  45. return nil
  46. }
  47. self.phoneNumber = phoneNumber as String
  48. super.init(coder: coder)
  49. }
  50. override public func encode(with coder: NSCoder) {
  51. super.encode(with: coder)
  52. coder.encode(phoneNumber, forKey: kPhoneNumberCodingKey)
  53. }
  54. }
  55. #endif