FIRInstallationsStoredAuthToken.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2019 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 "FIRInstallationsStoredAuthToken.h"
  17. #import "FIRInstallationsLogger.h"
  18. NSString *const kFIRInstallationsStoredAuthTokenStatusKey = @"status";
  19. NSString *const kFIRInstallationsStoredAuthTokenTokenKey = @"token";
  20. NSString *const kFIRInstallationsStoredAuthTokenExpirationDateKey = @"expirationDate";
  21. NSString *const kFIRInstallationsStoredAuthTokenStorageVersionKey = @"storageVersion";
  22. NSInteger const kFIRInstallationsStoredAuthTokenStorageVersion = 1;
  23. @implementation FIRInstallationsStoredAuthToken
  24. - (nonnull id)copyWithZone:(nullable NSZone *)zone {
  25. FIRInstallationsStoredAuthToken *clone = [[FIRInstallationsStoredAuthToken alloc] init];
  26. clone.status = self.status;
  27. clone.token = [self.token copy];
  28. clone.expirationDate = self.expirationDate;
  29. clone.storageVersion = self.storageVersion;
  30. return clone;
  31. }
  32. - (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
  33. [aCoder encodeInteger:self.status forKey:kFIRInstallationsStoredAuthTokenStatusKey];
  34. [aCoder encodeObject:self.token forKey:kFIRInstallationsStoredAuthTokenTokenKey];
  35. [aCoder encodeObject:self.expirationDate
  36. forKey:kFIRInstallationsStoredAuthTokenExpirationDateKey];
  37. [aCoder encodeInteger:kFIRInstallationsStoredAuthTokenStorageVersion
  38. forKey:kFIRInstallationsStoredAuthTokenStorageVersionKey];
  39. }
  40. - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
  41. NSInteger storageVersion =
  42. [aDecoder decodeIntegerForKey:kFIRInstallationsStoredAuthTokenStorageVersionKey];
  43. if (storageVersion > kFIRInstallationsStoredAuthTokenStorageVersion) {
  44. FIRLogWarning(kFIRLoggerInstallations,
  45. kFIRInstallationsMessageCodeAuthTokenCoderVersionMismatch,
  46. @"FIRInstallationsStoredAuthToken was encoded by a newer coder version %ld. "
  47. @"Current coder version is %ld. Some auth token data may be lost.",
  48. (long)storageVersion, (long)kFIRInstallationsStoredAuthTokenStorageVersion);
  49. }
  50. FIRInstallationsStoredAuthToken *object = [[FIRInstallationsStoredAuthToken alloc] init];
  51. object.status = [aDecoder decodeIntegerForKey:kFIRInstallationsStoredAuthTokenStatusKey];
  52. object.token = [aDecoder decodeObjectOfClass:[NSString class]
  53. forKey:kFIRInstallationsStoredAuthTokenTokenKey];
  54. object.expirationDate =
  55. [aDecoder decodeObjectOfClass:[NSDate class]
  56. forKey:kFIRInstallationsStoredAuthTokenExpirationDateKey];
  57. return object;
  58. }
  59. + (BOOL)supportsSecureCoding {
  60. return YES;
  61. }
  62. @end