Fixed bug where getting non existing passwords would throw on ARM processors. #1

This commit is contained in:
Joel Arvidsson 2015-05-28 19:10:41 +02:00
parent 30217ff1b5
commit b27fc72c8d
1 changed files with 12 additions and 10 deletions

View File

@ -53,21 +53,23 @@ RCT_EXPORT_METHOD(getInternetCredentialsForServer:(NSString*)server callback:(RC
// Look up server in the keychain // Look up server in the keychain
NSDictionary* found = nil; NSDictionary* found = nil;
CFDictionaryRef foundCF; CFTypeRef foundTypeRef = NULL;
OSStatus osStatus = SecItemCopyMatching((__bridge CFDictionaryRef) dict, (CFTypeRef*)&foundCF); OSStatus osStatus = SecItemCopyMatching((__bridge CFDictionaryRef) dict, (CFTypeRef*)&foundTypeRef);
found = (__bridge NSDictionary*)(foundCF);
if (!found) return callback(@[[NSNull null]]);
// Found
NSString* username = (NSString*) [found objectForKey:(__bridge id)(kSecAttrAccount)];
NSString* password = [[NSString alloc] initWithData:[found objectForKey:(__bridge id)(kSecValueData)] encoding:NSUTF8StringEncoding];
if (osStatus != noErr) { if (osStatus != noErr) {
NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:osStatus userInfo:nil]; NSError *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:osStatus userInfo:nil];
return callback(@[makeError(error)]); return callback(@[makeError(error)]);
} }
found = (__bridge NSDictionary*)(foundTypeRef);
if (!found) {
return callback(@[[NSNull null]]);
}
// Found
NSString* username = (NSString*) [found objectForKey:(__bridge id)(kSecAttrAccount)];
NSString* password = [[NSString alloc] initWithData:[found objectForKey:(__bridge id)(kSecValueData)] encoding:NSUTF8StringEncoding];
callback(@[[NSNull null], username, password]); callback(@[[NSNull null], username, password]);
} }