com.musclecard.CardEdge
Class ObjectManager

java.lang.Object
  extended bycom.musclecard.CardEdge.ObjectManager

public class ObjectManager
extends java.lang.Object

Object Manager Class

Objects are linked in a list in the dynamic memory. No smart search is done at the moment.

TODO - Could we definitively avoid a map enforcing the ID (equal to the memory address, i.e.) - security implications ?

Object fields:
    short next
    short obj_class
    short obj_id
    short obj_size
    byte[] data
 

Version:
0.9.9
Author:
Tommaso Cucinotta, David Corcoran, Ludovic Rousseau

Field Summary
private  short it
          Iterator on objects.
private  MemoryManager mem
          The Memory Manager object
static byte OBJ_ACL_SIZE
           
private static byte OBJ_H_ACL
           
private static byte OBJ_H_CLASS
           
private static byte OBJ_H_DATA
           
private static byte OBJ_H_ID
           
private static byte OBJ_H_NEXT
           
private static byte OBJ_H_SIZE
           
private static byte OBJ_HEADER_SIZE
           
private  short obj_list_head
          Head of the objects' list
static short RECORD_SIZE
          Size of an Object Record filled by getFirstRecord() or getNextRecord(): ID, Size, ACL
static short SW_NO_MEMORY_LEFT
          There have been memory problems on the card
static short SW_OBJECT_NOT_FOUND
           
 
Constructor Summary
ObjectManager(MemoryManager mem_ref)
          Constructor for the ObjectManager class.
 
Method Summary
 boolean authorizeDeleteFromAddress(short base, short logged_ids)
          Allow or unallow delete on object given the logged identities
private  boolean authorizeOp(short required_ids, short logged_ids)
          Check if logged in identities satisfy requirements for an operation
 boolean authorizeReadFromAddress(short base, short logged_ids)
          Allow or unallow read on object given the logged identities
 boolean authorizeWriteFromAddress(short base, short logged_ids)
          Allow or unallow write on object given the logged identities
 boolean clampObject(short type, short id, short new_size)
          Clamps an object freeing the unused memory
 boolean compareACLFromAddress(short base, byte[] acl)
          Compare an object's ACL with the provided ACL.
 short createObject(short type, short id, short size, byte[] acl_buf, short acl_offset)
          Creates an object with specified parameters.
 short createObjectMax(short type, short id, byte[] acl_buf, short acl_offset)
          Creates an object with the maximum available size
 void destroyObject(short type, short id, boolean secure)
          Destroy the specified object
 boolean exists(short type, short id)
          Checks if an object exists
 short getBaseAddress(short type, short id)
          Returns the data base address (offset) for an object.
private  short getEntry(short type, short id)
          Returns the header base address (offset) for the specified object.
 boolean getFirstRecord(byte[] buffer, short offset)
          Resets the objects iterator and retrieves the information record of the first object, if any.
 boolean getNextRecord(byte[] buffer, short offset)
          Retrieves the information record of the next object, if any.
 short getSizeFromAddress(short base)
          Returns object size from the base address
private  void setACL(short type, short id, byte[] acl_buf, short acl_offset)
          Set the object's ACL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

it

private short it
Iterator on objects.


mem

private MemoryManager mem
The Memory Manager object


OBJ_ACL_SIZE

public static final byte OBJ_ACL_SIZE
See Also:
Constant Field Values

OBJ_H_ACL

private static final byte OBJ_H_ACL
See Also:
Constant Field Values

OBJ_H_CLASS

private static final byte OBJ_H_CLASS
See Also:
Constant Field Values

OBJ_H_DATA

private static final byte OBJ_H_DATA
See Also:
Constant Field Values

OBJ_H_ID

private static final byte OBJ_H_ID
See Also:
Constant Field Values

OBJ_H_NEXT

private static final byte OBJ_H_NEXT
See Also:
Constant Field Values

OBJ_H_SIZE

private static final byte OBJ_H_SIZE
See Also:
Constant Field Values

OBJ_HEADER_SIZE

private static final byte OBJ_HEADER_SIZE
See Also:
Constant Field Values

obj_list_head

private short obj_list_head
Head of the objects' list


RECORD_SIZE

public static final short RECORD_SIZE
Size of an Object Record filled by getFirstRecord() or getNextRecord(): ID, Size, ACL

See Also:
Constant Field Values

SW_NO_MEMORY_LEFT

public static final short SW_NO_MEMORY_LEFT
There have been memory problems on the card

See Also:
Constant Field Values

SW_OBJECT_NOT_FOUND

public static final short SW_OBJECT_NOT_FOUND
See Also:
Constant Field Values
Constructor Detail

ObjectManager

public ObjectManager(MemoryManager mem_ref)
Constructor for the ObjectManager class.

Parameters:
mem_ref - The MemoryManager object to be used to allocate objects' memory.
Method Detail

authorizeDeleteFromAddress

public boolean authorizeDeleteFromAddress(short base,
                                          short logged_ids)
Allow or unallow delete on object given the logged identities


authorizeOp

private boolean authorizeOp(short required_ids,
                            short logged_ids)
Check if logged in identities satisfy requirements for an operation

Parameters:
required_ids - The required identities as from an ACL short
logged_ids - The current logged in identities as stored in CardEdge.logged_ids

authorizeReadFromAddress

public boolean authorizeReadFromAddress(short base,
                                        short logged_ids)
Allow or unallow read on object given the logged identities

Parameters:
base - The object base address as returned from getBaseAddress()
logged_ids - The current logged in identities as stored in CardEdge.logged_ids

authorizeWriteFromAddress

public boolean authorizeWriteFromAddress(short base,
                                         short logged_ids)
Allow or unallow write on object given the logged identities

Parameters:
base - The object base address as returned from getBaseAddress()
logged_ids - The current logged in identities as stored in CardEdge.logged_ids

clampObject

public boolean clampObject(short type,
                           short id,
                           short new_size)
Clamps an object freeing the unused memory

Parameters:
type - Object Type
id - Object ID (Type and ID form a generic 4 bytes identifier)
new_size - The new object size (must be less than current size)
Returns:
True if clamp was possible, false otherwise
Throws:
SW_NO_MEMORY_LEFT - exception if cannot allocate the memory. Does not check if object exists.

compareACLFromAddress

public boolean compareACLFromAddress(short base,
                                     byte[] acl)
Compare an object's ACL with the provided ACL.

Parameters:
base - The object base address, as returned from getBaseAddress()
acl - The buffer containing the ACL
Returns:
True if the ACLs are equal

createObject

public short createObject(short type,
                          short id,
                          short size,
                          byte[] acl_buf,
                          short acl_offset)
Creates an object with specified parameters.

Parameters:
type - Object Type
id - Object ID (Type and ID form a generic 4 bytes identifier)
acl_buf - Java byte array containing the ACL for the new object
acl_offset - Offset at which the ACL starts in acl_buf[]
Returns:
The memory base address for the object. It can be used in successive calls to xxxFromAddress() methods.
Throws:
SW_NO_MEMORY_LEFT - exception if cannot allocate the memory. Does not check if object exists.

createObjectMax

public short createObjectMax(short type,
                             short id,
                             byte[] acl_buf,
                             short acl_offset)
Creates an object with the maximum available size


destroyObject

public void destroyObject(short type,
                          short id,
                          boolean secure)
Destroy the specified object

Parameters:
type - Object Type
id - Object ID (Type and ID form a generic 4 bytes identifier)
secure - If true, object memory is zeroed before being released.

exists

public boolean exists(short type,
                      short id)
Checks if an object exists

Parameters:
type - The object type
id - The object ID
Returns:
true if object exists

getBaseAddress

public short getBaseAddress(short type,
                            short id)
Returns the data base address (offset) for an object.

The base address can be used for further calls to xxxFromAddress() methods

This function should only be used if performance issue arise. setObjectData() and getObjectData() should be used, instead.

Parameters:
type - Object Type
id - Object ID (Type and ID form a generic 4 bytes identifier)
Returns:
The starting offset of the object. At this location

getEntry

private short getEntry(short type,
                       short id)
Returns the header base address (offset) for the specified object.

Object header is found at the returned offset, while object data starts right after the header.

This performs a linear search, so performance issues could arise as the number of objects grows If object is not found, then returns NULL_OFFSET.

Parameters:
type - Object Type
id - Object ID (Type and ID form a generic 4 bytes identifier)
Returns:
The starting offset of the object or NULL_OFFSET if the object is not found.

getFirstRecord

public boolean getFirstRecord(byte[] buffer,
                              short offset)
Resets the objects iterator and retrieves the information record of the first object, if any.

Parameters:
buffer - The byte array into which the record will be copied
offset - The offset in buffer[] at which the record will be copied
Returns:
True if an object was found. False if there are no objects.
See Also:
getNextRecord(byte[], short)

getNextRecord

public boolean getNextRecord(byte[] buffer,
                             short offset)
Retrieves the information record of the next object, if any.

Parameters:
buffer - The byte array into which the record will be copied
offset - The offset in buffer[] at which the record will be copied
Returns:
True if an object was found. False if there are no more objects to inspect.
See Also:
getFirstRecord(byte[], short)

getSizeFromAddress

public short getSizeFromAddress(short base)
Returns object size from the base address


setACL

private void setACL(short type,
                    short id,
                    byte[] acl_buf,
                    short acl_offset)
Set the object's ACL.