Skip to content

Commit

Permalink
Rename singleton constructor; fixes #124
Browse files Browse the repository at this point in the history
  • Loading branch information
nabla-c0d3 committed Jul 13, 2017
1 parent 6c741dc commit a09437d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Alternatively, the pinning policy can be set programmatically:
}
}};

[TrustKit initializeWithConfiguration:trustKitConfig];
[TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
```
The policy can also be set programmatically in Swift Apps:
Expand All @@ -83,7 +83,7 @@ The policy can also be set programmatically in Swift Apps:
"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="
],]]] as [String : Any]
TrustKit.initialize(withConfiguration:trustKitConfig)
TrustKit.initSharedInstance(withConfiguration:trustKitConfig)
```

After TrustKit has been initialized, a
Expand Down
17 changes: 8 additions & 9 deletions TrustKit/TrustKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ NS_ASSUME_NONNULL_BEGIN
configured for the App. In singleton mode, the policy can be set either:
* By adding it to the App's _Info.plist_ under the `TSKConfiguration` key, or
* By programmatically supplying it using the `+initializeWithConfiguration:` method.
* By programmatically supplying it using the `+initSharedInstanceWithConfiguration:` method.
In singleton mode, TrustKit can only be initialized once so only one of the two techniques
should be used.
For more complex Apps where multiple SSL pinning policies need to be used independently
(for example within different frameworks), TrustKit can be used in "multi-instance" mode
by leveraging the `-initWithConfiguration:identifier:` method described at the end of this
page.
by leveraging the `-initWithConfiguration:` method described at the end of this page.
A TrustKit pinning policy is a dictionary which contains some global, App-wide settings
(of type `TSKGlobalConfigurationKey`) as well as domain-specific configuration keys
Expand All @@ -64,8 +63,8 @@ NS_ASSUME_NONNULL_BEGIN
```
When setting the pinning policy programmatically, it has to be supplied to the
`initializeWithConfiguration:` method as a dictionary in order to initialize TrustKit.
For example:
`initSharedInstanceWithConfiguration:` method as a dictionary in order to initialize
TrustKit. For example:
```
NSDictionary *trustKitConfig =
Expand All @@ -91,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN
}
}};
[TrustKit initializeWithConfiguration:trustKitConfig];
[TrustKit initSharedInstanceWithConfiguration:trustKitConfig];
trustKit = [TrustKit sharedInstance];
```
Expand All @@ -109,7 +108,7 @@ NS_ASSUME_NONNULL_BEGIN
"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="
],]]] as [String : Any]
TrustKit.initialize(withConfiguration:trustKitConfig)
TrustKit.initSharedInstance(withConfiguration:trustKitConfig)
```
After initialization, the `TrustKit` instance's `pinningValidator` should be used to implement
Expand All @@ -128,11 +127,11 @@ NS_ASSUME_NONNULL_BEGIN
already been initialized.
*/
+ (void)initializeWithConfiguration:(NSDictionary<TSKGlobalConfigurationKey, id> *)trustKitConfig;
+ (void)initSharedInstanceWithConfiguration:(NSDictionary<TSKGlobalConfigurationKey, id> *)trustKitConfig;


/**
Retrieve the global TrustKit singleton instance. Raises an exception if `+initializeWithConfiguration:`
Retrieve the global TrustKit singleton instance. Raises an exception if `+initSharedInstanceWithConfiguration:`
has not yet been invoked.
@return the shared TrustKit singleton
Expand Down
8 changes: 4 additions & 4 deletions TrustKit/TrustKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ + (instancetype)sharedInstance
if (!sharedTrustKit) {
// TrustKit should only be initialized once so we don't double swizzle or get into anything unexpected
[NSException raise:@"TrustKit was not initialized"
format:@"TrustKit must be initialized using +initializeWithConfiguration: prior to accessing sharedInstance"];
format:@"TrustKit must be initialized using +initSharedInstanceWithConfiguration: prior to accessing sharedInstance"];
}
return sharedTrustKit;
}

+ (void)initializeWithConfiguration:(NSDictionary<TSKGlobalConfigurationKey, id> *)trustKitConfig
+ (void)initSharedInstanceWithConfiguration:(NSDictionary<TSKGlobalConfigurationKey, id> *)trustKitConfig
{
TSKLog(@"Configuration passed via explicit call to initializeWithConfiguration:");
TSKLog(@"Configuration passed via explicit call to initSharedInstanceWithConfiguration:");

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand Down Expand Up @@ -266,6 +266,6 @@ + (void)setLoggerBlock:(void (^)(NSString *))block
if (trustKitConfigFromInfoPlist)
{
TSKLog(@"Configuration supplied via the App's Info.plist");
[TrustKit initializeWithConfiguration:trustKitConfigFromInfoPlist];
[TrustKit initSharedInstanceWithConfiguration:trustKitConfigFromInfoPlist];
}
}
2 changes: 1 addition & 1 deletion TrustKitDemo/TrustKitDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
]
}}};

[TrustKit initializeWithConfiguration:trustKitConfig];
[TrustKit initSharedInstanceWithConfiguration:trustKitConfig];

// Demonstrate how to receive pin validation notifications (only useful for performance/metrics)
[TrustKit sharedInstance].pinningValidatorCallbackQueue =dispatch_get_main_queue();
Expand Down
2 changes: 1 addition & 1 deletion TrustKitDemo/TrustKitDemoInSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
]
]] as [String : Any]

TrustKit.initialize(withConfiguration: trustKitConfig)
TrustKit.initSharedInstance(withConfiguration: trustKitConfig)

return true
}
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ folder on disk.
### Configuring a Pinning Policy

Enabling TrustKit within an App requires generating a pinning policy and then
initializing TrustKit by calling the `initializeWithConfiguration:` method with your
initializing TrustKit by calling the `initSharedInstanceWithConfiguration:` method with your
pinning policy.

A pinning policy is a dictionary of domain names and pinning configuration keys.
Expand Down

0 comments on commit a09437d

Please sign in to comment.