''' *****************************************************************************
*
* Sentinel LDK Licensing API
*
* Copyright (C) 2024 THALES. All rights reserved.
*
***************************************************************************** '''
  

'''------------------------------------------------------------------------------
basic types (for platform compatibility)
------------------------------------------------------------------------------'''

hasp_u64_t = int;
hasp_s64_t = int;
hasp_u32_t = int;
hasp_s32_t = int;
hasp_u16_t = int;
hasp_s16_t = int;
hasp_u8_t  = int;
hasp_s8_t  = int;

'''-----------------------------------------------------------------------------
hasp_ types
-----------------------------------------------------------------------------'''

hasp_status_t       = hasp_u32_t;  # raw error code
hasp_size_t         = hasp_u32_t;  # length
hasp_handle_t       = hasp_u32_t;  # connection handle
hasp_feature_t      = hasp_u32_t;  # feature id
hasp_fileid_t       = hasp_u32_t;  # memory file id
hasp_time_t         = hasp_u64_t;  # time, seconds since Jan-01-1970 0:00 GMT
hasp_vendor_code_t  = int;         # contains the vendor code

'''-----------------------------------------------------------------------------
FORMAT TEMPLATES
-----------------------------------------------------------------------------'''
# hasp_get_info() / hasp_get_sessioninfo() format to get update info (C2V) 
HASP_UPDATEINFO = '<haspformat format="updateinfo"/>';

HASP_FINGERPRINT_INFO = '<haspformat format="host_fingerprint"/>';

# format to retrieve a small update info (C2V) 
HASP_FASTUPDATEINFO = '<haspformat format="fastupdateinfo"/>';

# hasp_get_info() / hasp_get_sessioninfo() format to get session info 
HASP_SESSIONINFO = '<haspformat format="sessioninfo"/>';

# hasp_get_info() / hasp_get_sessioninfo() format to get key/hardware info 
HASP_KEYINFO = '<haspformat format="keyinfo"/>';

HASP_LM_INFO = """<?xml version="1.0" encoding="UTF-8" ?>
                  <haspformat root="hasp_info">
                    <license_manager>
                      <element name="hostname" />
                      <element name="ip" />
                      <element name="osname" />
                    </license_manager> 
                  </haspformat>""";

HASP_RECIPIENT = """<haspformat root="location">
                   <license_manager>
                     <attribute name="id" />
                     <attribute name="time" />
                     <element name="hostname" />
                     <element name="version" />
                     <element name="host_fingerprint" />
                   </license_manager>
                 </haspformat>""";

# Invalid handle value for hasp_login() and hasp_login_scope() functions 
HASP_INVALID_HANDLE_VALUE = 0;

# Minimum block size for hasp_encrypt() and hasp_decrypt() functions. 
HASP_MIN_BLOCK_SIZE = 16;

# Present in every hardware key. 
HASP_DEFAULT_FID = 0;

'''------------------------------------------------------------------------------
hasp_file_ids - Memory file id constants
------------------------------------------------------------------------------'''

# File ID for Sentinel HASP secure writable memory. 
HASP_FILEID_RW = 0x0000fff4;

# File ID for Sentinel HASP secure read only memory 
HASP_FILEID_RO = 0x0000fff5;


'''------------------------------------------------------------------------------
hasp_error_codes - Error code constants
------------------------------------------------------------------------------'''

HASP_STATUS_OK = 0;               # Request completed successfully
HASP_MEM_RANGE = 1;               # Request exceeds the Sentinel protection key memory file
HASP_INV_PROGNUM_OPT = 2;         # Invalid program number option
HASP_INSUF_MEM = 3;               # The system is out of memory
HASP_TMOF = 4;                    # Application has too many open login sessions
HASP_ACCESS_DENIED = 5;           # Access to Feature, Sentinel protection key, or functionality was denied
HASP_INCOMPAT_FEATURE = 6;        # Legacy decryption function is not compatible with this Feature
HASP_HASP_NOT_FOUND = 7;          # Sentinel protection key was not found
HASP_TOO_SHORT = 8;               # Encrypted/decrypted data length is too short to execute function call
HASP_INV_HND = 9;                 # Invalid login handle passed to a function
HASP_INV_FILEID = 10;             # The specified file ID is not recognized by the API
HASP_OLD_DRIVER = 11;             # Installed driver or daemon is too old. Install a later Run-time Environment
HASP_NO_TIME = 12;                # Real-time clock and V-Clock are not available
HASP_SYS_ERR = 13;                # Generic error from host system call
HASP_NO_DRIVER = 14;              # Hardware key driver was not found
HASP_INV_FORMAT = 15;             # An invalid license update or an invalid format string was passed
HASP_REQ_NOT_SUPP = 16;           # Unable to execute the function in this context; the requested functionality is not supported
HASP_INV_UPDATE_OBJ = 17;         # The binary data passed to the function does not contain a valid update
HASP_KEYID_NOT_FOUND = 18;        # A Sentinel protection key with the requested key ID was not found
HASP_INV_UPDATE_DATA = 19;        # Required XML tags were not found OR contents in binary data are missing or invalid
HASP_INV_UPDATE_NOTSUPP = 20;     # The update request is not supported by the Sentinel protection key
HASP_INV_UPDATE_CNTR = 21;        # An update counter mismatch occurred
HASP_INV_VCODE = 22;              # An invalid vendor code was passed to a function
HASP_ENC_NOT_SUPP = 23;           # The Sentinel protection key does not support the encryption type used. You may have an obsolete key
HASP_INV_TIME = 24;               # The date/time value passed is outside the supported range
HASP_NO_BATTERY_POWER = 25;       # The battery for the HL Time key or HL NetTime key is depleted
HASP_NO_ACK_SPACE = 26;           # Acknowledge data requested by update, but ack_data parameter is NULL
HASP_TS_DETECTED = 27;            # An application is running on a remote desktop (terminal server)
HASP_FEATURE_TYPE_NOT_IMPL = 28;  # The requested Feature type is not implemented
HASP_UNKNOWN_ALG = 29;            # An unrecognized algorithm was used in an H2R/V2C file
HASP_INV_SIG = 30;                # Signature verification operation failed
HASP_FEATURE_NOT_FOUND = 31;      # The requested Feature was not found
HASP_NO_LOG = 32;                 # Access log or trace log is not enabled
HASP_LOCAL_COMM_ERR = 33;         # A communication error occurred between the API and the local Sentinel License Manager
HASP_UNKNOWN_VCODE = 34;          # The vendor code is not recognized by the API library
HASP_INV_SPEC = 35;               # An invalid XML login specification was passed to a function
HASP_INV_SCOPE = 36;              # XML scope is not valid
HASP_TOO_MANY_KEYS = 37;          # The scope matches too many Sentinel protection keys
HASP_TOO_MANY_USERS = 38;         # Too many concurrent user sessions are connected
HASP_BROKEN_SESSION = 39;         # A login session was interrupted due to certain updates
HASP_REMOTE_COMM_ERR = 40;        # A communication error occurred between local and remote Sentinel License Managers
HASP_FEATURE_EXPIRED = 41;        # The Feature has expired
HASP_OLD_LM = 42;                 # The existing version of the Sentinel License Manager does not support the API request
HASP_DEVICE_ERR = 43;             # Input/output error occurred in secure storage area of Sentinel SL key OR a USB error occurred when communicating with a Sentinel HL key
HASP_UPDATE_BLOCKED = 44;         # Update installation is not permitted - the update was already applied
HASP_TIME_ERR = 45;               # System time has been tampered with
HASP_SCHAN_ERR = 46;              # Communication error occurred in a secure channel
HASP_STORAGE_CORRUPT = 47;        # Secure storage area of Sentinel SL protection key is corrupted
HASP_NO_VLIB = 48;                # The customized vendor library (haspvlib_<vendorID>.*) cannot be located
HASP_INV_VLIB = 49;               # The vendor library cannot be loaded
HASP_SCOPE_RESULTS_EMPTY = 50;    # Unable to locate any Features that satisfy the provided scope
HASP_VM_DETECTED = 51;            # The license does not allow running the application on a virtual machine
HASP_HARDWARE_MODIFIED = 52;      # Sentinel SL key is locked to a different machine
HASP_USER_DENIED = 53;            # Login is denied because of user restrictions
HASP_UPDATE_TOO_OLD = 54;         # Attempting to apply a V2C file that was already applied
HASP_UPDATE_TOO_NEW = 55;         # Attempting to apply V2C files for a Sentinel protection key in the wrong sequence
HASP_OLD_VLIB = 56;               # Your vendor library version is not supported by the current version of the Licensing API
HASP_UPLOAD_ERROR = 57;           # An attempt to check in a file (such as V2C or H2R) using Admin Control Center failed due to invalid format
HASP_INV_RECIPIENT = 58;          # Invalid XML "recipient" parameter
HASP_INV_DETACH_ACTION = 59;      # Invalid XML "action" parameter
HASP_TOO_MANY_PRODUCTS = 60;      # The scope specified in hasp_transfer() does not identify a unique Product
HASP_INV_PRODUCT = 61;            # Invalid Product information
HASP_UNKNOWN_RECIPIENT = 62;      # The update can only be applied to the Recipient specified in hasp_transfer() and not to this machine
HASP_INV_DURATION = 63;           # The duration is invalid
HASP_CLONE_DETECTED = 64;         # Cloned Sentinel SL secure storage area was detected
HASP_UPDATE_ALREADY_ADDED = 65;   # The specified V2C or V2CP update was already installed in the License Manager service
HASP_HASP_INACTIVE = 66;          # The specified key ID identifies an inactive key
HASP_NO_DETACHABLE_FEATURE = 67;  # No detachable Feature exists
HASP_NO_DEATCHABLE_FEATURE = 67;  # No detachable Feature exists (typo kept for compatibility)
HASP_TOO_MANY_HOSTS = 68;         # Scope does not identify a unique host
HASP_REHOST_NOT_ALLOWED = 69;     # Rehost action is not allowed for the specified key ID
HASP_LICENSE_REHOSTED = 70;       # The original license has been rehosted to another machine
HASP_REHOST_ALREADY_APPLIED = 71; # An old rehost license cannot be applied; a rehost-counter mismatch occurred
HASP_CANNOT_READ_FILE = 72;       # A V2C or V2CP file was not found or access was denied
HASP_EXTENSION_NOT_ALLOWED = 73;  # The license cannot be extended because the number of detached licenses is greater than the number of concurrent licenses allowed
HASP_DETACH_DISABLED = 74;        # Detach of the license not allowed because the Product contains a VM-disabled Feature and the host machine is a virtual machine
HASP_REHOST_DISABLED = 75;        # You cannot rehost the license to a virtual machine
HASP_DETACHED_LICENSE_FOUND = 76; # The user attempted to format an SL AdminMode key or to migrate an SL Legacy key to an SL AdminMode key. However, a Product is currently detached from the key
HASP_RECIPIENT_OLD_LM = 77;       # The fingerprint of the target machine was collected using tools (RUS utility or Licensing API) earlier than Sentinel LDK 7.0
HASP_SECURE_STORE_ID_MISMATCH=78; # A secure storage ID mismatch occurred
HASP_DUPLICATE_HOSTNAME = 79;     # The license is locked to a specific hostname; however, two or more machines with this hostname were found in the network
HASP_MISSING_LM = 80;             # The Sentinel License Manager is required for this operation
HASP_FEATURE_INSUFFICIENT_EXECUTION_COUNT = 81; # The application tried to consume or reserve multiple executions while logging in to a Feature. However, the license does not contain the number of executions that were requested
HASP_INCOMPATIBLE_PLATFORM = 82;  # Attempting to perform an operation that is not compatible with target platform
HASP_HASP_DISABLED = 83;          # The protection key is disabled due to suspected tampering
HASP_SHARING_VIOLATION = 84;      # The protection key is not accessible due to a USB sharing violation
HASP_KILLED_SESSION = 85;         # The session was interrupted due a network malfunction, or the session was interrupted manually from Admin Control Center
HASP_VS_DETECTED = 86;            # The license does not allow installing the application on a virtual machine
HASP_IDENTITY_REQUIRED = 87;      # A client identity is required to run this application
HASP_IDENTITY_UNAUTHENTICATED = 88; # The client identity is not authenticated
HASP_IDENTITY_DISABLED = 89;      # The client identity is disabled
HASP_IDENTITY_DENIED = 90;        # The client identity does not have the required permissions
HASP_IDENTITY_SHARING_VIOLATION = 91; # Your license is in use on a different machine
HASP_IDENTITY_TOO_MANY_MACHINES = 92; # The maximum number of machines usable by the client identity was reached
HASP_IDENTITY_SERVER_NOT_READY = 93; # The server is not ready to authenticate
HASP_UPDATE_OUT_OF_SYNC = 94;     # Trying to install a V2C file with an update counter that is out of sync with the update counter in the Sentinel protection key
HASP_REMOTE_SHARING_VIOLATION = 95; # There were multiple attempts to access the protection key from a remote machine using a proxy
HASP_CLOUD_SESSION_OCCUPIED_REMOTELY = 96; # A cloud licensing session was released because the client requested the seat from a different location
HASP_CLOUD_MISSING_AUTHORIZATION = 97; # Cloud licensing authorization is required to use this license
HASP_INV_NETWORK_SEATS = 98;      # Invalid seat value in network detach. The seat count cannot be decreased when modifying a detach
HASP_NETWORK_DETACH_DISABLED = 99; # Network detach of seats with concurrency is disabled on a Product with only unlimited-concurrency Features
HASP_CLOUD_NOT_SUPP = 100;        # The required functionality is not supported for cloud licenses
HASP_CLOUD_NOT_TRUSTED = 101;     # Only trusted licenses can be installed in the trusted license storage
HASP_CLOUD_STORAGE_COMM_ERR = 102; # A communication error ocurred with the license storage
HASP_IDENTITY_EXPIRED = 103;      # Your client identity has expired
HASP_INV_OPTION = 104;            # The option value specified for the API function is not valid
HASP_CLOUD_STORAGE_BUSY = 105;    # The license server is overloaded. Retry the operation in a few seconds
HASP_MACHINE_DENIED = 106;        # This machine cannot be used - the fingeprint is invalid or not accessible
HASP_MACHINE_DISABLED = 107;      # The application license is not accessible because this machine is disabled
HASP_IDENTITY_RATE_LIMIT_EXCEEDED = 108; # The rate at which identity requests are received exceeded the contracted limit. Try again later
HASP_FEATURE_START_DATE_NOT_REACHED = 109; # The start date for the Feature has not yet arrived
HASP_IDENTITY_TEMPORARILY_NOT_ACCESSIBLE = 110; # The client identity is temporarily not accessible. Try again in a few seconds
HASP_CONFLICTING_AUTHENTICATION_METHODS = 111; # You cannot use both an identity string and a JWT for the same server address
HASP_ACCESS_TOKEN_IS_INVALID = 112; # The JWT or LM access token is invalid. Restart the operation
HASP_ACCESS_TOKEN_EXPIRED = 113;  # The JWT or LM access token has expired. Restart the operation
HASP_NO_API_DYLIB = 400;          # Unable to locate the dynamic library for this vendor code
HASP_INV_API_DYLIB = 401;         # The dynamic library for this vendor code cannot be loaded, possibly due to corruption
HASP_INCOMPLETE_API_DYLIB = 402;  # The dynamic library for this vendor code is too old and a requested function was not found
HASP_INVALID_OBJECT = 500;        # Object was incorrectly initialized
HASP_INVALID_PARAMETER = 501;     # An invalid function parameter was specified
HASP_ALREADY_LOGGED_IN = 502;     # Attempting to log in twice to the same object
HASP_ALREADY_LOGGED_OUT = 503;    # Attempting to log out twice from the same object
HASP_OPERATION_FAILED = 525;      # Incorrect use of system or platform
HASP_NO_EXTBLOCK = 600;           # An internal error occurred: No classic memory extension block is available
HASP_INV_PORT_TYPE = 650;         # An internal error occurred: Invalid port type
HASP_INV_PORT = 651;              # An internal error occurred: Invalid port value
HASP_NET_DLL_BROKEN = 652;        # The .NET DLL appears to be broken
HASP_NOT_IMPL = 698;              # The requested functionality is not supported
HASP_INT_ERR = 699;               # An internal error ocurred in the API
HASP_FIRST_HELPER = 2001;         # Reserved for Sentinel helper libraries
HASP_FIRST_HASP_ACT = 3001;       # Reserved for Sentinel Activation API
HASP_NEXT_FREE_VALUES = 7001;     #####   #####
