⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jibappletaccesscardservice.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
字号:
/*--------------------------------------------------------------------------- * Copyright (C) 1999,2000 Dallas Semiconductor Corporation, All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Dallas Semiconductor * shall not be used except as stated in the Dallas Semiconductor * Branding Policy. *--------------------------------------------------------------------------- */package com.dalsemi.onewire.jib.service;import opencard.opt.applet.mgmt.*;import java.util.*;import opencard.opt.applet.*;import opencard.core.service.*;import opencard.core.terminal.*;import com.dalsemi.onewire.container.*;import com.dalsemi.onewire.jib.terminal.*;/** * <p>The <code>JiBAppletAccessCardService</code> class implements  * calls for accessing card-resident applets.</p> *  * <p>This set of methods supports access to an applet directory and * retrieves information like a list of applets, security domain, * label, etc.. This information is returned in an <code>AppletInfo</code> * object.</p> *  * <p>This interface is typically implemented for card technology handling * multi-application management different (e.g. EMV compliant cards, * JavaCards, ...)<p> * * @author   K * * @see JiBAppletManagerCardService * @see JiBCardServiceFactory */public class JiBAppletAccessCardService extends CardService implements AppletAccessCardService{    protected OneWireContainer16 owc16;// = ((com.dalsemi.onewire.jib.terminal.JiBCardTerminal) this.getCardChannel().getCardTerminal()).getContainer(getCard().getCardID().getSlot().getSlotID());    protected void initContainer()    {        CardID cid = getCard().getCardID();        JiBCardTerminal terminal = (JiBCardTerminal) cid.getCardTerminal();        owc16 = terminal.getContainer(cid.getSlot().getSlotID());            }    /**     * List the available card-resident applets on the smart card.<p>     *     * @return   An array of <code>AppletInfo</code>s of the     *           card-resident applets.     * @exception opencard.core.service.CardServiceException     *            Thrown when error occurs during execution of the operation.     */    public AppletInfo[] list() throws CardServiceException, CardTerminalException    {        if (owc16==null)            initContainer();             Vector v = new Vector();                    com.dalsemi.onewire.container.ResponseAPDU rapdu;        try        {            owc16.getAdapter().beginExclusive(true);            for (int i=0;i<16;i++)            {                rapdu = owc16.getAIDByNumber(i);                if (rapdu.getSW()==0x9000)                {                    byte[] data = rapdu.getData();                    AppletID id = new AppletID(data);                    AppletInfo info = new AppletInfo();                    info.setAppletID(id);                    info.setLabel((new String(data, 1, 16)).trim());                    v.addElement(info);                }            }            owc16.getAdapter().endExclusive();            AppletInfo[] ret_info = new AppletInfo[v.size()];            for (int i=0;i<ret_info.length;i++)            {                ret_info[i] = (AppletInfo)v.elementAt(i);            }            return ret_info;        }        catch(com.dalsemi.onewire.OneWireException e)        {            throw new CardTerminalException(e.getMessage());        }    }    /**     * <p>Check whether the card-resident applet with the specified     * <code>AppletID</code> exists on the card.</p>     *     * <p>On the Java Powered <u>i</u>Button, this is a very inefficient     * operation.  To check if the applet exists, it should not be selected,     * because this changes the behaviour of the <u>i</u>Button (the newly     * selected applet recieves all APDU's).  This implementation, then,     * makes a list of all available applet IDs and checks to see if any     * of them equals <code>appletIdentifier</code>.</p>     *     * @param    applet identifier     *           The <code>AppletID</code> object referring to the applet     *           whose existence we want to check.     * @return   <code>true</code> if card-resident applet exists, otherwise     *           return <code>false</code>.     * @exception opencard.core.service.CardServiceException     *            Thrown when error occurs during execution of the operation.     */    public boolean exists(AppletID appletIdentifier) throws CardServiceException, CardTerminalException    {        byte[] to = appletIdentifier.getBytes();        if (to==null)            return false;        //OK, we definitely don't want to select or delete the applet, but those are our only        //elegant choice if we want to send the AID to the button, so it looks like we need to do a list,        //and use that data.                AppletInfo[] info = list();        for (int i=0;i<info.length;i++)        {            byte[] from = info[i].getAppletID().getBytes();            boolean good = true;            if (to.length!=from.length)                good = false;            for (int k=0;(k<to.length) && good;k++)            {                if (to[k]!=from[k])                    good = false;            }            if (good) return true;        }                return false;    }    /**     * Reads the <code>AppletInfo</code> of a given applet ID from     * the card's list of applets.     * <p>     *     * @param     appletIdentifier     *            The <code>AppletID</code> object referring to the applet     *            whose info we want to read.     * @return    An <code>AppletInfo</code> of the applets.     *            If no applet info was found for the given <code>AppletID</code>     *            a <code>null</code> is returned     * @exception opencard.core.service.CardServiceException     *            Thrown when error occurs during execution of the operation.     */    public AppletInfo getInfo(AppletID appletIdentifier) throws CardServiceException, CardTerminalException    {        /* I don't see that this one makes a whole lot of sense for iButtons.           I mean, lets look at what an AppletInfo entails...               AppletID       : this is the argument to the method...               SecurityDomain : i'm not messing with any of this stuff               label          : i create this from the appletinfo, since we don't really                                 have an Applet.getInformationLabel() method on the ibutton               data           : this is just free data, the only thing I can think of to                                 say here is the ROMID of the button, which you can get through                                 the card service factory through the CardType object         */        if (exists(appletIdentifier))        {            AppletInfo inf = new AppletInfo();            inf.setAppletID(appletIdentifier);            inf.setLabel((new String(appletIdentifier.getBytes(), 1, 16)).trim());            return inf;        }        return null;    }    //inherited from CardServiceInterface    /**     * <p>Provides an application-specific dialog for CHV input.     * If an application does not set it's own dialog, a default     * dialog will be used if password input is required.</p>     *     * <b><i>NOTE: This method is not implemented in the <code>     *    JiBAppletAccessCardService</code> class.</i></b>     *     * @param dialog   the dialog to use for querying a password or PIN     */    public void setCHVDialog(CHVDialog dialog)    {            }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -