Class JCint


  • public final class JCint
    extends Object
    The JCint class contains common utility functions using ints. Some of the methods may be implemented as native functions for performance reasons. All the methods in JCint class are static methods.

    The methods makeTransientIntArray() and and setInt(), refer to the persistence of array objects. The term persistent means that arrays and their values persist from one CAD session to the next, indefinitely. The makeTransientIntArray() method is used to create transient int arrays. Constants related to transience control are available in the JCSystem class.

    Since:
    2.2.2
    See Also:
    javacard.framework.JCSystem
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int getInt​(byte[] bArray, short bOff)
      Concatenates four bytes in a byte array to form a int value.
      static int makeInt​(byte b1, byte b2, byte b3, byte b4)
      Concatenates the four parameter bytes to form an int value.
      static int makeInt​(short s1, short s2)
      Concatenates the two parameter short values to form an int value.
      static int[] makeIntArrayView​(int[] array, short offset, short length, short attributes, Shareable service)
      Creates an int array which is a view on the specified array parameter.
      static int[] makeTransientIntArray​(short length, byte event)
      Creates a transient int array with the specified array length.
      static short setInt​(byte[] bArray, short bOff, int iValue)
      Deposits the int value as four successive bytes at the specified offset in the byte array.
    • Method Detail

      • makeInt

        public static final int makeInt​(byte b1,
                                        byte b2,
                                        byte b3,
                                        byte b4)
        Concatenates the four parameter bytes to form an int value.
        Parameters:
        b1 - the first byte ( high order byte )
        b2 - the second byte
        b3 - the third byte
        b4 - the fourth byte ( low order byte )
        Returns:
        the int value the concatenated result
      • makeInt

        public static final int makeInt​(short s1,
                                        short s2)
        Concatenates the two parameter short values to form an int value.
        Parameters:
        s1 - the first short value ( high order short value )
        s2 - the second short value ( low order short value )
        Returns:
        the int value the concatenated result
      • getInt

        public static final int getInt​(byte[] bArray,
                                       short bOff)
                                throws NullPointerException,
                                       ArrayIndexOutOfBoundsException
        Concatenates four bytes in a byte array to form a int value.
        Parameters:
        bArray - byte array
        bOff - offset within byte array containing first byte (the high order byte)
        Returns:
        the int value the concatenated result
        Throws:
        NullPointerException - if the bArray parameter is null
        ArrayIndexOutOfBoundsException - if the bOff parameter is negative or if bOff+4 is greater than the length of bArray
      • makeTransientIntArray

        public static int[] makeTransientIntArray​(short length,
                                                  byte event)
                                           throws NegativeArraySizeException,
                                                  SystemException
        Creates a transient int array with the specified array length.
        Parameters:
        length - the length of the int array
        event - the CLEAR_ON... event which causes the array elements to be cleared
        Returns:
        the new transient int array
        Throws:
        NegativeArraySizeException - if the length parameter is negative
        SystemException - with the following reason codes:
        • SystemException.ILLEGAL_VALUE if event is not a valid event code.
        • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available.
        • SystemException.ILLEGAL_TRANSIENT if the current applet context is not the currently selected applet context and CLEAR_ON_DESELECT is specified.
        See Also:
        javacard.framework.JCSystem
      • makeIntArrayView

        public static int[] makeIntArrayView​(int[] array,
                                             short offset,
                                             short length,
                                             short attributes,
                                             Shareable service)
        Creates an int array which is a view on the specified array parameter. The elements of the created array are mapped to the corresponding elements in the parent array. Any change in the parent array will be visible in the view and vice versa.

        The layout attributes (transient, persistent, sensitive) of the created array are identical to the array parameter ones.
        In addition, it is possible to create read-only, write-only or R/W views using combinations (bitwise inclusive OR) of the following access attributes:

        • ATTR_READABLE_VIEW: the elements of the view can be read. If this attribute is not set, any attempt to read elements from the created view will throw a SecurityException
        • ATTR_WRITABLE_VIEW: the elements of the view can be modified and changes are visible in the actual array and any other view on it. If this attribute is not set, any attempt to write elements in the created view will throw a SecurityException

        The attributes requested for the view shall remain consistent with the attributes of the array parameter:

        • Any attempt to create a view with the ATTR_READABLE_VIEW attribute will throw a SecurityException if the array parameter is not readable.
        • Any attempt to create a view with the ATTR_WRITABLE_VIEW attribute will throw a SecurityException if the array parameter is not writable.

        The created view is temporary and any attempt to store the reference into a class or instance field or in array elements will throw a SecurityException

        Example:

         // creates a R/W view of 5 int on array, starting at offset 4
         int[] view = JCint.makeIntArrayView(array, (short) 4, (short) 5,
                 (short) (ATTR_READABLE_VIEW | ATTR_WRITABLE_VIEW), null);
        
         // creates a view in the service context and share it with the service
         int[] view = JCint.makeIntArrayView(array, (short) 4, (short) 5,
                 (short) (ATTR_READABLE_VIEW | ATTR_WRITABLE_VIEW), service);
         service.execute(view);
         

        Parameters:
        array - the array on which to create the view (either an actual array or a view)
        offset - the offset in the array where the view starts
        length - the number of elements in the view
        attributes - the view access attributes (combinations of ATTR_READABLE_VIEW and ATTR_WRITABLE_VIEW attributes)
        service - the shareable object identifying the recipient context of the new view. If null, the view will remain in the current context. If non-null, the method returns an object created in the context of the specified service and should be used as parameter when calling methods of this service. Other operations executed in current context, including casting, will throw a SecurityException.
        Returns:
        a view on the specified array parameter
        Throws:
        NullPointerException - if the array parameter is null
        NegativeArraySizeException - if the length parameter is negative
        SecurityException -
        • if the array cannot be accessed from current context
        • if requesting access attributes that were not available for the array parameter
        SystemException - with the following reason code:
        ArrayIndexOutOfBoundsException - if the view would cause access of data outside array bounds
        Since:
        3.1