FIRAuthDataResult.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRAdditionalUserInfo.h"
  17. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIROAuthCredential.h"
  18. #import "FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h"
  19. #import "FirebaseAuth/Sources/Auth/FIRAuthDataResult_Internal.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @implementation FIRAuthDataResult
  22. /** @var kAdditionalUserInfoCodingKey
  23. @brief The key used to encode the additionalUserInfo property for NSSecureCoding.
  24. */
  25. static NSString *const kAdditionalUserInfoCodingKey = @"additionalUserInfo";
  26. /** @var kUserCodingKey
  27. @brief The key used to encode the user property for NSSecureCoding.
  28. */
  29. static NSString *const kUserCodingKey = @"user";
  30. /** @var kCredentialCodingKey
  31. @brief The key used to encode the credential for NSSecureCoding.
  32. */
  33. static NSString *const kCredentialCodingKey = @"credential";
  34. - (nullable instancetype)initWithUser:(FIRUser *)user
  35. additionalUserInfo:(nullable FIRAdditionalUserInfo *)additionalUserInfo {
  36. return [self initWithUser:user additionalUserInfo:additionalUserInfo credential:nil];
  37. }
  38. - (nullable instancetype)initWithUser:(FIRUser *)user
  39. additionalUserInfo:(nullable FIRAdditionalUserInfo *)additionalUserInfo
  40. credential:(nullable FIROAuthCredential *)credential {
  41. self = [super init];
  42. if (self) {
  43. _additionalUserInfo = additionalUserInfo;
  44. _user = user;
  45. _credential = credential;
  46. }
  47. return self;
  48. }
  49. #pragma mark - NSSecureCoding
  50. + (BOOL)supportsSecureCoding {
  51. return YES;
  52. }
  53. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  54. FIRUser *user = [aDecoder decodeObjectOfClass:[FIRUser class] forKey:kUserCodingKey];
  55. FIRAdditionalUserInfo *additionalUserInfo =
  56. [aDecoder decodeObjectOfClass:[FIRAdditionalUserInfo class]
  57. forKey:kAdditionalUserInfoCodingKey];
  58. FIROAuthCredential *credential = [aDecoder decodeObjectOfClass:[FIROAuthCredential class]
  59. forKey:kCredentialCodingKey];
  60. return [self initWithUser:user additionalUserInfo:additionalUserInfo credential:credential];
  61. }
  62. - (void)encodeWithCoder:(NSCoder *)aCoder {
  63. [aCoder encodeObject:_user forKey:kUserCodingKey];
  64. [aCoder encodeObject:_additionalUserInfo forKey:kAdditionalUserInfoCodingKey];
  65. [aCoder encodeObject:_credential forKey:kCredentialCodingKey];
  66. }
  67. @end
  68. NS_ASSUME_NONNULL_END