1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /* 17 * Copyright (c) 2017, The Linux Foundation. 18 */ 19 20 /* 21 * Copyright 2010 Giesecke & Devrient GmbH. 22 * 23 * Licensed under the Apache License, Version 2.0 (the "License"); 24 * you may not use this file except in compliance with the License. 25 * You may obtain a copy of the License at 26 * 27 * http://www.apache.org/licenses/LICENSE-2.0 28 * 29 * Unless required by applicable law or agreed to in writing, software 30 * distributed under the License is distributed on an "AS IS" BASIS, 31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 32 * See the License for the specific language governing permissions and 33 * limitations under the License. 34 */ 35 36 package com.android.se.security; 37 38 /** Represents the Response received from the Secure Element */ 39 public class ResponseApdu { 40 41 protected int mSw1 = 0x00; 42 protected int mSw2 = 0x00; 43 protected byte[] mData = new byte[0]; 44 ResponseApdu(byte[] respApdu)45 public ResponseApdu(byte[] respApdu) { 46 if (respApdu.length < 2) { 47 return; 48 } 49 if (respApdu.length > 2) { 50 mData = new byte[respApdu.length - 2]; 51 System.arraycopy(respApdu, 0, mData, 0, respApdu.length - 2); 52 } 53 mSw1 = 0x00FF & respApdu[respApdu.length - 2]; 54 mSw2 = 0x00FF & respApdu[respApdu.length - 1]; 55 } 56 getSW1()57 public int getSW1() { 58 return mSw1; 59 } 60 getSW2()61 public int getSW2() { 62 return mSw2; 63 } 64 getSW1SW2()65 public int getSW1SW2() { 66 return (mSw1 << 8) | mSw2; 67 } 68 getData()69 public byte[] getData() { 70 return mData; 71 } 72 73 /** Returns true if the Status Words are equal */ isStatus(int sw1sw2)74 public boolean isStatus(int sw1sw2) { 75 return (getSW1SW2() == sw1sw2); 76 } 77 } 78