@@ -37,7 +37,7 @@ bool WinCredKeyStore::contains(const QString &key) const
3737 if (error == ERROR_NOT_FOUND)
3838 return false ;
3939 else
40- throw QtDataSync::KeyStoreException (this , formatWinError (error));
40+ throw QtDataSync::KeyStoreException (this , qt_error_string (error));
4141 } else
4242 return true ;
4343}
@@ -56,14 +56,14 @@ void WinCredKeyStore::save(const QString &key, const QByteArray &pKey)
5656 cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
5757
5858 if (!CredWriteW (&cred, 0 ))
59- throw QtDataSync::KeyStoreException (this , formatWinError ( GetLastError () ));
59+ throw QtDataSync::KeyStoreException (this , qt_error_string ( ));
6060}
6161
6262QByteArray WinCredKeyStore::load (const QString &key)
6363{
6464 auto res = tryLoad (key);
6565 if (res.isEmpty ())
66- throw QtDataSync::KeyStoreException (this , formatWinError ( GetLastError () ));
66+ throw QtDataSync::KeyStoreException (this , qt_error_string ( ));
6767 else
6868 return res;
6969}
@@ -72,7 +72,7 @@ void WinCredKeyStore::remove(const QString &key)
7272{
7373 auto fullName = fullKey (key);
7474 if (!CredDeleteW (reinterpret_cast <LPWSTR>(const_cast <ushort*>(fullName.utf16 ())), CRED_TYPE_GENERIC, 0 ))
75- throw QtDataSync::KeyStoreException (this , formatWinError ( GetLastError () ));
75+ throw QtDataSync::KeyStoreException (this , qt_error_string ( ));
7676}
7777
7878QString WinCredKeyStore::fullKey (const QString &key)
@@ -82,24 +82,6 @@ QString WinCredKeyStore::fullKey(const QString &key)
8282 .arg (key);
8383}
8484
85- QString WinCredKeyStore::formatWinError (ulong error)
86- {
87- wchar_t *buffer = nullptr ;
88- auto num = FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
89- NULL ,
90- error,
91- 0 ,
92- reinterpret_cast <LPWSTR>(&buffer),
93- 0 ,
94- NULL );
95- if (buffer) {
96- auto res = QString::fromWCharArray (buffer, num);
97- LocalFree (buffer);
98- return res;
99- } else
100- return {};
101- }
102-
10385QByteArray WinCredKeyStore::tryLoad (const QString &key) const
10486{
10587 PCREDENTIALW pCred = NULL ;
0 commit comments