Code with Finding: |
class BERTLVObject {
private void readValue(DataInputStream in) throws IOException {
valueBytes = new byte[length];
in.readFully(valueBytes);
if (isPrimitive) {
/*
* Primitive, the value consists of 0 or more Simple-TLV objects,
* or just (application-dependent) bytes. If tag is not known
* (or universal) we assume the value is just bytes.
*/
if (tagClass == UNIVERSAL_CLASS)
switch (tag[0]) {
case INTEGER_TYPE_TAG: value = valueBytes; break;
case BIT_STRING_TYPE_TAG: value = valueBytes; break;
case OCTET_STRING_TYPE_TAG: value = valueBytes; break;
case NULL_TYPE_TAG: value = null; break;
case OBJECT_IDENTIFIER_TYPE_TAG: value = valueBytes; break;
case UTF8_STRING_TYPE_TAG:
case PRINTABLE_STRING_TYPE_TAG:
case T61_STRING_TYPE_TAG:
case IA5_STRING_TYPE_TAG:
case VISIBLE_STRING_TYPE_TAG:
case GENERAL_STRING_TYPE_TAG:
case UNIVERSAL_STRING_TYPE_TAG:
case BMP_STRING_TYPE_TAG: value = new String(valueBytes); break;
case UTC_TIME_TYPE_TAG: value = parseUTCTime(new String(valueBytes)); break;
default: value = valueBytes;
} else {
value = valueBytes;
}
} else {
/*
* Not primitive, the value itself consists of 0 or more
* BER-TLV objects.
*/
in = new DataInputStream(new ByteArrayInputStream(valueBytes));
value = readSubObjects(in);
}
}
}
|