Path: blob/master/test/jdk/javax/smartcardio/HistoricalBytes.java
41144 views
/*1* Copyright (c) 2006, 2017, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 644536726* @summary Verify that ATR.getHistoricalBytes() works27* @author Andreas Sterbenz28*/2930import java.util.Arrays;3132import javax.smartcardio.*;3334public class HistoricalBytes {3536public static String toString(byte[] b) {37return Serialize.toString(b);38}3940public static byte[] parse(String s) {41return Serialize.parse(s);42}4344// generated using ATR_analysis from pcsc-tools4546private final static String[] ATRS = {47"3B 7F 18 00 00 00 31 C0 73 9E 01 0B 64 52 D9 04 00 82 90 00",48"3B 65 00 00 9C 02 02 07 02",49"3B 95 18 40 FF 62 01 02 01 04",50"3B 86 40 20 68 01 01 02 04 AC",51"3B 9F 96 80 1F C3 80 31 E0 73 FE 21 1B B3 E2 02 7E 83 0F 90 00 82",52"3B FF 13 00 FF 81 31 FE 5D 80 25 A0 00 00 00 56 57 44 4B 33 32 30 05 00 3F",53"3F 6D 00 00 80 31 80 65 B0 05 01 02 5E 83 00 90 00",54"3F 65 35 64 02 04 6C 90 40",55"3B 9F 96 80 1F C3 80 31 E0 73 FE 21 1B B3 E2 02 7E 83 0F 90 00 82 11",56"3F 65 35 64 02 04 6C 90 40 55 55", // invalid57};5859private final static String[] HIST = {60"00 31 C0 73 9E 01 0B 64 52 D9 04 00 82 90 00",61"9C 02 02 07 02",62"62 01 02 01 04",63"68 01 01 02 04 AC",64"80 31 E0 73 FE 21 1B B3 E2 02 7E 83 0F 90 00",65"80 25 A0 00 00 00 56 57 44 4B 33 32 30 05 00",66"80 31 80 65 B0 05 01 02 5E 83 00 90 00",67"02 04 6C 90 40",68"",69"",70};7172public static void main(String[] args) throws Exception {73for (int i = 0; i < ATRS.length; i++) {74ATR atr = new ATR(parse(ATRS[i]));75byte[] hist = parse(HIST[i]);76byte[] b = atr.getHistoricalBytes();77if (!Arrays.equals(b, hist)) {78throw new Exception("mismatch: " + toString(b) + " != " + toString(hist));79}80}81System.out.println("OK");82}8384}858687