Fix secrets.cpp on Windows.
This commit is contained in:
parent
8c7fe9b071
commit
28c72f0cf4
|
@ -29,28 +29,29 @@ namespace KIPLATFORM
|
||||||
{
|
{
|
||||||
bool StoreSecret( const wxString& aService, const wxString& aKey, const wxString& aSecret )
|
bool StoreSecret( const wxString& aService, const wxString& aKey, const wxString& aSecret )
|
||||||
{
|
{
|
||||||
wxString display = aService + L":" + aKey;
|
wxString display = aService + wxS( ":" ) + aKey;
|
||||||
|
|
||||||
CREDENTIALW cred = { 0 };
|
CREDENTIALW cred = { 0 };
|
||||||
cred.Type = CRED_TYPE_GENERIC;
|
cred.Type = CRED_TYPE_GENERIC;
|
||||||
cred.TargetName = (LPWSTR)display.wc_str();
|
cred.TargetName = (LPWSTR) display.wc_str();
|
||||||
cred.CredentialBlobSize = (DWORD)aSecret.size();
|
cred.CredentialBlobSize = (DWORD) aSecret.size();
|
||||||
cred.CredentialBlob = (LPBYTE)aSecret.c_str();
|
cred.CredentialBlob = (LPBYTE) aSecret.utf8_str().data();
|
||||||
cred.Persist = CRED_PERSIST_USER;
|
cred.Persist = CRED_PERSIST_ENTERPRISE;
|
||||||
|
|
||||||
return CredWriteW( &cred, 0 );
|
return CredWriteW( &cred, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSecret( const wxString& aService, const wxString& aKey, wxString& aSecret )
|
bool GetSecret( const wxString& aService, const wxString& aKey, wxString& aSecret )
|
||||||
{
|
{
|
||||||
wxString display = aService + ":" + aKey;
|
wxString display = aService + wxS( ":" ) + aKey;
|
||||||
|
|
||||||
CREDENTIALW* cred = nullptr;
|
CREDENTIALW* cred = nullptr;
|
||||||
bool result = CredReadW( display.wc_str(), CRED_TYPE_GENERIC, 0, &cred );
|
bool result = CredReadW( display.wc_str(), CRED_TYPE_GENERIC, 0, &cred );
|
||||||
|
|
||||||
if( result )
|
if( result )
|
||||||
{
|
{
|
||||||
aSecret = wxString( (char*)cred->CredentialBlob, cred->CredentialBlobSize );
|
aSecret = wxString::FromUTF8( (const char*) cred->CredentialBlob,
|
||||||
|
cred->CredentialBlobSize );
|
||||||
CredFree( cred );
|
CredFree( cred );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue