Package opencard.opt.iso.fs
Class CardFilePath
- java.lang.Object
-
- opencard.opt.iso.fs.CardFilePath
-
- All Implemented Interfaces:
SecurityDomain
public class CardFilePath extends java.lang.Object implements SecurityDomain
CardFilePath encapsulates the various ways of addressing files on a smart card:- File ID paths: A sequence of two byte file IDs as defined in ISO 7816-4
- Short File ID: One byte short file ID (0..31) for selecting EFs.
- Application ID: 5-16 bytes for selecting applications as defined by ISO 7816-4/5
- Symbolic paths: A sequence of symbolic names
- Author:
- Dirk Husemann (hud@zurich.ibm.com), Reto Hermann (rhe@zurich.ibm.com)
- See Also:
CardFile
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
APPID_PREFIX
protected CardFilePathComponent[]
components
CardFilePath array containing the path components.static java.lang.String
FID_SEPARATOR
static java.lang.String
PARTIALAPPID_POSTFIX
static java.lang.String
ROOTFILEID
static java.lang.String
SYM_SEPARATOR
There are two kinds of path component separators: SYM_SEPARATOR used for symbolic paths (for example "/wuff/oink") FID_SEPARATOR used for file ID paths (for example ":CAFF:EEBA:BE00") Although represented as a string, both separators really are just one character long.
-
Constructor Summary
Constructors Constructor Description CardFilePath(byte[] bites)
Instantiate a CardFilePath from an array of bytes.CardFilePath(java.lang.String path)
Create a CardFilePath from a String.CardFilePath(CardFilePath path)
Clone the path object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CardFilePath
append(CardFilePath path)
Append to this CardFilePath object.CardFilePath
append(CardFilePathComponent comp)
Append to this CardFilePath object.CardFilePath
chompPrefix(CardFilePath prefix)
Chomp of the prefix of this path.boolean
chompTail()
Chomp off the last component of the path.int
commonPrefixLength(CardFilePath path)
Return the length of the common CardFilePath prefix (if at all).java.util.Enumeration
components()
Return an enumeration of the components of this CardFilePath.boolean
equals(java.lang.Object filePath)
Check whether this CardFilePath is equal to another.CardFilePath
greatestCommonPrefix(CardFilePath path)
Return the longest commmon prefix with another CardFilePath.int
hashCode()
Overrides Object.hashCode() since we already provide equals().int
numberOfComponents()
Return the number components in this path.boolean
startsWith(CardFilePath prefix)
Check whether this path starts with prefix.CardFilePathComponent
tail()
Return the last CardFilePathComponent of this CardFilePath object.java.lang.String
toString()
Return a string representation of this object.
-
-
-
Field Detail
-
SYM_SEPARATOR
public static final java.lang.String SYM_SEPARATOR
There are two kinds of path component separators:- SYM_SEPARATOR used for symbolic paths (for example "/wuff/oink")
- FID_SEPARATOR used for file ID paths (for example ":CAFF:EEBA:BE00")
- See Also:
- Constant Field Values
-
FID_SEPARATOR
public static final java.lang.String FID_SEPARATOR
- See Also:
- Constant Field Values
-
APPID_PREFIX
public static final java.lang.String APPID_PREFIX
- See Also:
- Constant Field Values
-
PARTIALAPPID_POSTFIX
public static final java.lang.String PARTIALAPPID_POSTFIX
- See Also:
- Constant Field Values
-
ROOTFILEID
public static final java.lang.String ROOTFILEID
- See Also:
- Constant Field Values
-
components
protected CardFilePathComponent[] components
CardFilePath array containing the path components.
-
-
Constructor Detail
-
CardFilePath
public CardFilePath(java.lang.String path) throws CardIOException
Create a CardFilePath from a String. The string representation uses the following notation:- :XXYY:ZZAA
- A path of file IDs; always starts with a colon (':'); always uses two bytes (with leading 0 if necessary); individual file IDs are separated by colons (':') as well
- :ZZ or :XXYY:ZZ
- A short file ID or a path ending in a short file ID; short file IDs can only occur at the end of path
- #AABBCCDDEE..QQ
- A 5-16 byte application ID as a sequence of bytes; must start with a hash ('#')
- Some string
- A 5-16 byte application ID as a string; can contain at most 16 characters
- #AABB*
- A partial application ID as a sequence of bytes
- some string*
- A partial application ID as a string.
- /some/path/using/symbolic/names
- A sequence of symbolic names started and separated by slashes ('/')
- Parameters:
path
- The string representation of the path.- Throws:
CardIOException
- Thrown either when the path has a silly format (e.g., file ID components followed by an application ID) or when the path contains malformed components (e.g., a short file ID containing just one nibble instead of a full byte) or when the path is empty
-
CardFilePath
public CardFilePath(byte[] bites)
Instantiate a CardFilePath from an array of bytes. Gobble up two bytes at a time and turn them into a two byte file ID. A remaining byte is turned into a short file ID.- Parameters:
bites
- An array of bytes containing file IDs; the lowest pair ( bites[0] and bites[1]) form the first path component; bites[0] is the high order byte and bites[1] is the low order byte.
-
CardFilePath
public CardFilePath(CardFilePath path)
Clone the path object.- Parameters:
path
- The CardFilePath object to clone.
-
-
Method Detail
-
components
public java.util.Enumeration components()
Return an enumeration of the components of this CardFilePath.- Returns:
- An Enumeration of CardFilePathComponent objects.
-
append
public CardFilePath append(CardFilePath path)
Append to this CardFilePath object.- Parameters:
path
- The CardFilePath object to append.
-
append
public CardFilePath append(CardFilePathComponent comp)
Append to this CardFilePath object.- Parameters:
comp
- The CardFilePathComponent object to append.
-
startsWith
public boolean startsWith(CardFilePath prefix)
Check whether this path starts with prefix. Note that prefix must be a true prefix of this path (i.e., after chompPrefix(prefix) this path would not be empty).- Parameters:
prefix
- The potentially common prefix.- Returns:
- True if this path starts with prefix
-
equals
public boolean equals(java.lang.Object filePath)
Check whether this CardFilePath is equal to another.- Overrides:
equals
in classjava.lang.Object
- Parameters:
filePath
- The path to compare with.- Returns:
- True if both paths are equal.
-
commonPrefixLength
public int commonPrefixLength(CardFilePath path)
Return the length of the common CardFilePath prefix (if at all). prefix.- Parameters:
path
- The other CardFilePath to check against.- Returns:
- The length of the common prefix (0 indicates that only the MF is common).
-
greatestCommonPrefix
public CardFilePath greatestCommonPrefix(CardFilePath path)
Return the longest commmon prefix with another CardFilePath.- Parameters:
path
- The other CardFilePath.- Returns:
- A new CardFilePath object containing the longest common prefix.
- Throws:
java.lang.IllegalArgumentException
- Thrown when both paths do not share a common prefix.
-
chompPrefix
public CardFilePath chompPrefix(CardFilePath prefix)
Chomp of the prefix of this path.- Parameters:
prefix
- The prefix to chomp off.- Returns:
- The chomped path.
- Throws:
java.lang.IllegalArgumentException
- Thrown when the prefix is not.
-
chompTail
public boolean chompTail()
Chomp off the last component of the path. This is a no-op if the path consists of a single component.- Returns:
- True if chomping succeeded.
-
tail
public CardFilePathComponent tail()
Return the last CardFilePathComponent of this CardFilePath object.- Returns:
- The last CardFilePathComponent of this CardFilePath.
-
numberOfComponents
public int numberOfComponents()
Return the number components in this path.- Returns:
- The number of CardFilePathComponents in this CardFilePath.
-
hashCode
public int hashCode()
Overrides Object.hashCode() since we already provide equals().- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code.
-
toString
public java.lang.String toString()
Return a string representation of this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representing this object.
-
-