ds.ov2.bignat
Class Bignat_array

java.lang.Object
  extended by ds.ov2.util.Serializable_array
      extended by ds.ov2.bignat.Bignat_array
All Implemented Interfaces:
APDU_Serializable
Direct Known Subclasses:
Vector

public class Bignat_array
extends Serializable_array
implements APDU_Serializable

APDU_Serializable interface around an array of Bignats. This is used inside Vector to factor out the bignat array functionality. This implementation uses simply an bignat array internally. Other implementations relying on a huge byte array seem possible.

Although this is a card data type, Serializable_array.is_compatible_with() is not overridden here. This is left for clients extending this class.

The size of the array is determined by the length argument of the constructor. The size stays constant for the lifetime of the object. However, the array can provide the illusion of a different (smaller) length. This functionality is thought for testing purposes and only available if the cpp symbol VARIABLE_SIZE_BIGNATS is defined, see field length and method set_length(short).

For a number of general topics see also the package description.

CPP Preprocessing
This class uses the following cpp defines: PACKAGE, DIGIT_TYPE, PUBLIC, VARIABLE_SIZE_BIGNATS, JAVACARD_APPLET, ASSERT, ASSERT_TAG(condition, tag)
Execution Environment:
host, card
Author:
Hendrik Tews
Version:
$Revision: 1.22 $
Last Commit:
$Date: 2009-04-06 12:51:26 $ by $Author: tews $

Field Summary
private  Bignat[] a
          The array of the contained bignats.
protected  short length
          Length of the array a.
 
Constructor Summary
Bignat_array(short length)
          Nonallocating constructor.
Bignat_array(short bignat_size, short length, boolean in_ram)
          Allocating constructor.
 
Method Summary
 void allocate(short bignat_size, boolean in_ram)
          Allocate fresh bignats for the whole array.
 void copy_digit(short digit, byte[] buf)
          Copy digit.
protected  APDU_Serializable[] get_array()
          Return the bignat array a in support for abstract Serializable_array.
 short get_bignat_length()
          Digit length of the contained bignats in bytes.
 short get_bignat_size()
          Size of the contained bignats in bytes.
 short get_length()
          Return length as effective size in support for abstract Serializable_array.
 Bignat get(short i)
          Return element i.
 void register_long_bignats()
          Register the array contents as long resizable bignats.
 void register_short_bignats()
          Register the array contents as short resizable bignats.
 void set_length(short new_length)
          Virtual length change.
 void set(short i, Bignat b)
          Set element i.
 short size()
          Size in bytes necessary to send or receive this object via the OV-chip protocol layer, see APDU_Serializable.size().
 
Methods inherited from class ds.ov2.util.Serializable_array
from_byte_array, is_compatible_with, to_byte_array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ds.ov2.util.APDU_Serializable
from_byte_array, is_compatible_with, to_byte_array
 

Field Detail

a

private Bignat[] a
The array of the contained bignats. Its length is determind in the constructor.


length

protected short length
Length of the array a. Final unless VARIABLE_SIZE_BIGNATS is defined. Can be changed via set_length to provide the illusion of a shorter array.

Constructor Detail

Bignat_array

public Bignat_array(short length)
Nonallocating constructor. This constructor allocates the internal bignat array but leaves null references in there. The array must then be filled by other means, for instance with set. Useful if some of the bignats that are going to populate this array are already allocated.

ASSERT's that length is at least 1. Bignat arrays of length zero are almost useless, because get_bignat_size() and get_bignat_length() access the element at index 0.

Parameters:
length - length of the array (maximal length if VARIABLE_SIZE_BIGNATS is defined and set_length is available).

Bignat_array

public Bignat_array(short bignat_size,
                    short length,
                    boolean in_ram)
Allocating constructor. Creates a fresh array with newly allocated bignats.

ASSERT's that length is at least 1. Bignat arrays of length zero are almost useless, because get_bignat_size() and get_bignat_length() access the element at index 0.

Parameters:
bignat_size - size of the bignats in the array
length - length of the array
in_ram - if true, allocate the digit array of the
Method Detail

set_length

public void set_length(short new_length)
Virtual length change. Set the length field to provide the illusion of a different array size.

Asserts that new_length is shorter than the real length of a.

Only available if VARIABLE_SIZE_BIGNATS is defined.

Parameters:
new_length - new length

allocate

public void allocate(short bignat_size,
                     boolean in_ram)
Allocate fresh bignats for the whole array. Fills the array with newly allocated, distinct bignats.

Parameters:
bignat_size - size of the bignats
in_ram - if true, allocate the digit array of the bignats in transient memory (RAM) on the card.

register_short_bignats

public void register_short_bignats()
Register the array contents as short resizable bignats. See Resize.

Only available if VARIABLE_SIZE_BIGNATS is defined.


register_long_bignats

public void register_long_bignats()
Register the array contents as long resizable bignats. See Resize.

Only available if VARIABLE_SIZE_BIGNATS is defined.


get_bignat_size

public short get_bignat_size()
Size of the contained bignats in bytes. Returns a[0].size().

Returns:
bignat size in bytes

get_bignat_length

public short get_bignat_length()
Digit length of the contained bignats in bytes. Returns a[0].length().

Returns:
number of digits of the contained bignats

get

public Bignat get(short i)
Return element i.

Parameters:
i - index
Returns:
bignat at index i
Throws:
ArrayIndexOutOfBoundsException - if i is out of bounds

set

public void set(short i,
                Bignat b)
Set element i.

Parameters:
i - index
b - bignat to store at index i
Throws:
ArrayIndexOutOfBoundsException - if i is out of bounds

copy_digit

public void copy_digit(short digit,
                       byte[] buf)
Copy digit. Copy digit digit of all bignats in the array into buf such that buf[0] contains the digit of get(0), buf[1] of get(1), and so on.

buf is an array of type DIGIT_TYPE.

Asserts that buf is at least of size length and that digit is less than the size of the bignats in this array.

Used in exponentiation in Vector.exponent_mod

Parameters:
digit - digit number to copy
buf - of type DIGIT_TYPE[], result array of digits

get_array

protected APDU_Serializable[] get_array()
Return the bignat array a in support for abstract Serializable_array.

Specified by:
get_array in class Serializable_array
Returns:
array of objects to (de-)serialize

get_length

public short get_length()
Return length as effective size in support for abstract Serializable_array.

Overrides:
get_length in class Serializable_array
Returns:
length

size

public short size()
Size in bytes necessary to send or receive this object via the OV-chip protocol layer, see APDU_Serializable.size().

Specified by:
size in interface APDU_Serializable
Overrides:
size in class Serializable_array
Returns:
size in bytes