KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gtk/secrets.cpp
Go to the documentation of this file.
1/*
2* This program source code file is part of KiCad, a free EDA CAD application.
3*
4* Copyright (C) 2023 KiCad Developers, see AUTHORS.txt for contributors.
5*
6* This program is free software: you can redistribute it and/or modify it
7* under the terms of the GNU General Public License as published by the
8* Free Software Foundation, either version 3 of the License, or (at your
9* option) any later version.
10*
11* This program is distributed in the hope that it will be useful, but
12* WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14* General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License along
17* with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include <kiplatform/secrets.h>
21
22#include <libsecret/secret.h>
23
24namespace KIPLATFORM
25{
26 namespace SECRETS
27 {
28 static const SecretSchema schema =
29 {
30 "org.kicad.kicad", SECRET_SCHEMA_NONE,
31 {
32 { "service", SECRET_SCHEMA_ATTRIBUTE_STRING },
33 { "key", SECRET_SCHEMA_ATTRIBUTE_STRING },
34 { nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING }
35 }
36 };
37
38 bool StoreSecret( const wxString& aService, const wxString& aKey, const wxString& aSecret )
39 {
40 GError* error = nullptr;
41 wxString display = aService + ":" + aKey;
42
43 secret_password_store_sync( &schema,
44 SECRET_COLLECTION_DEFAULT,
45 display.mb_str(), // Display name
46 aSecret.mb_str(), // Secret value
47 nullptr,
48 &error,
49 "service", aService.ToStdString().c_str(),
50 "key", aKey.ToStdString().c_str(),
51 nullptr );
52
53 if( error )
54 {
55 g_error_free( error );
56 return false;
57 }
58
59 return true;
60 }
61
62 bool GetSecret( const wxString& aService, const wxString& aKey, wxString& aSecret )
63 {
64 GError* error = nullptr;
65 gchar* secret = secret_password_lookup_sync( &schema,
66 nullptr,
67 &error,
68 "service", aService.ToStdString().c_str(),
69 "key", aKey.ToStdString().c_str(),
70 nullptr );
71
72 if( error )
73 {
74 g_error_free( error );
75 return false;
76 }
77
78 aSecret = secret;
79 g_free( secret );
80
81 return true;
82 }
83 }
84}
bool StoreSecret(const wxString &aService, const wxString &aKey, const wxString &aSecret)
Definition: gtk/secrets.cpp:38
bool GetSecret(const wxString &aService, const wxString &aKey, wxString &aSecret)
Definition: gtk/secrets.cpp:62
static const SecretSchema schema
Definition: gtk/secrets.cpp:28