1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 18:37:47 +01:00
Telegram/thirdparty/GDFileManager/GDKeychainCredentialManager.m

47 lines
1.2 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
//
// GDKeychainCredentialManager.m
// GDFileManagerExample
//
// Created by Graham Dennis on 11/07/13.
// Copyright (c) 2013 Graham Dennis. All rights reserved.
//
#import "GDKeychainCredentialManager.h"
#import "GDCredentialManager_Private.h"
#import "SSKeychain.h"
static NSString * const GDKeychainCredentialManagerKeychainKey = @"GDKeychainCredentialManagerKeychainKey";
@implementation GDKeychainCredentialManager
- (NSArray *)loadCredentialsForAccount:(NSString *)account
{
SSKeychainQuery *query = [SSKeychainQuery new];
query.account = account;
query.service = GDKeychainCredentialManagerKeychainKey;
NSError *error = nil;
if ([query fetch:&error] && [(id)query.passwordObject isKindOfClass:[NSArray class]]) {
return [(NSArray *)query.passwordObject copy];
}
return [NSArray new];
}
- (void)saveCredentials:(NSArray *)credentials forAccount:(NSString *)account
{
SSKeychainQuery *query = [SSKeychainQuery new];
query.account = account;
query.service = GDKeychainCredentialManagerKeychainKey;
query.passwordObject = credentials;
NSError *error = nil;
if (![query save:&error]) {
NSLog(@"Failed to save to keychain with error: %@", error);
}
}
@end