#ifndef CRYPTO_APPLE_KEYCHAIN_V2_H_
#define CRYPTO_APPLE_KEYCHAIN_V2_H_
#import <CryptoTokenKit/CryptoTokenKit.h>
#import <Foundation/Foundation.h>
#import <Security/Security.h>
#include "base/apple/scoped_cftyperef.h"
#include "base/no_destructor.h"
#include "crypto/crypto_export.h"
#if !BUILDFLAG(IS_IOS_TVOS)
#import <LocalAuthentication/LocalAuthentication.h>
#endif
namespace crypto::apple {
class CRYPTO_EXPORT KeychainV2 {
public:
static KeychainV2& GetInstance();
KeychainV2(const KeychainV2&) = delete;
KeychainV2& operator=(const KeychainV2&) = delete;
virtual NSArray* GetTokenIDs();
virtual base::apple::ScopedCFTypeRef<SecKeyRef> KeyCreateRandomKey(
CFDictionaryRef params,
CFErrorRef* error);
virtual base::apple::ScopedCFTypeRef<CFDataRef> KeyCreateSignature(
SecKeyRef key,
SecKeyAlgorithm algorithm,
CFDataRef data,
CFErrorRef* error);
virtual base::apple::ScopedCFTypeRef<SecKeyRef> KeyCopyPublicKey(
SecKeyRef key);
virtual base::apple::ScopedCFTypeRef<CFDataRef> KeyCopyExternalRepresentation(
SecKeyRef key,
CFErrorRef* error);
virtual base::apple::ScopedCFTypeRef<CFDictionaryRef> KeyCopyAttributes(
SecKeyRef key);
virtual OSStatus ItemAdd(CFDictionaryRef attributes, CFTypeRef* result);
virtual OSStatus ItemCopyMatching(CFDictionaryRef query, CFTypeRef* result);
virtual OSStatus ItemDelete(CFDictionaryRef query);
virtual OSStatus ItemUpdate(CFDictionaryRef query,
CFDictionaryRef keychain_data);
#if !BUILDFLAG(IS_IOS)
virtual base::apple::ScopedCFTypeRef<CFTypeRef> TaskCopyValueForEntitlement(
SecTaskRef task,
CFStringRef entitlement,
CFErrorRef* error);
#endif
#if !BUILDFLAG(IS_IOS_TVOS)
virtual BOOL LAContextCanEvaluatePolicy(LAPolicy policy, NSError** error);
#endif
protected:
KeychainV2();
virtual ~KeychainV2();
protected:
friend class base::NoDestructor<KeychainV2>;
friend class ScopedTouchIdTestEnvironment;
friend class ScopedFakeKeychainV2;
static void SetInstanceOverride(KeychainV2* keychain);
static void ClearInstanceOverride();
};
}
#endif