19template<
class _Traits,
class _Ax>
20static BOOL
CredProtectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
23 DWORD dwSize = _countof(buf);
26 if (
CredProtectA(fAsSelf,
const_cast<LPSTR
>(pszCredentials), cchCredentials, buf, &dwSize, ProtectionType)) {
28 sProtectedCredentials.assign(buf, dwSize - 1);
30 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
32 std::unique_ptr<char[]> buf(
new char[dwSize]);
33 if (
CredProtectA(fAsSelf,
const_cast<LPSTR
>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
34 sProtectedCredentials.assign(buf.get(), dwSize - 1);
47template<
class _Traits,
class _Ax>
48static BOOL
CredProtectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sProtectedCredentials, _Out_ CRED_PROTECTION_TYPE *ProtectionType)
51 DWORD dwSize = _countof(buf);
54 if (
CredProtectW(fAsSelf,
const_cast<LPWSTR
>(pszCredentials), cchCredentials, buf, &dwSize, ProtectionType)) {
56 sProtectedCredentials.assign(buf, dwSize - 1);
58 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
60 std::unique_ptr<wchar_t[]> buf(
new wchar_t[dwSize]);
61 if (
CredProtectW(fAsSelf,
const_cast<LPWSTR
>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
62 sProtectedCredentials.assign(buf.get(), dwSize - 1);
71template<
class _Traits,
class _Ax>
72static BOOL
CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sCredentials)
75 DWORD dwSize = _countof(buf);
78 if (
CredUnprotectA(fAsSelf,
const_cast<LPSTR
>(pszProtectedCredentials), cchCredentials, buf, &dwSize)) {
80 sCredentials.assign(buf, dwSize);
82 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
84 std::unique_ptr<char[]> buf(
new char[dwSize]);
85 if (
CredUnprotectA(fAsSelf,
const_cast<LPSTR
>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
86 sCredentials.assign(buf.get(), dwSize);
99template<
class _Traits,
class _Ax>
100static BOOL
CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sCredentials)
103 DWORD dwSize = _countof(buf);
106 if (
CredUnprotectW(fAsSelf,
const_cast<LPWSTR
>(pszProtectedCredentials), cchCredentials, buf, &dwSize)) {
108 sCredentials.assign(buf, dwSize);
110 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
112 std::unique_ptr<wchar_t[]> buf(
new wchar_t[dwSize]);
113 if (
CredUnprotectW(fAsSelf,
const_cast<LPWSTR
>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
114 sCredentials.assign(buf.get(), dwSize);
184 template<
class _Other>
202#pragma warning(suppress: 4505)
203static BOOL
CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[],
winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials)
noexcept
205 PCREDENTIAL *pCredentials;
207 cCredentials.reset(pCredentials);
static BOOL CredUnprotectA(BOOL fAsSelf, LPCSTR pszProtectedCredentials, DWORD cchCredentials, std::basic_string< char, _Traits, _Ax > &sCredentials)
Decrypts credentials that were previously encrypted by using the CredProtect function.
Definition: Cred.h:72
static BOOL CredEnumerate(LPCTSTR Filter, DWORD Flags, DWORD *Count, std::unique_ptr< PCREDENTIAL[], winstd::CredFree_delete< PCREDENTIAL[]> > &cCredentials) noexcept
Enumerates the credentials from the user's credential set. The credential set used is the one associa...
Definition: Cred.h:203
static BOOL CredProtectA(BOOL fAsSelf, LPCSTR pszCredentials, DWORD cchCredentials, std::basic_string< char, _Traits, _Ax > &sProtectedCredentials, CRED_PROTECTION_TYPE *ProtectionType)
Encrypts the specified credentials so that only the current security context can decrypt them.
Definition: Cred.h:20
static BOOL CredProtectW(BOOL fAsSelf, LPCWSTR pszCredentials, DWORD cchCredentials, std::basic_string< wchar_t, _Traits, _Ax > &sProtectedCredentials, CRED_PROTECTION_TYPE *ProtectionType)
Encrypts the specified credentials so that only the current security context can decrypt them.
Definition: Cred.h:48
static BOOL CredUnprotectW(BOOL fAsSelf, LPCWSTR pszProtectedCredentials, DWORD cchCredentials, std::basic_string< wchar_t, _Traits, _Ax > &sCredentials)
Decrypts credentials that were previously encrypted by using the CredProtect function.
Definition: Cred.h:100
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition: Common.h:93
CredFree_delete< _Ty > _Myt
This type.
Definition: Cred.h:162
CredFree_delete()
Default construct.
Definition: Cred.h:167
void operator()(_Other *) const
Delete a pointer of another type.
Definition: Cred.h:185
void operator()(_Ty *_Ptr) const noexcept
Delete a pointer.
Definition: Cred.h:174
Deleter for unique_ptr using CredFree.
Definition: Cred.h:133
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition: Cred.h:151
CredFree_delete()
Default construct.
Definition: Cred.h:139
CredFree_delete< _Ty > _Myt
This type.
Definition: Cred.h:134
CredFree_delete(const CredFree_delete< _Ty2 > &)
Construct from another CredFree_delete.
Definition: Cred.h:144