Package org.jmrtd

Class DefaultFileSystem

  • All Implemented Interfaces:
    net.sf.scuba.smartcards.FileSystemStructured

    public class DefaultFileSystem
    extends Object
    implements net.sf.scuba.smartcards.FileSystemStructured
    A file system for ICAO MRTDs (and similar file systems). This translates abstract high level selection and read binary commands to concrete low level file related APDUs which are sent to the ICC through the card service.
    Since:
    0.7.0
    Version:
    $Revision: 1799 $
    Author:
    The JMRTD team ([email protected])
    • Constructor Detail

      • DefaultFileSystem

        public DefaultFileSystem​(APDULevelReadBinaryCapable service,
                                 boolean isSFIEnabled)
        Creates a file system.
        Parameters:
        service - the card service supporting low-level SELECT and/or READ BINARY commands
        isSFIEnabled - whether the file system should use short file identifiers in READ BINARY commands
      • DefaultFileSystem

        public DefaultFileSystem​(APDULevelReadBinaryCapable service,
                                 boolean isSFIEnabled,
                                 Map<Short,Byte> fidToSFI)
        Creates a file system.
        Parameters:
        service - the card service supporting low-level SELECT and/or READ BINARY commands
        isSFIEnabled - whether the file system should use short file identifiers in READ BINARY commands
        fidToSFI - maps file identifiers to short file identifiers
    • Method Detail

      • setWrapper

        public void setWrapper​(net.sf.scuba.smartcards.APDUWrapper wrapper)
        Sets the current wrapper to the given APDU wrapper. Subsequent APDUs will be wrapped before sending to the ICC.
        Parameters:
        wrapper - an APDU wrapper
      • getSelectedPath

        public net.sf.scuba.smartcards.FileInfo[] getSelectedPath()
                                                           throws net.sf.scuba.smartcards.CardServiceException
        Returns the selected path.
        Specified by:
        getSelectedPath in interface net.sf.scuba.smartcards.FileSystemStructured
        Returns:
        the path components
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on error
      • selectFile

        public void selectFile​(short fid)
                        throws net.sf.scuba.smartcards.CardServiceException
        Selects a file.
        Specified by:
        selectFile in interface net.sf.scuba.smartcards.FileSystemStructured
        Parameters:
        fid - indicates the file to select
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on error communicating over the service
      • readBinary

        public byte[] readBinary​(int offset,
                                 int length)
                          throws net.sf.scuba.smartcards.CardServiceException
        Reads a block of bytes.
        Specified by:
        readBinary in interface net.sf.scuba.smartcards.FileSystemStructured
        Parameters:
        offset - offset index in the selected file
        length - the number of bytes to read
        Returns:
        a copy of the bytes read
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on error
      • sendSelectFile

        public void sendSelectFile​(short fid)
                            throws net.sf.scuba.smartcards.CardServiceException
        Selects a file within the MRTD application.
        Parameters:
        fid - a file identifier
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on error
      • sendReadBinary

        public byte[] sendReadBinary​(int offset,
                                     int le,
                                     boolean isTLVEncodedOffsetNeeded)
                              throws net.sf.scuba.smartcards.CardServiceException
        Sends a READ BINARY command using a short file identifier to the passport, using the wrapper when a secure channel has been set up.
        Parameters:
        offset - offset into the file
        le - the expected length of the file to read
        isTLVEncodedOffsetNeeded - whether to encode the offset in a TLV object (typically for offset larger than 32767)
        Returns:
        a byte array of length le with (the specified part of) the contents of the currently selected file
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on tranceive error
      • sendReadBinary

        public byte[] sendReadBinary​(int sfi,
                                     int offset,
                                     int le,
                                     boolean isTLVEncodedOffsetNeeded)
                              throws net.sf.scuba.smartcards.CardServiceException
        Sends a READ BINARY command using a short file identifier to the passport, using the wrapper when a secure channel has been set up.
        Parameters:
        sfi - the short file identifier byte as int value (between 0 and 255)
        offset - offset into the file
        le - the expected length of the file to read
        isTLVEncodedOffsetNeeded - whether to encode the offset in a TLV object (typically for offset larger than 32767)
        Returns:
        a byte array of length le with (the specified part of) the contents of the currently selected file
        Throws:
        net.sf.scuba.smartcards.CardServiceException - on tranceive error