From 58ebbe700d922af33b79886f715ee302fb62c523 Mon Sep 17 00:00:00 2001 From: clemenso Date: Fri, 28 Jan 2011 17:22:04 +0000 Subject: Read PuK_QS (secure messaging case1b/2) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@896 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../src/main/java/at/gv/egiz/smcc/util/TLV.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'smccTest/src/main/java/at/gv/egiz/smcc/util/TLV.java') diff --git a/smccTest/src/main/java/at/gv/egiz/smcc/util/TLV.java b/smccTest/src/main/java/at/gv/egiz/smcc/util/TLV.java index b67fe3fa..a724b4b5 100644 --- a/smccTest/src/main/java/at/gv/egiz/smcc/util/TLV.java +++ b/smccTest/src/main/java/at/gv/egiz/smcc/util/TLV.java @@ -39,11 +39,28 @@ public class TLV { return 0xFF & bytes[start]; } + public int getLengthFieldLength() { + if ((bytes[start + 1] & 0x80) > 0) { + // ISO 7816 allows length fields of up to 5 bytes + return 1 + (bytes[start + 1] & 0x07); + } + return 1; + } + /** * @return the length */ public int getLength() { - return 0xFF & bytes[start + 1]; + + if ((bytes[start + 1] & 0x80) > 0) { + int length = 0; + for (int i = 0; i < (bytes[start + 1] & 0x07); i++) { + length <<= 8; + length += bytes[start + 2 + i] & 0xff; + } + return length; + } + return bytes[start + 1] & 0x7f; } /** @@ -51,7 +68,7 @@ public class TLV { */ public byte[] getValue() { byte[] value = new byte[getLength()]; - System.arraycopy(bytes, start + 2, value, 0, value.length); + System.arraycopy(bytes, start + 1 + getLengthFieldLength(), value, 0, value.length); return value; } @@ -78,7 +95,7 @@ public class TLV { sb.append(']'); return sb.toString(); } + - } -- cgit v1.2.3