|
| 1 | +/* |
| 2 | + * Copyright 2025 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 | + |
| 17 | +#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDTokenClaim.h" |
| 18 | + |
| 19 | +// Private interface to declare the internal initializer |
| 20 | +@interface GIDTokenClaim () |
| 21 | + |
| 22 | +- (instancetype)initWithName:(NSString *)name |
| 23 | + essential:(BOOL)essential NS_DESIGNATED_INITIALIZER; |
| 24 | + |
| 25 | +@end |
| 26 | + |
| 27 | +@implementation GIDTokenClaim |
| 28 | + |
| 29 | +// Private designated initializer |
| 30 | +- (instancetype)initWithName:(NSString *)name essential:(BOOL)essential { |
| 31 | + self = [super init]; |
| 32 | + if (self) { |
| 33 | + _name = [name copy]; |
| 34 | + _essential = essential; |
| 35 | + } |
| 36 | + return self; |
| 37 | +} |
| 38 | + |
| 39 | +#pragma mark - Factory Methods |
| 40 | + |
| 41 | ++ (instancetype)authTimeClaim { |
| 42 | + return [[self alloc] initWithName:@"auth_time" essential:NO]; |
| 43 | +} |
| 44 | + |
| 45 | ++ (instancetype)essentialAuthTimeClaim { |
| 46 | + return [[self alloc] initWithName:@"auth_time" essential:YES]; |
| 47 | +} |
| 48 | + |
| 49 | +#pragma mark - NSObject |
| 50 | + |
| 51 | +- (BOOL)isEqual:(id)object { |
| 52 | + // 1. Check if the other object is the same instance in memory. |
| 53 | + if (self == object) { |
| 54 | + return YES; |
| 55 | + } |
| 56 | + |
| 57 | + // 2. Check if the other object is not a GIDTokenClaim instance. |
| 58 | + if (![object isKindOfClass:[GIDTokenClaim class]]) { |
| 59 | + return NO; |
| 60 | + } |
| 61 | + |
| 62 | + // 3. Compare the properties that define equality. |
| 63 | + GIDTokenClaim *other = (GIDTokenClaim *)object; |
| 64 | + return [self.name isEqualToString:other.name] && |
| 65 | + self.isEssential == other.isEssential; |
| 66 | +} |
| 67 | + |
| 68 | +- (NSUInteger)hash { |
| 69 | + // The hash value should be based on the same properties used in isEqual: |
| 70 | + return self.name.hash ^ @(self.isEssential).hash; |
| 71 | +} |
| 72 | + |
| 73 | +@end |
0 commit comments