use of com.beanit.asn1bean.ber.BerLength in project jasn1 by openmuc.
the class BerObjectIdentifier method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
if (length.val == 0) {
value = new int[0];
return codeLength;
}
byte[] byteCode = new byte[length.val];
Util.readFully(is, byteCode);
codeLength += length.val;
List<Integer> objectIdentifierComponentsList = new ArrayList<>();
int subIDEndIndex = 0;
while ((byteCode[subIDEndIndex] & 0x80) == 0x80) {
if (subIDEndIndex >= (length.val - 1)) {
throw new IOException("Invalid Object Identifier");
}
subIDEndIndex++;
}
int subidentifier = 0;
for (int i = 0; i <= subIDEndIndex; i++) {
subidentifier |= ((byteCode[i] & 0x7f) << ((subIDEndIndex - i) * 7));
}
if (subidentifier < 40) {
objectIdentifierComponentsList.add(0);
objectIdentifierComponentsList.add(subidentifier);
} else if (subidentifier < 80) {
objectIdentifierComponentsList.add(1);
objectIdentifierComponentsList.add(subidentifier - 40);
} else {
objectIdentifierComponentsList.add(2);
objectIdentifierComponentsList.add(subidentifier - 80);
}
subIDEndIndex++;
while (subIDEndIndex < length.val) {
int subIDStartIndex = subIDEndIndex;
while ((byteCode[subIDEndIndex] & 0x80) == 0x80) {
if (subIDEndIndex == (length.val - 1)) {
throw new IOException("Invalid Object Identifier");
}
subIDEndIndex++;
}
subidentifier = 0;
for (int j = subIDStartIndex; j <= subIDEndIndex; j++) {
subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7));
}
objectIdentifierComponentsList.add(subidentifier);
subIDEndIndex++;
}
value = new int[objectIdentifierComponentsList.size()];
for (int i = 0; i < objectIdentifierComponentsList.size(); i++) {
value[i] = objectIdentifierComponentsList.get(i);
}
return codeLength;
}
use of com.beanit.asn1bean.ber.BerLength in project jasn1 by openmuc.
the class BerVisibleString method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
value = new byte[length.val];
if (length.val != 0) {
Util.readFully(is, value);
codeLength += length.val;
}
return codeLength;
}
use of com.beanit.asn1bean.ber.BerLength in project jasn1 by openmuc.
the class BerBoolean method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
if (length.val != 1) {
throw new IOException("Decoded length of BerBoolean is not correct");
}
int nextByte = is.read();
if (nextByte == -1) {
throw new EOFException("Unexpected end of input stream.");
}
codeLength++;
value = nextByte != 0;
return codeLength;
}
use of com.beanit.asn1bean.ber.BerLength in project jasn1 by openmuc.
the class BerNull method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int codeLength = 0;
if (withTag) {
codeLength += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
codeLength += length.decode(is);
if (length.val != 0) {
throw new IOException("Decoded length of BerNull is not correct");
}
return codeLength;
}
use of com.beanit.asn1bean.ber.BerLength in project jasn1 by openmuc.
the class BerOctetString method decodePrimitiveOctetString.
private int decodePrimitiveOctetString(InputStream is) throws IOException {
int codeLength = 0;
BerLength length = new BerLength();
codeLength += length.decode(is);
value = new byte[length.val];
if (length.val != 0) {
Util.readFully(is, value);
codeLength += length.val;
}
return codeLength;
}
Aggregations