diff options
Diffstat (limited to 'framework/src/keyring.cpp')
-rw-r--r-- | framework/src/keyring.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/framework/src/keyring.cpp b/framework/src/keyring.cpp new file mode 100644 index 00000000..759d0c4c --- /dev/null +++ b/framework/src/keyring.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or modify it | ||
5 | under the terms of the GNU Library General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or (at your | ||
7 | option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, but WITHOUT | ||
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public | ||
12 | License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to the | ||
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
17 | 02110-1301, USA. | ||
18 | */ | ||
19 | #include "keyring.h" | ||
20 | |||
21 | #include <sink/secretstore.h> | ||
22 | #include <QSettings> | ||
23 | |||
24 | using namespace Kube; | ||
25 | |||
26 | Keyring::Keyring(const QByteArray &accountId, QObject *parent) | ||
27 | : QObject(parent), | ||
28 | mAccountIdentifier(accountId) | ||
29 | { | ||
30 | } | ||
31 | |||
32 | void Keyring::storePassword(const QByteArray &resourceId, const QString &password) | ||
33 | { | ||
34 | QSettings settings{mAccountIdentifier + ".keyring", QSettings::IniFormat}; | ||
35 | settings.setValue(resourceId, password); | ||
36 | Sink::SecretStore::instance().insert(resourceId, password); | ||
37 | } | ||
38 | |||
39 | void Keyring::unlock() | ||
40 | { | ||
41 | QSettings settings{mAccountIdentifier + ".keyring", QSettings::IniFormat}; | ||
42 | for (const auto &resourceId : settings.allKeys()) { | ||
43 | Sink::SecretStore::instance().insert(resourceId.toLatin1(), settings.value(resourceId).toString()); | ||
44 | } | ||
45 | } | ||
46 | |||