/*
 *  Copyright (C) 2025 THALES. All rights reserved.
 *  Use is subject to license terms.
 */

package Aladdin;

public class HaspStatus
{
    /**
     * return codes
     */

    /**
     * Request completed successfully
     */
    public static final int HASP_STATUS_OK              = 0;

    /**
     * Request exceeds the Sentinel protection key memory file
     */
    public static final int HASP_MEM_RANGE              = 1;

    /**
     * Invalid program number option
     */
    public static final int HASP_INV_PROGNUM_OPT        = 2;

    /**
     * The system is out of memory
     */
    public static final int HASP_INSUF_MEM              = 3;

    /**
     * Application has too many open login sessions
     */
    public static final int HASP_TMOF                   = 4;

    /**
     * Access to Feature, Sentinel protection key, or functionality was denied
     */
    public static final int HASP_ACCESS_DENIED          = 5;

    /**
     * Legacy decryption function is not compatible with this Feature
     */
    public static final int HASP_INCOMPAT_FEATURE       = 6;

    /**
     * Sentinel protection key was not found
     */
    public static final int HASP_HASP_NOT_FOUND         = 7;

    /**
     * Deprecated - use HASP_HASP_NOT_FOUND
     */
    public static final int HASP_CONTAINER_NOT_FOUND    = 7;

    /**
     * Encrypted/decrypted data length is too short to execute function call
     */
    public static final int HASP_TOO_SHORT              = 8;

    /**
     * Invalid login handle passed to a function
     */
    public static final int HASP_INV_HND                = 9;

    /**
     * The specified file ID is not recognized by the API 
     */
    public static final int HASP_INV_FILEID             = 10;

    /**
     * Installed driver or daemon is too old. Install a later Run-time Environment
     */
    public static final int HASP_OLD_DRIVER             = 11;

    /**
     * Real-time clock and V-Clock are not available
     */
    public static final int HASP_NO_TIME                = 12;

    /**
     * Generic error from host system call
     */
    public static final int HASP_SYS_ERR                = 13;

    /**
     * Hardware key driver was not found 
     */
    public static final int HASP_NO_DRIVER              = 14;

    /**
     * An invalid license update or an invalid format string was passed
     */
    public static final int HASP_INV_FORMAT             = 15;

    /**
     * Unable to execute the function in this context; the requested functionality is not supported
     */
    public static final int HASP_REQ_NOT_SUPP           = 16;

    /**
     * The binary data passed to the function does not contain a valid update 
     */
    public static final int HASP_INV_UPDATE_OBJ         = 17;

    /**
     * A Sentinel protection key with the requested key ID was not found
     */
    public static final int HASP_KEYID_NOT_FOUND        = 18;

    /**
     * Required XML tags were not found OR contents in binary data are missing or invalid
     */
    public static final int HASP_INV_UPDATE_DATA        = 19;

    /**
     * The update request is not supported by the Sentinel protection key
     */
    public static final int HASP_INV_UPDATE_NOTSUPP     = 20;

    /**
     * An update counter mismatch occurred
     */
    public static final int HASP_INV_UPDATE_CNTR        = 21;

    /**
     * An invalid vendor code was passed to a function
     */
    public static final int HASP_INV_VCODE              = 22;

    /**
     * The Sentinel protection key does not support the encryption type used.
     * You may have an obsolete key
     */
    public static final int HASP_ENC_NOT_SUPP           = 23;

    /**
     * The date/time value passed is outside the supported range
     */
    public static final int HASP_INV_TIME               = 24;

    /**
     * The battery for the HL Time key or HL NetTime key is depleted
     */
    public static final int HASP_NO_BATTERY_POWER       = 25;

    /**
     * Acknowledge data requested by update, but ack_data parameter
     * is NULL 
     */
    public static final int HASP_NO_ACK_SPACE           = 26;

    /**
     * An application is running on a remote desktop (terminal server)
     */
    public static final int HASP_TS_DETECTED            = 27;

    /**
     * The requested Feature type is not implemented
     */
    public static final int HASP_FEATURE_TYPE_NOT_IMPL  = 28;

    /**
     * An unrecognized algorithm was used in an H2R/V2C file
     */
    public static final int HASP_UNKNOWN_ALG            = 29;

    /**
     * Signature verification operation failed
     */
    public static final int HASP_INV_SIG                = 30;

    /**
     * The requested Feature was not found
     */
    public static final int HASP_FEATURE_NOT_FOUND      = 31;

    /**
     * Access log or trace log is not enabled
     */
    public static final int HASP_NO_LOG                 = 32;

    /**
     * A communication error occurred between the API and the local Sentinel
     * License Manager
     */
    public static final int HASP_LOCAL_COMM_ERR         = 33;

    /**
     * The vendor code is not recognized by the API library
     */
    public static final int HASP_UNKNOWN_VCODE          = 34;

    /**
     * An invalid XML login specification was passed to a function
     */
    public static final int HASP_INV_SPEC               = 35;

    /**
     * XML scope is not valid
     */
    public static final int HASP_INV_SCOPE              = 36;

    /**
     * The scope matches too many Sentinel protection keys
     */
    public static final int HASP_TOO_MANY_KEYS          = 37;

    /**
     * Too many concurrent user sessions are connected
     */
    public static final int HASP_TOO_MANY_USERS         = 38;

    /**
     * A login session was interrupted due to certain updates
     */
    public static final int HASP_BROKEN_SESSION         = 39;

    /**
     * A communication error occurred between local and remote Sentinel
     * License Managers
     */
    public static final int HASP_REMOTE_COMM_ERR        = 40;

    /**
     * The Feature has expired
     */
    public static final int HASP_FEATURE_EXPIRED        = 41;

    /**
     * The existing version of the Sentinel License Manager does not support
     * the API request
     */
    public static final int HASP_OLD_LM                 = 42;

    /**
     * Input/output error occurred in secure storage area of Sentinel SL key
     * OR a USB error occurred when communicating with a Sentinel HL key
     */
    public static final int HASP_DEVICE_ERR             = 43;

    /**
     * Update installation is not permitted - the update was already applied
     */
    public static final int HASP_UPDATE_BLOCKED         = 44;

    /**
     * System time has been tampered with
     */
    public static final int HASP_TIME_ERR               = 45;

    /**
     * Communication error occurred in a secure channel
     */
    public static final int HASP_SCHAN_ERR              = 46;

    /**
     * Secure storage area of Sentinel SL protection key is corrupted
     */
    public static final int HASP_STORAGE_CORRUPT        = 47;

    /**
     * The customized vendor library (haspvlib_<vendorID>.*) cannot be located
     */
    public static final int HASP_NO_VLIB                = 48;

    /**
     * The vendor library cannot be loaded
     */
    public static final int HASP_INV_VLIB               = 49;

    /**
     * Unable to locate any Features that satisfy the provided scope
     */
    public static final int HASP_SCOPE_RESULTS_EMPTY    = 50;

    /**
     * The license does not allow running the application on a virtual machine
     */
    public static final int HASP_VM_DETECTED            = 51;

    /**
     * Sentinel SL key is locked to a different machine
     */
    public static final int HASP_HARDWARE_MODIFIED      = 52;

    /**
     * Login is denied because of user restrictions
     */
    public static final int HASP_USER_DENIED            = 53;

    /**
     * Attempting to apply a V2C file that was already applied
     */
    public static final int HASP_UPDATE_TOO_OLD         = 54;

    /**
     * Attempting to apply V2C files for a Sentinel protection key in the wrong
     * sequence
     */
    public static final int HASP_UPDATE_TOO_NEW         = 55;

    /**
     * Your vendor library version is not supported by the current version
     * of the Licensing API
     */
    public static final int HASP_OLD_VLIB               = 56;

    /**
     * An attempt to check in a file (such as V2C or H2R) using Admin Control
     * Center failed due to invalid format
     */
    public static final int HASP_UPLOAD_ERROR           = 57;

    /**
     * Invalid XML "recipient" parameter
     */
    public static final int HASP_INV_RECIPIENT          = 58;

    /**
     * Invalid XML "action" parameter
     */
    public static final int HASP_INV_DETACH_ACTION      = 59;

    /**
     * The scope specified in hasp_transfer() does not identify a unique Product
     */
    public static final int HASP_TOO_MANY_PRODUCTS      = 60;

    /**
     * Invalid Product information
     */
    public static final int HASP_INV_PRODUCT            = 61;

    /**
     * The update can only be applied to the Recipient specified in hasp_transfer()
     * and not to this machine
     */
    public static final int HASP_UNKNOWN_RECIPIENT      = 62;

    /**
     * The duration is invalid
     */
    public static final int HASP_INV_DURATION           = 63;

    /**
     * Cloned Sentinel SL secure storage area was detected
     */
    public static final int HASP_CLONE_DETECTED         = 64;

    /**
     * The specified V2C or V2CP update was already installed in the License
     * Manager service
     */
    public static final int HASP_UPDATE_ALREADY_ADDED   = 65;

    /**
     * The specified key ID identifies an inactive key
     */
    public static final int HASP_HASP_INACTIVE          = 66;

    /**
     * No detachable Feature exists
     */
    public static final int HASP_NO_DETACHABLE_FEATURE  = 67;

    /**
     * No detachable Feature exists (typo; kept for compatibility)
     */
    public static final int HASP_NO_DEATCHABLE_FEATURE  = 67;

    /**
     * Scope does not identify a unique host
     */
    public static final int HASP_TOO_MANY_HOSTS         = 68;

    /**
     * Rehost action is not allowed for the specified key ID
     */
    public static final int HASP_REHOST_NOT_ALLOWED     = 69;

    /**
     * The original license has been rehosted to another machine
     */
    public static final int HASP_LICENSE_REHOSTED       = 70;

    /**
     * An old rehost license cannot be applied; a rehost-counter mismatch
     * occurred
     */
    public static final int HASP_REHOST_ALREADY_APPLIED = 71;

    /**
     * A V2C or V2CP file was not found or access was denied
     */
    public static final int HASP_CANNOT_READ_FILE       = 72;

    /**
     * The license cannot be extended because the number of detached licenses
     * is greater than the number of concurrent licenses allowed
     */
    public static final int HASP_EXTENSION_NOT_ALLOWED  = 73;

    /**
     * Detach of the license not allowed because the Product contains a
     * VM-disabled Feature and the host machine is a virtual machine
     */
    public static final int HASP_DETACH_DISABLED        = 74;

    /**
     * You cannot rehost the license to a virtual machine
     */
    public static final int HASP_REHOST_DISABLED        = 75;

    /**
     * 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
     */
    public static final int HASP_DETACHED_LICENSE_FOUND = 76;

    /**
     * The fingerprint of the target machine was collected using tools
     * (RUS utility or Licensing API) earlier than Sentinel LDK 7.0
     */
    public static final int HASP_RECIPIENT_OLD_LM       = 77;

    /**
     * A secure storage ID mismatch occurred
     */
    public static final int HASP_SECURE_STORE_ID_MISMATCH = 78;

    /**
     * The license is locked to a specific hostname; however, two or more
     * machines with this hostname were found in the network
     */
    public static final int HASP_DUPLICATE_HOSTNAME     = 79;

    /**
     * The Sentinel License Manager is required for this operation
     */
    public static final int HASP_MISSING_LM             = 80;

    /**
     * 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
     */
    public static final int HASP_FEATURE_INSUFFICIENT_EXECUTION_COUNT = 81;

    /**
     * Attempting to perform an operation that is not compatible with target
     * platform
     */
    public static final int HASP_INCOMPATIBLE_PLATFORM  = 82;

    /**
     * The protection key is disabled due to suspected tampering
     */
    public static final int HASP_HASP_DISABLED          = 83;

    /**
     * The protection key is not accessible due to a USB sharing violation
     */ 
    public static final int HASP_SHARING_VIOLATION      = 84;

    /**
     * The session was interrupted due a network malfunction, or the session
     * was interrupted manually from Admin Control Center
     */
    public static final int HASP_KILLED_SESSION         = 85;

    /**
     * The license does not allow installing the application on a virtual
     * machine
     */
    public static final int HASP_VS_DETECTED            = 86;

    /**
     * A client identity is required to run this application
     */
    public static final int HASP_IDENTITY_REQUIRED      = 87;

    /**
     * The client identity is not authenticated
     */
    public static final int HASP_IDENTITY_UNAUTHENTICATED = 88;

    /**
     * The client identity is disabled
     */
    public static final int HASP_IDENTITY_DISABLED      = 89;

    /**
     * The client identity does not have the required permissions
     */
    public static final int HASP_IDENTITY_DENIED        = 90;

    /**
     * Your license is in use on a different machine
     */
    public static final int HASP_IDENTITY_SHARING_VIOLATION      = 91;

    /**
     * The maximum number of machines usable by the client identity was reached
     */
    public static final int HASP_IDENTITY_TOO_MANY_MACHINES      = 92;

    /**
     * The server is not ready to authenticate
     */
    public static final int HASP_IDENTITY_SERVER_NOT_READY       = 93;

    /**
     * Trying to install a V2C file with an update counter that is out of sync
     * with the update counter in the Sentinel protection key
     */
    public static final int HASP_UPDATE_OUT_OF_SYNC              = 94;

    /**
     * There were multiple attempts to access the protection key from a remote
     * machine using a proxy
     */
    public static final int HASP_REMOTE_SHARING_VIOLATION        = 95;

    /**
     * A cloud licensing session was released because the client requested the
     * seat from a different location
     */
    public static final int HASP_CLOUD_SESSION_OCCUPIED_REMOTELY = 96;

    /**
     * Cloud licensing authorization is required to use this license
     */
    public static final int HASP_CLOUD_MISSING_AUTHORIZATION     = 97;

    /**
     * Invalid seat value in network detach. The seat count cannot be decreased
     * when modifying a detach
     */
    public static final int HASP_INV_NETWORK_SEATS               = 98;

    /**
     * Network detach of seats with concurrency is disabled on a Product with
     * only unlimited-concurrency Features
     */
    public static final int HASP_NETWORK_DETACH_DISABLED         = 99;

    /**
     * The required functionality is not supported for cloud licenses
     */
    public static final int HASP_CLOUD_NOT_SUPP                  = 100;

    /**
     * Only trusted licenses can be installed in the trusted license storage
     */
    public static final int HASP_CLOUD_NOT_TRUSTED               = 101;

    /**
     * A communication error ocurred with the license storage
     */
    public static final int HASP_CLOUD_STORAGE_COMM_ERR          = 102;

    /**
     * Your client identity has expired
     */
    public static final int HASP_IDENTITY_EXPIRED                = 103;

    /**
     * The option value specified for the API function is not valid
     */
    public static final int HASP_INV_OPTION                      = 104;

    /**
     * The license server is overloaded. Retry the operation in a few seconds
     */
    public static final int HASP_CLOUD_STORAGE_BUSY              = 105;

    /**
     * This machine cannot be used - the fingeprint is invalid or not accessible
     */
    public static final int HASP_MACHINE_DENIED                  = 106;

    /**
     * The application license is not accessible because this machine is disabled
     */
    public static final int HASP_MACHINE_DISABLED                = 107;

    /**
     * The rate at which identity requests are received exceeded the contracted
     * limit. Try again later
     */
    public static final int HASP_IDENTITY_RATE_LIMIT_EXCEEDED    = 108;

    /**
     * The start date for the Feature has not yet arrived
     */
    public static final int HASP_FEATURE_START_DATE_NOT_REACHED  = 109;

    /** 
     * The client identity is temporarily not accessible. Try again in a few
     * seconds 
     */
    public static final int HASP_IDENTITY_TEMPORARILY_NOT_ACCESSIBLE = 110;

    /** 
     * You cannot use both an identity string and a JWT for the same server
     * address 
     */
    public static final int HASP_CONFLICTING_AUTHENTICATION_METHODS = 111;

    /** 
     * The JWT or LM access token is invalid. Restart the operation 
     */
    public static final int HASP_ACCESS_TOKEN_IS_INVALID = 112;

    /** 
     * The JWT or LM access token has expired. Restart the operation
     */
    public static final int HASP_ACCESS_TOKEN_EXPIRED = 113;

    /**
     * Unable to locate the dynamic library for this vendor code
     */
    public static final int HASP_NO_API_DYLIB           = 400;

    /**
     * The dynamic library for this vendor code cannot be loaded, possibly
     * due to corruption
     */
    public static final int HASP_INV_API_DYLIB          = 401;

    /**
     * The dynamic library for this vendor code is too old and a requested
     * function was not found
     */
    public static final int HASP_INCOMPLETE_API_DYLIB   = 402;

    /**
     * Object was incorrectly initialized
     */
    public static final int HASP_INVALID_OBJECT         = 500;

    /**
     * An invalid function parameter was specified
     */
    public static final int HASP_INV_PARAM              = 501;

    /**
     * Attempting to log in twice to the same object
     */
    public static final int HASP_ALREADY_LOGGED_IN      = 502;

    /**
     * Attempting to log out twice from the same object
     */
    public static final int HASP_ALREADY_LOGGED_OUT     = 503;

    /**
     * Incorrect use of system or platform
     */
    public static final int HASP_OPERATION_FAILED       = 525;

    /*
     * An internal error occurred: No classic memory extension block is available
     */
    public static final int HASP_NO_EXTBLOCK            = 600;

    /*
     * An internal error occurred: Invalid port type
     */
    public static final int HASP_INV_PORT_TYPE          = 650;

    /*
     * An internal error occurred: Invalid port value
     */
    public static final int HASP_INV_PORT               = 651;

    /*
     * The .NET DLL appears to be broken
     */
    public static final int HASP_NET_DLL_BROKEN         = 652;

    /**
     * The requested functionality is not supported
     */
    public static final int HASP_NOT_IMPL               = 698;

    /**
     * An internal error ocurred in the API
     */
    public static final int HASP_INT_ERR                = 699;

    /*
     * Reserved for Sentinel helper libraries
     */
    public static final int HASP_FIRST_HELPER           = 2001;

    /*
     * Reserved for Sentinel Activation API
     */
    public static final int HASP_FIRST_HASP_ACT         = 3001;

    public static final int HASP_NEXT_FREE_VALUES       = 7001;

    public static String runtime_library_default     = "HASPJava";
    public static String runtime_library_x64_windows = "HASPJava_x64";
    public static String runtime_library_x64_linux   = "HASPJava_x86_64";
    public static String runtime_library_armhf_linux = "HASPJava_armhf";
    public static String runtime_library_arm64_linux = "HASPJava_arm64";

    public static void Init()
    {
        String operatingSystem = System.getProperty("os.name");
        String architecture = System.getProperty("os.arch");

        try
        {
            if (operatingSystem.indexOf("Windows") != -1)
            {
                if (architecture.equals("x86_64") || architecture.equals("amd64"))
                {
                    System.loadLibrary(runtime_library_x64_windows);
                }
                else
                {
                    System.loadLibrary(runtime_library_default);
                }
            }
            else if (operatingSystem.indexOf("Linux") != -1)
            {
                    if (architecture.equals("x86_64") || architecture.equals("amd64"))
                    {
                        System.loadLibrary(runtime_library_x64_linux);
                    }
                    else if (architecture.equals("arm"))
                    {
                        System.loadLibrary(runtime_library_armhf_linux);
                    }
                    else if (architecture.equals("aarch64"))
                    {
                        System.loadLibrary(runtime_library_arm64_linux);
                    }
                    else
                    {
                        System.loadLibrary(runtime_library_default);
                    }
            }
            else
            {
                System.loadLibrary(runtime_library_default);
            }
        }
        catch (UnsatisfiedLinkError e)
        {
            if (e.getMessage().indexOf("already loaded in another classloader") == -1)
            {
                throw e;
            }
        }
    }
}
