Search in sources :

Example 41 with ReverseByteArrayOutputStream

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

the class BerIntegerTest method implicitEncoding5.

@Test
public void implicitEncoding5() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(128));
    int length = testInteger.encode(berBAOStream, false);
    assertEquals(3, length);
    byte[] expectedBytes = new byte[] { 0x02, 0x00, (byte) 0x80 };
    assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 42 with ReverseByteArrayOutputStream

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

the class BerIntegerTest method explicitEncoding2.

@Test
public void explicitEncoding2() throws IOException {
    ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
    BerInteger testInteger = new BerInteger(BigInteger.valueOf(5555));
    int length = testInteger.encode(berStream, true);
    assertEquals(4, length);
    byte[] expectedBytes = new byte[] { 0x02, 0x02, 0x15, (byte) 0xb3 };
    assertArrayEquals(expectedBytes, berStream.getArray());
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 43 with ReverseByteArrayOutputStream

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

the class BerGeneralizedTimeTest method explicitEncoding.

@Test
public void explicitEncoding() throws IOException {
    ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
    byte[] byteArray = new byte[] { 0x01, 0x02, 0x03 };
    BerGeneralizedTime berGeneralizedTime = new BerGeneralizedTime(byteArray);
    int length = berGeneralizedTime.encode(berStream, true);
    assertEquals(5, length);
    byte[] expectedBytes = new byte[] { 24, 0x03, 0x01, 0x02, 0x03 };
    assertArrayEquals(expectedBytes, berStream.getArray());
}
Also used : ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 44 with ReverseByteArrayOutputStream

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

the class BerReal method encodeAndSave.

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

Example 45 with ReverseByteArrayOutputStream

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

the class BerRealTest method coding1dot5.

@Test
public void coding1dot5() throws IOException {
    ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50);
    BerReal berReal = new BerReal(1.5);
    berReal.encode(berStream, true);
    // System.out.println(DatatypeConverter.printHexBinary(berStream.getArray()));
    assertArrayEquals(HexString.toBytes("090380FF03"), berStream.getArray());
    ByteArrayInputStream berInputStream = new ByteArrayInputStream(berStream.getArray());
    BerReal berRealDecoded = new BerReal();
    berRealDecoded.decode(berInputStream, true);
    assertEquals(1.5, berRealDecoded.value, 0.01);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

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