add checkSW method

This commit is contained in:
Andrea Franz 2018-11-27 11:58:39 +01:00
parent 918aec72ac
commit 5a2204bbcb
No known key found for this signature in database
GPG Key ID: 4F0D2F2D9DE7F29D
1 changed files with 11 additions and 15 deletions

View File

@ -33,18 +33,18 @@ public class APDUResponse {
System.arraycopy(this.apdu, 0, this.data, 0, length - 2); System.arraycopy(this.apdu, 0, this.data, 0, length - 2);
} }
public boolean isOK() { public APDUResponse checkOK() throws APDUException {
return this.sw == SW_OK; this.checkSW(SW_OK);
return this;
} }
public APDUResponse checkOK(int... codes) throws APDUException { public APDUResponse checkSW(int... codes) throws APDUException {
for (int code : codes) { for (int code : codes) {
if (this.sw == code) { if (this.sw == code) {
return this; return this;
} }
} }
if (!isOK()) {
switch (this.sw) { switch (this.sw) {
case SW_SECURITY_CONDITION_NOT_SATISFIED: case SW_SECURITY_CONDITION_NOT_SATISFIED:
throw new APDUException(this.sw, "security condition not satisfied"); throw new APDUException(this.sw, "security condition not satisfied");
@ -53,10 +53,6 @@ public class APDUResponse {
default: default:
throw new APDUException(this.sw, "Unexpected error SW"); throw new APDUException(this.sw, "Unexpected error SW");
} }
}
return this;
} }
public byte[] getData() { public byte[] getData() {