Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/smartcardio/Card.java
38827 views
/*1* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.smartcardio;2627import java.nio.ByteBuffer;2829/**30* A Smart Card with which a connection has been established. Card objects31* are obtained by calling {@link CardTerminal#connect CardTerminal.connect()}.32*33* @see CardTerminal34*35* @since 1.636* @author Andreas Sterbenz37* @author JSR 268 Expert Group38*/39public abstract class Card {4041/**42* Constructs a new Card object.43*44* <p>This constructor is called by subclasses only. Application should45* call the {@linkplain CardTerminal#connect CardTerminal.connect()}46* method to obtain a Card47* object.48*/49protected Card() {50// empty51}5253/**54* Returns the ATR of this card.55*56* @return the ATR of this card.57*/58public abstract ATR getATR();5960/**61* Returns the protocol in use for this card.62*63* @return the protocol in use for this card, for example "T=0" or "T=1"64*/65public abstract String getProtocol();6667/**68* Returns the CardChannel for the basic logical channel. The basic69* logical channel has a channel number of 0.70*71* @throws SecurityException if a SecurityManager exists and the72* caller does not have the required73* {@linkplain CardPermission permission}74* @throws IllegalStateException if this card object has been disposed of75* via the {@linkplain #disconnect disconnect()} method76*/77public abstract CardChannel getBasicChannel();7879/**80* Opens a new logical channel to the card and returns it. The channel is81* opened by issuing a <code>MANAGE CHANNEL</code> command that should use82* the format <code>[00 70 00 00 01]</code>.83*84* @throws SecurityException if a SecurityManager exists and the85* caller does not have the required86* {@linkplain CardPermission permission}87* @throws CardException is a new logical channel could not be opened88* @throws IllegalStateException if this card object has been disposed of89* via the {@linkplain #disconnect disconnect()} method90*/91public abstract CardChannel openLogicalChannel() throws CardException;9293/**94* Requests exclusive access to this card.95*96* <p>Once a thread has invoked <code>beginExclusive</code>, only this97* thread is allowed to communicate with this card until it calls98* <code>endExclusive</code>. Other threads attempting communication99* will receive a CardException.100*101* <p>Applications have to ensure that exclusive access is correctly102* released. This can be achieved by executing103* the <code>beginExclusive()</code> and <code>endExclusive</code> calls104* in a <code>try ... finally</code> block.105*106* @throws SecurityException if a SecurityManager exists and the107* caller does not have the required108* {@linkplain CardPermission permission}109* @throws CardException if exclusive access has already been set110* or if exclusive access could not be established111* @throws IllegalStateException if this card object has been disposed of112* via the {@linkplain #disconnect disconnect()} method113*/114public abstract void beginExclusive() throws CardException;115116/**117* Releases the exclusive access previously established using118* <code>beginExclusive</code>.119*120* @throws SecurityException if a SecurityManager exists and the121* caller does not have the required122* {@linkplain CardPermission permission}123* @throws IllegalStateException if the active Thread does not currently have124* exclusive access to this card or125* if this card object has been disposed of126* via the {@linkplain #disconnect disconnect()} method127* @throws CardException if the operation failed128*/129public abstract void endExclusive() throws CardException;130131/**132* Transmits a control command to the terminal device.133*134* <p>This can be used to, for example, control terminal functions like135* a built-in PIN pad or biometrics.136*137* @param controlCode the control code of the command138* @param command the command data139*140* @throws SecurityException if a SecurityManager exists and the141* caller does not have the required142* {@linkplain CardPermission permission}143* @throws NullPointerException if command is null144* @throws CardException if the card operation failed145* @throws IllegalStateException if this card object has been disposed of146* via the {@linkplain #disconnect disconnect()} method147*/148public abstract byte[] transmitControlCommand(int controlCode,149byte[] command) throws CardException;150151/**152* Disconnects the connection with this card. After this method returns,153* calling methods on this object or in CardChannels associated with this154* object that require interaction with the card will raise an155* IllegalStateException.156*157* @param reset whether to reset the card after disconnecting.158*159* @throws CardException if the card operation failed160* @throws SecurityException if a SecurityManager exists and the161* caller does not have the required162* {@linkplain CardPermission permission}163*/164public abstract void disconnect(boolean reset) throws CardException;165166}167168169