You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

6 years ago
  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 "FIRAuthAppCredential.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kReceiptKey
  19. @brief The key used to encode the receipt property for NSSecureCoding.
  20. */
  21. static NSString *const kReceiptKey = @"receipt";
  22. /** @var kSecretKey
  23. @brief The key used to encode the secret property for NSSecureCoding.
  24. */
  25. static NSString *const kSecretKey = @"secret";
  26. @implementation FIRAuthAppCredential
  27. - (instancetype)initWithReceipt:(NSString *)receipt secret:(nullable NSString *)secret {
  28. self = [super init];
  29. if (self) {
  30. _receipt = [receipt copy];
  31. _secret = [secret copy];
  32. }
  33. return self;
  34. }
  35. #pragma mark - NSSecureCoding
  36. + (BOOL)supportsSecureCoding {
  37. return YES;
  38. }
  39. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  40. NSString *receipt = [aDecoder decodeObjectOfClass:[NSString class] forKey:kReceiptKey];
  41. if (!receipt) {
  42. return nil;
  43. }
  44. NSString *secret = [aDecoder decodeObjectOfClass:[NSString class] forKey:kSecretKey];
  45. return [self initWithReceipt:receipt secret:secret];
  46. }
  47. - (void)encodeWithCoder:(NSCoder *)aCoder {
  48. [aCoder encodeObject:_receipt forKey:kReceiptKey];
  49. [aCoder encodeObject:_secret forKey:kSecretKey];
  50. }
  51. @end
  52. NS_ASSUME_NONNULL_END