Nenhuma descrição

FIRGameCenterAuthCredential.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2018 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 "FIRGameCenterAuthCredential.h"
  17. #import "FIRAuthExceptionUtils.h"
  18. #import "FIRAuthCredential_Internal.h"
  19. #import "FIRGameCenterAuthProvider.h"
  20. #import "FIRVerifyAssertionRequest.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. @implementation FIRGameCenterAuthCredential
  23. - (nullable instancetype)initWithProvider:(NSString *)provider {
  24. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  25. @"Please call the designated initializer."];
  26. return nil;
  27. }
  28. - (nullable instancetype)initWithPlayerID:(NSString *)playerID
  29. publicKeyURL:(NSURL *)publicKeyURL
  30. signature:(NSData *)signature
  31. salt:(NSData *)salt
  32. timestamp:(uint64_t)timestamp
  33. displayName:(NSString *)displayName {
  34. self = [super initWithProvider:FIRGameCenterAuthProviderID];
  35. if (self) {
  36. _playerID = [playerID copy];
  37. _publicKeyURL = [publicKeyURL copy];
  38. _signature = [signature copy];
  39. _salt = [salt copy];
  40. _timestamp = timestamp;
  41. _displayName = [displayName copy];
  42. }
  43. return self;
  44. }
  45. - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
  46. [FIRAuthExceptionUtils raiseMethodNotImplementedExceptionWithReason:
  47. @"Attempt to call prepareVerifyAssertionRequest: on a FIRGameCenterAuthCredential."];
  48. }
  49. #pragma mark - NSSecureCoding
  50. + (BOOL)supportsSecureCoding {
  51. return YES;
  52. }
  53. - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
  54. NSString *playerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"playerID"];
  55. NSURL *publicKeyURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"publicKeyURL"];
  56. NSData *signature = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"signature"];
  57. NSData *salt = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"salt"];
  58. NSNumber *timestamp = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:@"timestamp"];
  59. NSString *displayName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"displayName"];
  60. self = [self initWithPlayerID:playerID
  61. publicKeyURL:publicKeyURL
  62. signature:signature
  63. salt:salt
  64. timestamp:timestamp.unsignedLongLongValue
  65. displayName:displayName];
  66. return self;
  67. }
  68. - (void)encodeWithCoder:(NSCoder *)aCoder {
  69. [aCoder encodeObject:self.playerID forKey:@"playerID"];
  70. [aCoder encodeObject:self.publicKeyURL forKey:@"publicKeyURL"];
  71. [aCoder encodeObject:self.signature forKey:@"signature"];
  72. [aCoder encodeObject:self.salt forKey:@"salt"];
  73. [aCoder encodeObject:[NSNumber numberWithUnsignedLongLong:self.timestamp] forKey:@"timestamp"];
  74. [aCoder encodeObject:self.displayName forKey:@"displayName"];
  75. }
  76. @end
  77. NS_ASSUME_NONNULL_END