23template<
class _Traits,
class _Ax>
24static 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)
27 DWORD dwSize = _countof(buf);
30 if (
CredProtectA(fAsSelf,
const_cast<LPSTR
>(pszCredentials), cchCredentials, buf, &dwSize, ProtectionType)) {
32 sProtectedCredentials.assign(buf, dwSize - 1);
34 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
36 std::unique_ptr<char[]> buf(
new char[dwSize]);
37 if (
CredProtectA(fAsSelf,
const_cast<LPSTR
>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
38 sProtectedCredentials.assign(buf.get(), dwSize - 1);
51template<
class _Traits,
class _Ax>
52static 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)
55 DWORD dwSize = _countof(buf);
58 if (
CredProtectW(fAsSelf,
const_cast<LPWSTR
>(pszCredentials), cchCredentials, buf, &dwSize, ProtectionType)) {
60 sProtectedCredentials.assign(buf, dwSize - 1);
62 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
64 std::unique_ptr<wchar_t[]> buf(
new wchar_t[dwSize]);
65 if (
CredProtectW(fAsSelf,
const_cast<LPWSTR
>(pszCredentials), cchCredentials, buf.get(), &dwSize, ProtectionType)) {
66 sProtectedCredentials.assign(buf.get(), dwSize - 1);
75template<
class _Traits,
class _Ax>
76static BOOL
CredUnprotectA(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<char, _Traits, _Ax> &sCredentials)
79 DWORD dwSize = _countof(buf);
82 if (
CredUnprotectA(fAsSelf,
const_cast<LPSTR
>(pszProtectedCredentials), cchCredentials, buf, &dwSize)) {
84 sCredentials.assign(buf, dwSize);
86 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
88 std::unique_ptr<char[]> buf(
new char[dwSize]);
89 if (
CredUnprotectA(fAsSelf,
const_cast<LPSTR
>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
90 sCredentials.assign(buf.get(), dwSize);
103template<
class _Traits,
class _Ax>
104static BOOL
CredUnprotectW(_In_ BOOL fAsSelf, _In_count_(cchCredentials) LPCWSTR pszProtectedCredentials, _In_ DWORD cchCredentials, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sCredentials)
107 DWORD dwSize = _countof(buf);
110 if (
CredUnprotectW(fAsSelf,
const_cast<LPWSTR
>(pszProtectedCredentials), cchCredentials, buf, &dwSize)) {
112 sCredentials.assign(buf, dwSize);
114 }
else if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
116 std::unique_ptr<wchar_t[]> buf(
new wchar_t[dwSize]);
117 if (
CredUnprotectW(fAsSelf,
const_cast<LPWSTR
>(pszProtectedCredentials), cchCredentials, buf.get(), &dwSize)) {
118 sCredentials.assign(buf.get(), dwSize);
188 template<
class _Other>
206#pragma warning(suppress: 4505)
207static BOOL
CredEnumerate(_In_z_ LPCTSTR Filter, _Reserved_ DWORD Flags, _Out_ DWORD *Count, _Inout_ std::unique_ptr<PCREDENTIAL[],
winstd::CredFree_delete<PCREDENTIAL[]> > &cCredentials)
noexcept
209 PCREDENTIAL *pCredentials;
211 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:76
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:207
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:24
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:52
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:104
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition: Common.h:101
CredFree_delete< _Ty > _Myt
This type.
Definition: Cred.h:166
CredFree_delete()
Default construct.
Definition: Cred.h:171
void operator()(_Other *) const
Delete a pointer of another type.
Definition: Cred.h:189
void operator()(_Ty *_Ptr) const noexcept
Delete a pointer.
Definition: Cred.h:178
Deleter for unique_ptr using CredFree.
Definition: Cred.h:137
void operator()(_Ty *_Ptr) const
Delete a pointer.
Definition: Cred.h:155
CredFree_delete()
Default construct.
Definition: Cred.h:143
CredFree_delete< _Ty > _Myt
This type.
Definition: Cred.h:138
CredFree_delete(const CredFree_delete< _Ty2 > &)
Construct from another CredFree_delete.
Definition: Cred.h:148