# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/win32ctypes/_common.py
# LPBYTE = POINTER(BYTE)
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/win32ctypes/_util.py
# def function_factory(
#         function,  argument_types=None, return_type=None,
#         error_checking=None):
#     if argument_types is not None:
#         function.argtypes = argument_types
#     function.restype = return_type
#     if error_checking is not None:
#         function.errcheck = error_checking
#     return function
# 
# def check_zero_factory(func_name=None):
#     def check_zero(result, func, arguments, *args):
#         if result == 0:
#             code = GetLastError()
#             description = FormatError(code).strip()
#             if func_name is None:
#                 raise error(code, func.__name__, description)
#             else:
#                 raise error(code, func_name, description)
#         return result
#     return check_zero


import ctypes
from ctypes import POINTER, Structure, c_void_p, c_wchar_p
from ctypes.wintypes import (
    BOOL, DWORD, FILETIME, LPCWSTR)
from ._common import LPBYTE
from ._util import function_factory, check_zero_factory



class CREDENTIAL(Structure):
    _fields_ = [
        ("Flags", DWORD),
        ("Type", DWORD),
        ("TargetName", c_wchar_p),
        ("Comment", c_wchar_p),
        ("LastWritten", FILETIME),
        ("CredentialBlobSize", DWORD),
        ("CredentialBlob", LPBYTE),
        ("Persist", DWORD),
        ("_DO_NOT_USE_AttributeCount", DWORD),
        ("__DO_NOT_USE_Attribute", c_void_p),
        ("TargetAlias", c_wchar_p),
        ("UserName", c_wchar_p)]
PCREDENTIAL = POINTER(CREDENTIAL)

SUPPORTED_CREDKEYS = set((
    'Type', 'TargetName', 'Persist', 'UserName', 'Comment', 'CredentialBlob'))

advapi = ctypes.windll.advapi32

_CredWrite = function_factory(
    advapi.CredWriteW,
    [PCREDENTIAL, DWORD],
    BOOL,
    check_zero_factory("CredWrite"))


# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/win32ctypes/_common.py
# LPBYTE = POINTER(BYTE)
# 
# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/win32ctypes/_util.py
# def function_factory(
#         function,  argument_types=None, return_type=None,
#         error_checking=None):
#     if argument_types is not None:
#         function.argtypes = argument_types
#     function.restype = return_type
#     if error_checking is not None:
#         function.errcheck = error_checking
#     return function
# 
# def check_zero_factory(func_name=None):
#     def check_zero(result, func, arguments, *args):
#         if result == 0:
#             code = GetLastError()
#             description = FormatError(code).strip()
#             if func_name is None:
#                 raise error(code, func.__name__, description)
#             else:
#                 raise error(code, func_name, description)
#         return result
#     return check_zero


# Path: resources/lib/PhoneBooks/pyicloud/vendorlibs/win32ctypes/_win32cred.py
import ctypes
from ctypes import POINTER, Structure, c_void_p, c_wchar_p
from ctypes.wintypes import (
    BOOL, DWORD, FILETIME, LPCWSTR)
from ._common import LPBYTE
from ._util import function_factory, check_zero_factory




class CREDENTIAL(Structure):
    _fields_ = [
        ("Flags", DWORD),
        ("Type", DWORD),
        ("TargetName", c_wchar_p),
        ("Comment", c_wchar_p),
        ("LastWritten", FILETIME),
        ("CredentialBlobSize", DWORD),
        ("CredentialBlob", LPBYTE),
        ("Persist", DWORD),
        ("_DO_NOT_USE_AttributeCount", DWORD),
        ("__DO_NOT_USE_Attribute", c_void_p),
        ("TargetAlias", c_wchar_p),
        ("UserName", c_wchar_p)]
PCREDENTIAL = POINTER(CREDENTIAL)

SUPPORTED_CREDKEYS = set((
    'Type', 'TargetName', 'Persist', 'UserName', 'Comment', 'CredentialBlob'))

advapi = ctypes.windll.advapi32

_CredWrite = function_factory(
    advapi.CredWriteW,
    [PCREDENTIAL, DWORD],
    BOOL,
    check_zero_factory("CredWrite"))


_CredRead = function_factory(