Secure settings rework
This commit is contained in:
parent
266859af19
commit
789902b79a
10 changed files with 79 additions and 95 deletions
|
@ -35,58 +35,3 @@ void MobileUtils::shareText(const QStringList& filesToSend) {
|
|||
}
|
||||
}
|
||||
|
||||
bool MobileUtils::deleteFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSDictionary *deleteQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemDelete((__bridge CFDictionaryRef)deleteQuery);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error deleteFromKeychain" << status;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void MobileUtils::writeToKeychain(const QString& tag, const QByteArray& value) {
|
||||
deleteFromKeychain(tag);
|
||||
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = value.toNSData();
|
||||
|
||||
NSDictionary* addQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
(id)kSecValueData: nsValue,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addQuery, NULL);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error writeToKeychain" << status;
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray MobileUtils::readFromKeychain(const QString& tag) {
|
||||
NSData* nsTag = [tag.toNSString() dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSData* nsValue = NULL;
|
||||
|
||||
NSDictionary *getQuery = @{ (id)kSecAttrAccount: nsTag,
|
||||
(id)kSecClass: (id)kSecClassGenericPassword,
|
||||
(id)kSecMatchLimit: (id)kSecMatchLimitOne,
|
||||
(id)kSecReturnData: @YES,
|
||||
};
|
||||
|
||||
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)getQuery,
|
||||
(CFTypeRef *)&nsValue);
|
||||
if (status != errSecSuccess) {
|
||||
qDebug() << "Error readFromKeychain" << status;
|
||||
}
|
||||
|
||||
QByteArray result;
|
||||
if (nsValue) {
|
||||
result = QByteArray::fromNSData(nsValue);
|
||||
CFRelease(nsValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue