Search in sources :

Example 46 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerRealTest method codingZero.

@Test
public void codingZero() throws IOException {
    ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
    BerReal berReal = new BerReal(0);
    berReal.encode(berStream, true);
    assertArrayEquals(HexString.toBytes("0900"), berStream.getArray());
    ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
    BerReal berRealDecoded = new BerReal();
    berRealDecoded.decode(berInputStream, true);
    assertEquals(0, berRealDecoded.value, 0.01);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 47 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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()));
    assertArrayEquals(HexString.toBytes("090980CC0B333333333333"), baos.getArray());
    final BerReal decoded = new BerReal();
    decoded.decode(new ByteArrayInputStream(baos.getArray()), true);
    assertEquals(orig.value, decoded.value, 0.001);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 48 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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);
    assertArrayEquals(HexString.toBytes("090141"), berStream.getArray());
    ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
    BerReal berRealDecoded = new BerReal();
    berRealDecoded.decode(berInputStream, true);
    assertEquals(Double.NEGATIVE_INFINITY, berRealDecoded.value, 0.01);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 49 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.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);
    assertEquals(5, length);
    byte[] expectedBytes = new byte[] { 0x04, 0x03, 0x01, 0x02, 0x03 };
    assertArrayEquals(expectedBytes, berStream.getArray());
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 50 with ReverseByteArrayOutputStream

use of com.beanit.asn1bean.ber.ReverseByteArrayOutputStream in project sandbox-java by stIncMale.

the class InAppAttribute method encodeAndSave.

public void encodeAndSave(int encodingSizeGuess) throws IOException {
    ReverseByteArrayOutputStream reverseOS = new ReverseByteArrayOutputStream(encodingSizeGuess);
    encode(reverseOS, false);
    code = reverseOS.getArray();
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)

Aggregations

ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)51 Test (org.junit.jupiter.api.Test)41 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)14 BerVisibleString (com.beanit.asn1bean.ber.types.string.BerVisibleString)5 HexString (com.beanit.asn1bean.util.HexString)5 BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)4 BerUTF8String (com.beanit.asn1bean.ber.types.string.BerUTF8String)4 ProfileElement (com.beanit.asn1bean.compiler.pedefinitions.ProfileElement)4 BerAny (com.beanit.asn1bean.ber.types.BerAny)3 BerBoolean (com.beanit.asn1bean.ber.types.BerBoolean)3 BerNull (com.beanit.asn1bean.ber.types.BerNull)3 ImplicitlyRetaggedTaggedChoice (com.beanit.asn1bean.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 NonExtensibleSequence (com.beanit.asn1bean.compiler.extension_test.non_extensible.NonExtensibleSequence)2 PEHeader (com.beanit.asn1bean.compiler.pedefinitions.PEHeader)2 UInt15 (com.beanit.asn1bean.compiler.pedefinitions.UInt15)2 ArrayList (java.util.ArrayList)2 BerEmbeddedPdv (com.beanit.asn1bean.ber.types.BerEmbeddedPdv)1 BerObjectIdentifier (com.beanit.asn1bean.ber.types.BerObjectIdentifier)1 ExtensibleAccessSequence (com.beanit.asn1bean.compiler.extension_test.extensible_with_access.ExtensibleAccessSequence)1