use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.
the class BerIntegerTest method encodeDecodeLargeLongs.
@Test
public void encodeDecodeLargeLongs() throws IOException {
ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50);
BerInteger myInt = new BerInteger(BigInteger.valueOf(20093243433l));
myInt.encode(os, true);
ByteArrayInputStream berInputStream = new ByteArrayInputStream(os.getArray());
BerInteger myInt2 = new BerInteger();
myInt2.decode(berInputStream, true);
Assert.assertEquals(20093243433l, myInt2.value.longValue());
}
use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.
the class BerIntegerTest method encodeDecodeLargeNegativeLongs.
@Test
public void encodeDecodeLargeNegativeLongs() throws IOException {
ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
BerInteger myInt = new BerInteger(BigInteger.valueOf(-20093243433l));
myInt.encode(berBAOStream, true);
ByteArrayInputStream berInputStream = new ByteArrayInputStream(berBAOStream.getArray());
BerInteger myInt2 = new BerInteger();
myInt2.decode(berInputStream, true);
Assert.assertEquals(-20093243433l, myInt2.value.longValue());
}
use of org.openmuc.jasn1.ber.types.BerInteger in project jasn1 by openmuc.
the class BerIntegerTest method explicitEncoding.
@Test
public void explicitEncoding() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
// 51 is the example in X.690
BerInteger testInteger = new BerInteger(BigInteger.valueOf(51));
int length = testInteger.encode(berStream, true);
Assert.assertEquals(3, length);
byte[] expectedBytes = new byte[] { 0x02, 0x01, 0x33 };
Assert.assertArrayEquals(expectedBytes, berStream.getArray());
}
use of org.openmuc.jasn1.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);
System.out.println("seqOf : " + DatatypeConverter.printHexBinary(os.getArray()));
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF21083006020103020104"), os.getArray());
seqOf = new ExplicitlyTaggedSeqOf();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
use of org.openmuc.jasn1.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);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("300AA303020103A303020104"), os.getArray());
seqOf = new SeqOfExplicitlyTaggedType();
seqOf.decode(new ByteArrayInputStream(os.getArray()));
}
Aggregations