GIDToken.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 2022 Google LLC
  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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h"
  17. #import "GoogleSignIn/Sources/GIDToken_Private.h"
  18. // Key constants used for encode and decode.
  19. static NSString *const kTokenStringKey = @"tokenString";
  20. static NSString *const kExpirationDateKey = @"expirationDate";
  21. @implementation GIDToken
  22. - (instancetype)initWithTokenString:(NSString *)tokenString
  23. expirationDate:(NSDate *)expirationDate {
  24. self = [super init];
  25. if (self) {
  26. _tokenString = tokenString;
  27. _expirationDate = expirationDate;
  28. }
  29. return self;
  30. }
  31. #pragma mark - NSSecureCoding
  32. + (BOOL)supportsSecureCoding {
  33. return YES;
  34. }
  35. - (nullable instancetype)initWithCoder:(NSCoder *)decoder {
  36. self = [super init];
  37. if (self) {
  38. _tokenString = [decoder decodeObjectOfClass:[NSString class] forKey:kTokenStringKey];
  39. _expirationDate = [decoder decodeObjectOfClass:[NSDate class] forKey:kExpirationDateKey];
  40. }
  41. return self;
  42. }
  43. - (void)encodeWithCoder:(NSCoder *)encoder {
  44. [encoder encodeObject:_tokenString forKey:kTokenStringKey];
  45. [encoder encodeObject:_expirationDate forKey:kExpirationDateKey];
  46. }
  47. @end