<s> from __future__ import unicode_literals , division , absolute_import , print_function <EOL> import sys <EOL> import ctypes <EOL> from ctypes import windll , wintypes , POINTER , c_void_p , c_uint , Structure <EOL> from ctypes . wintypes import DWORD , ULONG <EOL> from . . _ffi import FFIEngineError , LibraryNotFoundError <EOL> from . . _types import str_cls <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> try : <EOL> secur32 = windll . secur32 <EOL> except ( OSError ) as e : <EOL> if str_cls ( e ) . find ( '<STR_LIT>' ) != - <NUM_LIT:1> : <EOL> raise LibraryNotFoundError ( '<STR_LIT>' ) <EOL> raise <EOL> HCERTSTORE = wintypes . HANDLE <EOL> ALG_ID = c_uint <EOL> if sys . maxsize > <NUM_LIT:2> ** <NUM_LIT:32> : <EOL> ULONG_PTR = ctypes . c_uint64 <EOL> else : <EOL> ULONG_PTR = ctypes . c_ulong <EOL> SEC_GET_KEY_FN = c_void_p <EOL> LUID = c_void_p <EOL> SECURITY_STATUS = ctypes . c_ulong <EOL> SEC_WCHAR = wintypes . WCHAR <EOL> try : <EOL> class SecHandle ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ULONG_PTR ) , <EOL> ( '<STR_LIT>' , ULONG_PTR ) , <EOL> ] <EOL> CredHandle = SecHandle <EOL> CtxtHandle = SecHandle <EOL> class SCHANNEL_CRED ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , c_void_p ) , <EOL> ( '<STR_LIT>' , HCERTSTORE ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , POINTER ( c_void_p ) ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , POINTER ( ALG_ID ) ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ] <EOL> class TimeStamp ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ] <EOL> class SecBuffer ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , POINTER ( ctypes . c_byte ) ) , <EOL> ] <EOL> PSecBuffer = POINTER ( SecBuffer ) <EOL> class SecBufferDesc ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , PSecBuffer ) , <EOL> ] <EOL> class SecPkgContext_StreamSizes ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ( '<STR_LIT>' , ULONG ) , <EOL> ] <EOL> class SecPkgContext_ConnectionInfo ( Structure ) : <EOL> _fields_ = [ <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , ALG_ID ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , ALG_ID ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ( '<STR_LIT>' , ALG_ID ) , <EOL> ( '<STR_LIT>' , DWORD ) , <EOL> ] <EOL> secur32 . AcquireCredentialsHandleW . argtypes = [ <EOL> POINTER ( SEC_WCHAR ) , <EOL> POINTER ( SEC_WCHAR ) , <EOL> ULONG , <EOL> POINTER ( LUID ) , <EOL> c_void_p , <EOL> SEC_GET_KEY_FN , <EOL> c_void_p , <EOL> POINTER ( CredHandle ) , <EOL> POINTER ( TimeStamp ) <EOL> ] <EOL> secur32 . AcquireCredentialsHandleW . restype = SECURITY_STATUS <EOL> secur32 . FreeCredentialsHandle . argtypes = [ <EOL> POINTER ( CredHandle ) <EOL> ] <EOL> secur32 . FreeCredentialsHandle . restype = SECURITY_STATUS <EOL> secur32 . InitializeSecurityContextW . argtypes = [ <EOL> POINTER ( CredHandle ) , <EOL> POINTER ( CtxtHandle ) , <EOL> POINTER ( SEC_WCHAR ) , <EOL> ULONG , <EOL> ULONG , <EOL> ULONG , <EOL> POINTER ( SecBufferDesc ) , <EOL> ULONG , <EOL> POINTER ( CtxtHandle ) , <EOL> POINTER ( SecBufferDesc ) , <EOL> POINTER ( ULONG ) , <EOL> POINTER ( TimeStamp ) <EOL> ] <EOL> secur32 . InitializeSecurityContextW . restype = SECURITY_STATUS <EOL> secur32 . FreeContextBuffer . argtypes = [ <EOL> c_void_p <EOL> ] <EOL> secur32 . FreeContextBuffer . restype = SECURITY_STATUS <EOL> secur32 . ApplyControlToken . argtypes = [ <EOL> POINTER ( CtxtHandle ) , <EOL> POINTER ( SecBufferDesc ) <EOL> ] <EOL> secur32 . ApplyControlToken . restype = SECURITY_STATUS <EOL> secur32 . DeleteSecurityContext . argtypes = [ <EOL> POINTER ( CtxtHandle ) <EOL> ] <EOL> secur32 . DeleteSecurityContext . restype = SECURITY_STATUS <EOL> secur32 . QueryContextAttributesW . argtypes = [ <EOL> POINTER ( CtxtHandle ) , <EOL> ULONG , <EOL> c_void_p <EOL> ] <EOL> secur32 . QueryContextAttributesW . restype = SECURITY_STATUS <EOL> secur32 . EncryptMessage . argtypes = [ <EOL> POINTER ( CtxtHandle ) , <EOL> ULONG , <EOL> POINTER ( SecBufferDesc ) , <EOL> ULONG <EOL> ] <EOL> secur32 . EncryptMessage . restype = SECURITY_STATUS <EOL> secur32 . DecryptMessage . argtypes = [ <EOL> POINTER ( CtxtHandle ) , <EOL> POINTER ( SecBufferDesc ) , <EOL> ULONG , <EOL> POINTER ( ULONG ) <EOL> ] <EOL> secur32 . DecryptMessage . restype = SECURITY_STATUS <EOL> except ( AttributeError ) : <EOL> raise FFIEngineError ( '<STR_LIT>' ) <EOL> setattr ( secur32 , '<STR_LIT>' , ALG_ID ) <EOL> setattr ( secur32 , '<STR_LIT>' , CredHandle ) <EOL> setattr ( secur32 , '<STR_LIT>' , CtxtHandle ) <EOL> setattr ( secur32 , '<STR_LIT>' , SecBuffer ) <EOL> setattr ( secur32 , '<STR_LIT>' , SecBufferDesc ) <EOL> setattr ( secur32 , '<STR_LIT>' , SecPkgContext_StreamSizes ) <EOL> setattr ( secur32 , '<STR_LIT>' , SecPkgContext_ConnectionInfo ) <EOL> setattr ( secur32 , '<STR_LIT>' , SCHANNEL_CRED ) <EOL> def get_error ( ) : <EOL> error = ctypes . GetLastError ( ) <EOL> return ( error , ctypes . FormatError ( error ) ) </s>
