< prev index next >

## src/java.smartcardio/share/classes/javax/smartcardio/CommandAPDU.java

Print this page

      1 /*
      2  * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     23  * questions.
     24  */
     25
     26 package javax.smartcardio;
     27
     28 import java.util.Arrays;
     29
     30 import java.nio.ByteBuffer;

     31
     32 /**
     33  * A command APDU following the structure defined in ISO/IEC 7816-4.
     34  * It consists of a four byte header and a conditional body of variable length.
     35  * This class does not attempt to verify that the APDU encodes a semantically
     36  * valid command.
     37  *
     38  * <p>Note that when the expected length of the response APDU is specified
     39  * in the {@linkplain #CommandAPDU(int,int,int,int,int) constructors},
     40  * the actual length (Ne) must be specified, not its
     41  * encoded form (Le). Similarly, {@linkplain #getNe} returns the actual
     42  * value Ne. In other words, a value of 0 means "no data in the response APDU"
     43  * rather than "maximum length."
     44  *
     45  * <p>This class supports both the short and extended forms of length
     46  * encoding for Ne and Nc. However, note that not all terminals and Smart Cards
     47  * are capable of accepting APDUs that use the extended form.
     48  *
     49  * <p>For the header bytes CLA, INS, P1, and P2 the Java type <code>int</code>
     50  * is used to represent the 8 bit unsigned values. In the constructors, only
    579     public boolean equals(Object obj) {
    580         if (this == obj) {
    581             return true;
    582         }
    583         if (obj instanceof CommandAPDU == false) {
    584             return false;
    585         }
    586         CommandAPDU other = (CommandAPDU)obj;
    587         return Arrays.equals(this.apdu, other.apdu);
    588      }
    589
    590     /**
    591      * Returns the hash code value for this command APDU.
    592      *
    593      * @return the hash code value for this command APDU.
    594      */
    595     public int hashCode() {
    596         return Arrays.hashCode(apdu);
    597     }
    598

    599     private void readObject(java.io.ObjectInputStream in)
    600             throws java.io.IOException, ClassNotFoundException {
    601         apdu = (byte[])in.readUnshared();
    602         // initialize transient fields
    603         parse();
    604     }
    605
    606 }
      1 /*
      2  * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
      3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
      4  *
      5  * This code is free software; you can redistribute it and/or modify it
      6  * under the terms of the GNU General Public License version 2 only, as
      7  * published by the Free Software Foundation.  Oracle designates this
      8  * particular file as subject to the "Classpath" exception as provided
      9  * by Oracle in the LICENSE file that accompanied this code.
     10  *
     11  * This code is distributed in the hope that it will be useful, but WITHOUT
     12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     14  * version 2 for more details (a copy is included in the LICENSE file that
     15  * accompanied this code).
     16  *
     17  * You should have received a copy of the GNU General Public License version
     18  * 2 along with this work; if not, write to the Free Software Foundation,
     19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     20  *
     21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     22  * or visit www.oracle.com if you need additional information or have any
     23  * questions.
     24  */
     25
     26 package javax.smartcardio;
     27
     28 import java.util.Arrays;
     29
     30 import java.nio.ByteBuffer;
     31 import java.io.IOException;
     32
     33 /**
     34  * A command APDU following the structure defined in ISO/IEC 7816-4.
     35  * It consists of a four byte header and a conditional body of variable length.
     36  * This class does not attempt to verify that the APDU encodes a semantically
     37  * valid command.
     38  *
     39  * <p>Note that when the expected length of the response APDU is specified
     40  * in the {@linkplain #CommandAPDU(int,int,int,int,int) constructors},
     41  * the actual length (Ne) must be specified, not its
     42  * encoded form (Le). Similarly, {@linkplain #getNe} returns the actual
     43  * value Ne. In other words, a value of 0 means "no data in the response APDU"
     44  * rather than "maximum length."
     45  *
     46  * <p>This class supports both the short and extended forms of length
     47  * encoding for Ne and Nc. However, note that not all terminals and Smart Cards
     48  * are capable of accepting APDUs that use the extended form.
     49  *
     50  * <p>For the header bytes CLA, INS, P1, and P2 the Java type <code>int</code>
     51  * is used to represent the 8 bit unsigned values. In the constructors, only
    580     public boolean equals(Object obj) {
    581         if (this == obj) {
    582             return true;
    583         }
    584         if (obj instanceof CommandAPDU == false) {
    585             return false;
    586         }
    587         CommandAPDU other = (CommandAPDU)obj;
    588         return Arrays.equals(this.apdu, other.apdu);
    589      }
    590
    591     /**
    592      * Returns the hash code value for this command APDU.
    593      *
    594      * @return the hash code value for this command APDU.
    595      */
    596     public int hashCode() {
    597         return Arrays.hashCode(apdu);
    598     }
    599
    600
    601     /**
    602      * Restores the state of this object from the stream.
    603      *
    604      * @param  in the {@code ObjectInputStream} from which data is read
    605      * @throws IOException if an I/O error occurs
    606      * @throws ClassNotFoundException if a serialized class cannot be loaded
    607      */
    608     private void readObject(java.io.ObjectInputStream in)
    609             throws IOException, ClassNotFoundException {
    610         apdu = (byte[])in.readUnshared();
    611         // initialize transient fields
    612         parse();
    613     }
    614
    615 }

< prev index next >