Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions MASFoundation/Classes/_private_/services/access/MASAccessService.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ extern NSString * const MASKeychainStorageKeyDeviceVendorId;



/**
Deletes keychain storage item based on storage key

@param storageKey NSString of storage key.
@param error NSError object reference.
*/
- (void)deleteForStorageKey:(NSString *)storageKey error:(NSError **)error;



///--------------------------------------
/// @name Public
///--------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions MASFoundation/Classes/_private_/services/access/MASAccessService.m
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,23 @@ - (SecKeyRef)getAccessValueCryptoKeyWithStorageKey:(NSString *)storageKey
}


- (void)deleteForStorageKey:(NSString *)storageKey error:(NSError **)error
{
NSString *storageType = [self getStorageTypeWithKey:storageKey];
NSString *accessValueAsString = [self convertKeyString:storageKey];
MASIKeyChainStore *destinationStorage = _storages[storageType];

NSError *operationError = nil;

[destinationStorage removeItemForKey:accessValueAsString error:&operationError];

if (operationError && error)
{
*error = operationError;
}
}


#pragma mark - Private

+ (NSString *)padding:(NSString *)encodedString{
Expand Down
10 changes: 10 additions & 0 deletions MASFoundation/Classes/models/MASSharedStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@
*/
+ (BOOL)saveData:(NSData *_Nonnull)data key:(NSString *_Nonnull)key error:(NSError * __nullable __autoreleasing * __nullable)error;



/**
Deletes any data type with the specified key from shared keychain storage.

@param key NSString of the key used to store the data
@param error NSError object reference that would notify if there was any error while deleting the data
*/
+ (void)deleteForKey:(NSString *_Nonnull)key error:(NSError * __nullable __autoreleasing * __nullable)error;

@end
46 changes: 46 additions & 0 deletions MASFoundation/Classes/models/MASSharedStorage.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,50 @@ + (BOOL)saveData:(NSData *)data key:(NSString *)key error:(NSError **)error
return result;
}


+ (void)deleteForKey:(NSString *_Nonnull)key error:(NSError * __nullable __autoreleasing * __nullable)error
{
//
// Check if SDK was initialized
//
if ([MAS MASState] != MASStateDidStart)
{
if (error)
{
*error = [NSError errorMASIsNotStarted];
}

return;
}

//
// Check for data key
//
if (key == nil || [key length] <= 0)
{
if (error)
{
*error = [NSError errorForFoundationCode:MASFoundationErrorCodeSharedStorageNotNilKey errorDomain:MASFoundationErrorDomainLocal];
}

return;
}

NSError *operationError = nil;
[[MASAccessService sharedService] deleteForStorageKey:[NSString stringWithFormat:@"%@.%@", MASSharedStorageCustomPrefix, key] error:&operationError];

//
// If an error occurred while keychain operation, convert it into MASFoundationErrorDomainLocal error object
//
if (operationError)
{
NSError *thisError = [NSError errorWithDomain:MASFoundationErrorDomainLocal code:operationError.code userInfo:@{NSLocalizedDescriptionKey : operationError.localizedDescription}];

if (error)
{
*error = thisError;
}
}
}

@end