30 bool StoreSecret(
const wxString& aService,
const wxString& aKey,
const wxString& aSecret )
32 wxString display = aService + wxS(
":" ) + aKey;
35 wxScopedCharBuffer utf8Secret = aSecret.utf8_str();
37 CREDENTIALW cred = { 0 };
38 cred.Type = CRED_TYPE_GENERIC;
39 cred.TargetName = (LPWSTR) display.wc_str();
40 cred.CredentialBlobSize = (DWORD) utf8Secret.length();
41 cred.CredentialBlob = (LPBYTE) utf8Secret.data();
42 cred.Persist = CRED_PERSIST_ENTERPRISE;
44 return CredWriteW( &cred, 0 );
47 void StoreSecretAsync(
const wxString& aService,
const wxString& aKey,
const wxString& aSecret,
48 std::function<
void(
bool )> aDone )
51 bool stored =
StoreSecret( aService, aKey, aSecret );
57 bool GetSecret(
const wxString& aService,
const wxString& aKey, wxString& aSecret )
59 wxString display = aService + wxS(
":" ) + aKey;
61 CREDENTIALW* cred =
nullptr;
62 bool result = CredReadW( display.wc_str(), CRED_TYPE_GENERIC, 0, &cred );
66 aSecret = wxString::FromUTF8( (
const char*) cred->CredentialBlob,
67 cred->CredentialBlobSize );
74 void GetSecretAsync(
const wxString& aService,
const wxString& aKey,
75 std::function<
void(
bool,
const wxString& )> aDone )
79 bool found =
GetSecret( aService, aKey, secret );
81 aDone( found, secret );
84 bool GetSecretNoPrompt(
const wxString& aService,
const wxString& aKey, wxString& aSecret )
86 return GetSecret( aService, aKey, aSecret );
89 bool DeleteSecret(
const wxString& aService,
const wxString& aKey )
91 wxString display = aService + wxS(
":" ) + aKey;
92 return CredDeleteW( display.wc_str(), CRED_TYPE_GENERIC, 0 );
wxString result
Test unit parsing edge cases and error handling.