001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.satsa.aclapplet;
028:
029: /**
030: * This class represents card file.
031: */
032: class File {
033:
034: /** File type constant - dedicated file (DF). */
035: static final byte DIR = 1;
036: /**
037: * File type constant - DF where PINs reside, must be unique for
038: * this implementation. */
039: static final byte PIN = 3;
040: /**
041: * File type constant - elementary file (EF) where private key
042: * reside. */
043: static final byte PrivateKeyFile = 4;
044: /** File type constant - root DF for WIM application. */
045: static final byte WIM = 9;
046: /** File type constant - EF with read permission. */
047: static final byte READ = 16;
048: /** File type constant - EF with read/write permission. */
049: static final byte UPDATE = 48;
050: /** File attribute constant - EF is mostly empty . */
051: static final byte EMPTY = 64;
052:
053: /** Parent DF. */
054: DFile parent;
055: /** File identifier. */
056: short id;
057: /** File type. */
058: short type;
059:
060: /**
061: * Returns true if this file is DF.
062: * @return true.
063: */
064: boolean isDF() {
065: return true;
066: }
067: }
068:
069: /**
070: * This class represents dedicated card file.
071: */
072: class DFile extends File {
073:
074: /**
075: * Files contained in this DF.
076: */
077: File[] files;
078:
079: /**
080: * Constructs new DFile oblect.
081: * @param parent parent DF
082: * @param id file identifier
083: * @param type file type
084: */
085: public DFile(DFile parent, short id, short type) {
086:
087: this .parent = parent;
088: this .id = id;
089: this .type = type;
090: }
091:
092: /**
093: * This method is used in file selection.
094: * @param id file identifier
095: * @return this file if it has specified identifier, one of the
096: * files in this DF or null if not found
097: */
098: public File getFile(short id) {
099:
100: if (this .id == id) {
101: return this ;
102: }
103:
104: for (short i = 0; i < files.length; i++) {
105:
106: if (files[i].id == id) {
107: return files[i];
108: }
109: }
110: return null;
111: }
112: }
113:
114: /**
115: * This class represents elementary card file.
116: */
117: class EFile extends File {
118:
119: /** Offset of file data in <code>Data.Files</code> array. */
120: short offset;
121: /** File length. */
122: short length;
123: /** File data. */
124: byte[] data;
125:
126: /**
127: * Constructs new EFile object.
128: * @param parent parent DF
129: * @param id file identifier
130: * @param type file type
131: * @param offset offset of file data in <code>data</code> array
132: * @param length file length
133: * @param data array where file data stored
134: */
135: public EFile(DFile parent, short id, short type, short offset,
136: short length, byte[] data) {
137:
138: this .parent = parent;
139: this .id = id;
140: this .type = type;
141: this .offset = offset;
142: this .length = length;
143: this .data = data;
144: }
145:
146: /**
147: * Returns true if this file is DF.
148: * @return false
149: */
150: boolean isDF() {
151: return false;
152: }
153: }
|