use of com.beanit.asn1bean.ber.types.BerInteger in project sandbox-java by stIncMale.
the class InAppAttribute method decode.
public int decode(InputStream is, boolean withTag) throws IOException {
int tlByteCount = 0;
int vByteCount = 0;
BerTag berTag = new BerTag();
if (withTag) {
tlByteCount += tag.decodeAndCheck(is);
}
BerLength length = new BerLength();
tlByteCount += length.decode(is);
int lengthVal = length.val;
vByteCount += berTag.decode(is);
if (berTag.equals(BerInteger.tag)) {
type = new BerInteger();
vByteCount += type.decode(is, false);
vByteCount += berTag.decode(is);
} else {
throw new IOException("Tag does not match mandatory sequence component.");
}
if (berTag.equals(BerInteger.tag)) {
version = new BerInteger();
vByteCount += version.decode(is, false);
vByteCount += berTag.decode(is);
} else {
throw new IOException("Tag does not match mandatory sequence component.");
}
if (berTag.equals(BerOctetString.tag)) {
value = new BerOctetString();
vByteCount += value.decode(is, false);
if (lengthVal >= 0 && vByteCount == lengthVal) {
return tlByteCount + vByteCount;
}
vByteCount += berTag.decode(is);
} else {
throw new IOException("Tag does not match mandatory sequence component.");
}
if (lengthVal < 0) {
if (!berTag.equals(0, 0, 0)) {
throw new IOException("Decoded sequence has wrong end of contents octets");
}
vByteCount += BerLength.readEocByte(is);
return tlByteCount + vByteCount;
}
throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method implicitlyRetaggedTaggedChoiceTest.
@Test
public void implicitlyRetaggedTaggedChoiceTest() throws Exception {
ImplicitlyRetaggedTaggedChoice choice = new ImplicitlyRetaggedTaggedChoice();
choice.setMyInteger(new BerInteger(1));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
choice.encode(os);
assertArrayEquals(toBytes("A305A403020101"), os.getArray());
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method seqOfExplicitlyTaggedTypeTest.
@Test
public void seqOfExplicitlyTaggedTypeTest() throws Exception {
SeqOfExplicitlyTaggedType seqOf = new SeqOfExplicitlyTaggedType();
List<BerInteger> integerList = seqOf.getBerInteger();
integerList.add(new BerInteger(3));
integerList.add(new BerInteger(4));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
seqOf.encode(os);
assertArrayEquals(toBytes("300AA303020103A303020104"), os.getArray());
seqOf = new SeqOfExplicitlyTaggedType();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method retaggedChoiceTest.
@Test
public void retaggedChoiceTest() throws Exception {
RetaggedUntaggedChoice choice = new RetaggedUntaggedChoice();
choice.setMyInteger(new BerInteger(1));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
choice.encode(os);
assertArrayEquals(toBytes("BF2103830101"), os.getArray());
choice = new RetaggedUntaggedChoice();
choice.decode(new ByteArrayInputStream(os.getArray()));
assertNotNull(choice.getMyInteger());
assertNull(choice.getMyBoolean());
}
use of com.beanit.asn1bean.ber.types.BerInteger in project jasn1 by openmuc.
the class TaggingTest method explicitlyTaggedSeqOfTest.
@Test
public void explicitlyTaggedSeqOfTest() throws Exception {
ExplicitlyTaggedSeqOf seqOf = new ExplicitlyTaggedSeqOf();
List<BerInteger> integerList = seqOf.getBerInteger();
integerList.add(new BerInteger(3));
integerList.add(new BerInteger(4));
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
seqOf.encode(os);
assertArrayEquals(toBytes("BF21083006020103020104"), os.getArray());
seqOf = new ExplicitlyTaggedSeqOf();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
Aggregations