2016-05-28 19:13:44 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: secretstore.cpp
|
|
|
|
// Purpose: wxWidgets sample showing the use of wxSecretStore class
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2016-05-27
|
|
|
|
// Copyright: (c) 2016 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "wx/secretstore.h"
|
|
|
|
|
|
|
|
#include "wx/init.h"
|
|
|
|
#include "wx/crt.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
|
|
|
bool Save(wxSecretStore& store, const wxString& service, const wxString& user)
|
|
|
|
{
|
|
|
|
char password[4096];
|
|
|
|
wxPrintf("Enter the password for %s/%s (echoing NOT disabled): ",
|
|
|
|
service, user);
|
|
|
|
|
|
|
|
if ( !wxFgets(password, WXSIZEOF(password), stdin) )
|
|
|
|
{
|
|
|
|
wxFprintf(stderr, "Password not stored.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-04 13:19:15 -04:00
|
|
|
size_t size = wxStrlen(password);
|
|
|
|
if ( size )
|
|
|
|
{
|
|
|
|
// Strip trailing new line.
|
|
|
|
--size;
|
|
|
|
password[size] = 0;
|
|
|
|
}
|
2016-05-28 19:13:44 -04:00
|
|
|
|
|
|
|
wxSecretValue secret(size, password);
|
|
|
|
|
|
|
|
// The password data was copied into wxSecretValue, don't leave it lying
|
|
|
|
// around in the stack unnecessarily.
|
|
|
|
wxSecretValue::Wipe(size, password);
|
|
|
|
|
|
|
|
if ( !store.Save(service, user, secret) )
|
|
|
|
{
|
|
|
|
wxFprintf(stderr,
|
|
|
|
"Failed to save the password for %s/%s.\n",
|
|
|
|
service, user);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPrintf("Password for %s/%s saved.\n",
|
|
|
|
service, user);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
bool Load(wxSecretStore& store, const wxString& service)
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
wxString user;
|
|
|
|
wxSecretValue secret;
|
|
|
|
if ( !store.Load(service, user, secret) )
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
wxFprintf(stderr, "Failed to load the password for %s.\n", service);
|
2016-05-28 19:13:44 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-04 13:19:15 -04:00
|
|
|
// Create a temporary variable just to make it possible to wipe it after
|
|
|
|
// using it.
|
|
|
|
wxString str(secret.GetAsString());
|
2016-05-28 19:13:44 -04:00
|
|
|
|
2016-06-04 13:19:15 -04:00
|
|
|
const size_t size = secret.GetSize();
|
|
|
|
wxPrintf("Password for %s/%s is %zu bytes long: \"%s\"\n",
|
|
|
|
service, user, size, str);
|
2016-05-28 19:13:44 -04:00
|
|
|
|
2016-06-04 13:19:15 -04:00
|
|
|
wxSecretValue::WipeString(str);
|
2016-05-28 19:13:44 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
bool Delete(wxSecretStore& store, const wxString& service)
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( !store.Delete(service) )
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
wxFprintf(stderr, "Password for %s not deleted.\n", service);
|
2016-05-28 19:13:44 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
wxPrintf("Stored password for %s deleted.\n", service);
|
2016-05-28 19:13:44 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool PrintResult(bool ok)
|
|
|
|
{
|
|
|
|
wxPuts(ok ? "ok" : "ERROR");
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
bool SelfTest(wxSecretStore& store, const wxString& service)
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
|
|
|
wxPrintf("Running the tests...\n");
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
const wxString userTest("test");
|
2016-05-28 19:13:44 -04:00
|
|
|
const wxSecretValue secret1(6, "secret");
|
|
|
|
|
|
|
|
wxPrintf("Storing the password:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
bool ok = store.Save(service, userTest, secret1);
|
2016-05-28 19:13:44 -04:00
|
|
|
if ( !PrintResult(ok) )
|
|
|
|
{
|
|
|
|
// The rest of the tests will probably fail too, no need to continue.
|
|
|
|
wxPrintf("Bailing out.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPrintf("Loading the password:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
wxSecretValue secret;
|
|
|
|
wxString user;
|
|
|
|
ok = PrintResult(store.Load(service, user, secret) &&
|
|
|
|
user == userTest &&
|
|
|
|
secret == secret1);
|
2016-05-28 19:13:44 -04:00
|
|
|
|
|
|
|
// Overwriting the password should work.
|
|
|
|
const wxSecretValue secret2(6, "privet");
|
|
|
|
|
|
|
|
wxPrintf("Changing the password:\t");
|
|
|
|
if ( PrintResult(store.Save(service, user, secret2)) )
|
|
|
|
{
|
|
|
|
wxPrintf("Reloading the password:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( !PrintResult(store.Load(service, user, secret) &&
|
|
|
|
secret == secret2) )
|
2016-05-28 19:13:44 -04:00
|
|
|
ok = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = false;
|
|
|
|
|
|
|
|
wxPrintf("Deleting the password:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( !PrintResult(store.Delete(service)) )
|
2016-05-28 19:13:44 -04:00
|
|
|
ok = false;
|
|
|
|
|
|
|
|
// This is supposed to fail now.
|
|
|
|
wxPrintf("Deleting it again:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( !PrintResult(!store.Delete(service)) )
|
2016-05-28 19:13:44 -04:00
|
|
|
ok = false;
|
|
|
|
|
|
|
|
// And loading should fail too.
|
|
|
|
wxPrintf("Loading after deleting:\t");
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( !PrintResult(!store.Load(service, user, secret)) )
|
2016-05-28 19:13:44 -04:00
|
|
|
ok = false;
|
|
|
|
|
|
|
|
if ( ok )
|
|
|
|
wxPrintf("All tests passed!\n");
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
// To complement the standard EXIT_{SUCCESS,FAILURE}.
|
|
|
|
const int EXIT_SYNTAX = 2;
|
|
|
|
|
|
|
|
wxInitializer initializer;
|
|
|
|
if ( !initializer )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to initialize the wxWidgets library, aborting.");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
if ( argc < 2 ||
|
|
|
|
argc != (argv[1] == wxString("save") ? 4 : 3) )
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
|
|
|
wxFprintf(stderr,
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
"Usage: %s save <service> <user>\n"
|
|
|
|
" or %s {load|delete|selftest} <service>\n"
|
2016-05-28 19:13:44 -04:00
|
|
|
"\n"
|
|
|
|
"Sample showing wxSecretStore class functionality.\n"
|
|
|
|
"Specify one of the commands to perform the corresponding\n"
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
"function call. The \"service\" argument is mandatory for\n"
|
|
|
|
"all commands, \"save\" also requires \"user\" and will\n"
|
|
|
|
"prompt for password.\n",
|
|
|
|
argv[0], argv[0]);
|
2016-05-28 19:13:44 -04:00
|
|
|
return EXIT_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSecretStore store = wxSecretStore::GetDefault();
|
2020-02-10 12:23:59 -05:00
|
|
|
wxString errmsg;
|
|
|
|
if ( !store.IsOk(&errmsg) )
|
2016-05-28 19:13:44 -04:00
|
|
|
{
|
2020-02-10 12:23:59 -05:00
|
|
|
wxFprintf(stderr, "Failed to create default secret store (%s)\n",
|
|
|
|
errmsg);
|
2016-05-28 19:13:44 -04:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const wxString operation = argv[1];
|
|
|
|
const wxString service = argv[2];
|
|
|
|
|
|
|
|
bool ok;
|
|
|
|
if ( operation == "save" )
|
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
ok = Save(store, service, argv[3]);
|
2016-05-28 19:13:44 -04:00
|
|
|
}
|
|
|
|
else if ( operation == "load" )
|
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
ok = Load(store, service);
|
2016-05-28 19:13:44 -04:00
|
|
|
}
|
|
|
|
else if ( operation == "delete" )
|
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
ok = Delete(store, service);
|
2016-05-28 19:13:44 -04:00
|
|
|
}
|
|
|
|
else if ( operation == "selftest" )
|
|
|
|
{
|
Change wxSecretStore API to allow retrieving the username
The old API didn't make any sense for the most common case when both the
user name and password need to be stored, as it required providing the
user name as input, which couldn't work (but somehow this went
unnoticed for more than a year...).
Fix this by returning the username, and not only the password, from
Load() instead of taking it as parameter and removing this parameter
from Delete() as well.
Also improve the documentation, notably include a simple example of
using this class.
Notice that this is a backwards-incompatible change, but the old API was
really badly broken and didn't appear in 3.1.0 yet, so the breakage is
both unavoidable and, hopefully, shouldn't affect much code.
Nevertheless, a special wxHAS_SECRETSTORE_LOAD_USERNAME symbol is added
to allow testing for it if necessary.
2017-07-16 17:47:15 -04:00
|
|
|
ok = SelfTest(store, service);
|
2016-05-28 19:13:44 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFprintf(stderr,
|
|
|
|
"Unknown operation \"%s\", expected \"save\", \"load\" or "
|
|
|
|
"\"delete\".\n",
|
|
|
|
operation);
|
|
|
|
return EXIT_SYNTAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|