TSKSPKIHashCache.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. TSKSPKIHashCache.h
  3. TrustKit
  4. Copyright 2015 The TrustKit Project Authors
  5. Licensed under the MIT license, see associated LICENSE file for terms.
  6. See AUTHORS file for the list of project authors.
  7. */
  8. #if __has_feature(modules)
  9. @import Foundation;
  10. #else
  11. #import <Foundation/Foundation.h>
  12. #endif
  13. #if __has_feature(modules)
  14. @import Security;
  15. #else
  16. #import <Security/Security.h>
  17. #endif
  18. NS_ASSUME_NONNULL_BEGIN
  19. // The identifier used for the default shared hash cache. Use this identifier
  20. // in the TSKSPKIHashCache constructor to use the shared cache.
  21. static NSString * const kTSKSPKISharedHashCacheIdentifier = @"spki-hash.cache";
  22. // Each key is a raw certificate data (for easy lookup) and each value is the certificate's raw SPKI data
  23. typedef NSMutableDictionary<NSData *, NSData *> SPKICacheDictionnary;
  24. @interface TSKSPKIHashCache : NSObject
  25. - (instancetype)new NS_UNAVAILABLE;
  26. - (instancetype)init NS_UNAVAILABLE;
  27. /**
  28. Create a new cache of SPKI hashes. The identifier is required to ensure that multiple cache
  29. instances do not attempt to use the same file on disk for persistence.
  30. @param uniqueIdentifier A unique identifier that is stable across app launches/instance creation
  31. @return An initialized hash cache.
  32. */
  33. - (instancetype _Nullable)initWithIdentifier:(NSString*)uniqueIdentifier NS_DESIGNATED_INITIALIZER;
  34. /**
  35. Get a pin cache for the provided certificate. The pins
  36. are cached so subsequent calls will be faster than the initial call.
  37. @param certificate The certificate containing the public key that will be hashed
  38. @return The hash of the public key or nil if the hash could not be generated
  39. */
  40. - (NSData * _Nullable)hashSubjectPublicKeyInfoFromCertificate:(SecCertificateRef)certificate;
  41. @end
  42. NS_ASSUME_NONNULL_END