SecretService 0.13.2d47dfe
SecretService is base back end library for your c++ Qt projects.
keystorage.cpp
Go to the documentation of this file.
1//#
2//# Copyright (C) 2024-2024 QuasarApp.
3//# Distributed under the GPLv3 software license, see the accompanying
4//# Everyone is permitted to copy and distribute verbatim copies
5//# of this license document, but changing it is not allowed.
6//#
7
8#include "keystorage.h"
9#include <QCryptographicHash>
10
11namespace QASecret {
12
13KeyStorage::KeyStorage(const QSharedPointer<DBSecret::IDataBase> &db) {
14 _db = db;
15}
16
17QByteArray KeyStorage::add(const QByteArray &value, const QString &alias) {
18
19 if (auto record = _db->getRecordByAlias(alias, true)) {
20 record->setData(value);
21 if (_db->saveRecord(record)) {
22 return record->getHash();
23 }
24 }
25
26 return {};
27}
28
29void KeyStorage::remove(const QByteArray &key) {
30 _db->removeRecordByKey(key);
31}
32
33void KeyStorage::remove(const QString &alias) {
34 _db->removeRecordByAlias(alias);
35}
36
37QByteArray KeyStorage::get(const QByteArray &key) {
38 if (auto&& result = _db->getRecordByHash(key)) {
39 return result->getData();
40
41 }
42
43 return "";
44}
45
46QByteArray KeyStorage::get(const QString &alias) {
47 if (auto&& result = _db->getRecordByAlias(alias)) {
48 return result->getData();
49
50 }
51
52 return "";
53}
54}
QByteArray get(const QByteArray &key)
get return value by access key.
QByteArray add(const QByteArray &value, const QString &alias={})
add adds to storage new value, and return access key.
void remove(const QByteArray &key)
remove This method remove secret from storage by key.