#if OCTAGON
#import <Foundation/Foundation.h>
#import "keychain/ckks/CKKSItem.h"
#import "keychain/ckks/CKKSKeychainBackedKey.h"
#import "keychain/ckks/CKKSSIV.h"
#import "keychain/ckks/CKKSPeer.h"
#import "keychain/ckks/proto/generated_source/CKKSSerializedKey.h"
NS_ASSUME_NONNULL_BEGIN
@interface CKKSKey : CKKSCKRecordHolder
@property CKKSKeychainBackedKey* keycore;
@property NSString* uuid;
@property NSString* parentKeyUUID;
@property (copy) CKKSKeyClass* keyclass;
@property (copy) CKKSWrappedAESSIVKey* wrappedkey;
@property (nullable, readonly) CKKSAESSIVKey* aessivkey;
@property (copy) CKKSProcessedState* state;
@property bool currentkey;
+ (instancetype _Nullable)loadKeyWithUUID:(NSString*)uuid zoneID:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)randomKeyWrappedByParent:(CKKSKey*)parentKey error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)randomKeyWrappedByParent:(CKKSKey*)parentKey
keyclass:(CKKSKeyClass*)keyclass
error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)randomKeyWrappedBySelf:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
- (BOOL)saveKeyMaterialToKeychain:(NSError* __autoreleasing*)error;
- (BOOL)saveKeyMaterialToKeychain:(bool)stashTLK
error:(NSError* __autoreleasing*)error;
- (BOOL)loadKeyMaterialFromKeychain:(NSError* __autoreleasing*)error;
- (BOOL)deleteKeyMaterialFromKeychain:(NSError* __autoreleasing*)error;
+ (NSString* _Nullable)isItemKeyForKeychainView:(SecDbItemRef)item;
+ (instancetype _Nullable)keyFromKeychain:(NSString*)uuid
parentKeyUUID:(NSString*)parentKeyUUID
keyclass:(CKKSKeyClass*)keyclass
state:(CKKSProcessedState*)state
zoneID:(CKRecordZoneID*)zoneID
encodedCKRecord:(NSData* _Nullable)encodedrecord
currentkey:(NSInteger)currentkey
error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)fromDatabase:(NSString*)uuid zoneID:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)tryFromDatabase:(NSString*)uuid zoneID:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)tryFromDatabaseAnyState:(NSString*)uuid zoneID:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (NSArray<CKKSKey*>* _Nullable)selfWrappedKeys:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (instancetype _Nullable)currentKeyForClass:(CKKSKeyClass*)keyclass zoneID:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (NSArray<CKKSKey*>* _Nullable)currentKeysForClass:(CKKSKeyClass*)keyclass
state:(CKKSProcessedState*)state
zoneID:(CKRecordZoneID*)zoneID
error:(NSError* __autoreleasing*)error;
+ (NSArray<CKKSKey*>*)allKeys:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (NSArray<CKKSKey*>*)remoteKeys:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
+ (NSArray<CKKSKey*>*)localKeys:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
- (bool)saveToDatabaseAsOnlyCurrentKeyForClassAndState:(NSError* __autoreleasing*)error;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initSelfWrappedWithAESKey:(CKKSAESSIVKey*)aeskey
uuid:(NSString*)uuid
keyclass:(CKKSKeyClass*)keyclass
state:(CKKSProcessedState*)state
zoneID:(CKRecordZoneID*)zoneID
encodedCKRecord:(NSData* _Nullable)encodedrecord
currentkey:(NSInteger)currentkey;
- (instancetype)initWrappedBy:(CKKSKey*)wrappingKey
AESKey:(CKKSAESSIVKey*)aeskey
uuid:(NSString*)uuid
keyclass:(CKKSKeyClass*)keyclass
state:(CKKSProcessedState*)state
zoneID:(CKRecordZoneID*)zoneID
encodedCKRecord:(NSData* _Nullable)encodedrecord
currentkey:(NSInteger)currentkey;
- (instancetype)initWithWrappedAESKey:(CKKSWrappedAESSIVKey* _Nullable)wrappedaeskey
uuid:(NSString*)uuid
parentKeyUUID:(NSString*)parentKeyUUID
keyclass:(CKKSKeyClass*)keyclass
state:(CKKSProcessedState*)state
zoneID:(CKRecordZoneID*)zoneID
encodedCKRecord:(NSData* _Nullable)encodedrecord
currentkey:(NSInteger)currentkey;
- (instancetype)initWithKeyCore:(CKKSKeychainBackedKey*)core;
- (bool)wrapsSelf;
- (CKKSKey* _Nullable)topKeyInAnyState:(NSError* __autoreleasing*)error;
- (CKKSAESSIVKey*)ensureKeyLoaded:(NSError* __autoreleasing*)error;
- (CKKSAESSIVKey*)unwrapViaKeyHierarchy:(NSError* __autoreleasing*)error;
- (bool)trySelfWrappedKeyCandidate:(CKKSAESSIVKey*)candidate error:(NSError* __autoreleasing*)error;
- (CKKSWrappedAESSIVKey*)wrapAESKey:(CKKSAESSIVKey*)keyToWrap error:(NSError* __autoreleasing*)error;
- (CKKSAESSIVKey*)unwrapAESKey:(CKKSWrappedAESSIVKey*)keyToUnwrap error:(NSError* __autoreleasing*)error;
- (bool)wrapUnder:(CKKSKey*)wrappingKey error:(NSError* __autoreleasing*)error;
- (NSData* _Nullable)encryptData:(NSData*)plaintext
authenticatedData:(NSDictionary<NSString*, NSData*>* _Nullable)ad
error:(NSError* __autoreleasing*)error;
- (NSData* _Nullable)decryptData:(NSData*)ciphertext
authenticatedData:(NSDictionary<NSString*, NSData*>* _Nullable)ad
error:(NSError* __autoreleasing*)error;
- (NSData* _Nullable)serializeAsProtobuf:(NSError* __autoreleasing*)error;
+ (CKKSKey* _Nullable)loadFromProtobuf:(NSData*)data error:(NSError* __autoreleasing*)error;
+ (NSDictionary<NSString*, NSNumber*>*)countsByClass:(CKRecordZoneID*)zoneID error:(NSError* __autoreleasing*)error;
@end
NS_ASSUME_NONNULL_END
#endif