PhoneMultiFactorInfo.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // TODO(Swift 6 Breaking): Make checked Sendable.
  16. #if os(iOS) || os(macOS)
  17. /// Extends the MultiFactorInfo class for phone number second factors.
  18. ///
  19. /// The identifier of this second factor is "phone".
  20. ///
  21. /// This class is available on iOS and macOS.
  22. @objc(FIRPhoneMultiFactorInfo) open class PhoneMultiFactorInfo: MultiFactorInfo,
  23. @unchecked Sendable {
  24. /// The string identifier for using phone as a second factor.
  25. @objc(FIRPhoneMultiFactorID) public static let PhoneMultiFactorID = "phone"
  26. /// The string identifier for using TOTP as a second factor.
  27. @objc(FIRTOTPMultiFactorID) public static let TOTPMultiFactorID = "totp"
  28. /// This is the phone number associated with the current second factor.
  29. @objc open var phoneNumber: String
  30. init(proto: AuthProtoMFAEnrollment) {
  31. guard let phoneInfo = proto.phoneInfo else {
  32. fatalError("Internal Auth Error: Missing phone number in Multi Factor Enrollment")
  33. }
  34. phoneNumber = phoneInfo
  35. super.init(proto: proto, factorID: Self.PhoneMultiFactorID)
  36. }
  37. // MARK: NSSecureCoding
  38. private let kPhoneNumberCodingKey = "phoneNumber"
  39. override public class var supportsSecureCoding: Bool { return true }
  40. public required init?(coder: NSCoder) {
  41. guard let phoneNumber = coder.decodeObject(of: NSString.self,
  42. forKey: kPhoneNumberCodingKey) else {
  43. return nil
  44. }
  45. self.phoneNumber = phoneNumber as String
  46. super.init(coder: coder)
  47. }
  48. override public func encode(with coder: NSCoder) {
  49. super.encode(with: coder)
  50. coder.encode(phoneNumber, forKey: kPhoneNumberCodingKey)
  51. }
  52. }
  53. #endif