use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream 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.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerObjectIdentifierTest method explicitEncoding.
@Test
public void explicitEncoding() throws IOException {
ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
BerObjectIdentifier oi = new BerObjectIdentifier(objectIdentifierComponents);
int length = oi.encode(berBAOStream, true);
Assert.assertEquals(7, length);
Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerOctetStringTest method explicitEncoding.
@Test
public void explicitEncoding() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
byte[] byteArray = new byte[] { 0x01, 0x02, 0x03 };
BerOctetString asn1OctetString = new BerOctetString(byteArray);
int length = asn1OctetString.encode(berStream, true);
Assert.assertEquals(5, length);
byte[] expectedBytes = new byte[] { 0x04, 0x03, 0x01, 0x02, 0x03 };
Assert.assertArrayEquals(expectedBytes, berStream.getArray());
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerRealTest method codingNegInf.
@Test
public void codingNegInf() throws IOException {
ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
BerReal berReal = new BerReal(Double.NEGATIVE_INFINITY);
berReal.encode(berStream, true);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090141"), berStream.getArray());
ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
BerReal berRealDecoded = new BerReal();
berRealDecoded.decode(berInputStream, true);
Assert.assertEquals(Double.NEGATIVE_INFINITY, berRealDecoded.value, 0.01);
}
use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.
the class BerRealTest method coding0dot7.
@Test
public void coding0dot7() throws IOException {
final BerReal orig = new BerReal(0.7);
final ReverseByteArrayOutputStream baos = new ReverseByteArrayOutputStream(100, true);
orig.encode(baos, true);
// System.out.println(DatatypeConverter.printHexBinary(baos.getArray()));
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("090980CC0B333333333333"), baos.getArray());
final BerReal decoded = new BerReal();
decoded.decode(new ByteArrayInputStream(baos.getArray()), true);
Assert.assertEquals(orig.value, decoded.value, 0.001);
}
Aggregations