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 wim_data;
028:
029: import java.io.UnsupportedEncodingException;
030:
031: /**
032: * This class represents PIN.
033: */
034: class PIN {
035:
036: /** Stored length for these PINs. */
037: static final int STORED_LENGTH = 8;
038:
039: /** PIN label. */
040: String label;
041:
042: /** PIN ID. */
043: int id;
044:
045: /** PIN reference. */
046: int ref;
047:
048: /** Path. */
049: short[] path;
050:
051: /** PIN value. */
052: String value;
053:
054: /**
055: * Constructor.
056: * @param label PIN label
057: * @param id PIN ID
058: * @param ref PIN reference
059: * @param path path
060: * @param value PIN value
061: */
062: PIN(String label, int id, int ref, short[] path, String value) {
063:
064: this .label = label;
065: this .id = id;
066: this .ref = ref;
067: this .path = path;
068: this .value = value;
069: }
070:
071: /**
072: * Generates TLV structure that represents this PIN.
073: * @return TLV structure
074: */
075: TLV toTLV() {
076:
077: TLV t, c, v;
078:
079: t = TLV.createSequence();
080:
081: t.setChild(TLV.createSequence()).setChild(
082: Utils.createLabel(label))
083: .setNext(
084: new TLV(TLV.BITSTRING_TYPE, Utils
085: .shortToBytes(0x0780)));
086:
087: c = t.child;
088:
089: c.setNext(TLV.createSequence()).setChild(
090: TLV.createOctetString(new byte[] { (byte) id }));
091:
092: c.next
093: .setNext(new TLV(0xa1))
094: .setChild(TLV.createSequence())
095: .setChild(
096: new TLV(TLV.BITSTRING_TYPE, Utils
097: .shortToBytes(0x022c)))
098: .setNext(new TLV(TLV.ENUMERATED_TYPE, new byte[] { 1 }))
099: .setNext(TLV.createInteger(4))
100: .setNext(TLV.createInteger(STORED_LENGTH))
101: .setNext(TLV.createInteger(ref).setTag(0x80))
102: .setNext(
103: TLV
104: .createOctetString(new byte[] { (byte) 0xff }))
105: .setNext(Utils.createPath(path));
106:
107: return t;
108: }
109:
110: /**
111: * Returns data for this PIN.
112: * @return PIN data
113: */
114: public byte[] getData() {
115:
116: byte[] data = new byte[STORED_LENGTH];
117: for (int i = 0; i < data.length; i++) {
118: data[i] = -1;
119: }
120:
121: try {
122: byte[] t = value.getBytes("UTF-8");
123: for (int i = 0; i < t.length; i++) {
124: data[i] = t[i];
125: }
126: return data;
127: } catch (UnsupportedEncodingException e) {
128: return null;
129: }
130: }
131: }
|