Search in sources :

Example 36 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding3.

@Test
public void implicitEncoding3() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(0));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(2, length);
    byte[] expectedBytes = new byte[] { 0x01, 0x00 };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 37 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding7.

@Test
public void implicitEncoding7() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(-129));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(3, length);
    byte[] expectedBytes = new byte[] { 0x02, (byte) 0xff, (byte) 0x7f };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 38 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.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);
    Assert.assertEquals(4, length);
    byte[] expectedBytes = new byte[] { 0x02, 0x02, 0x15, (byte) 0xb3 };
    Assert.assertArrayEquals(expectedBytes, berStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 39 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding1.

@Test
public void implicitEncoding1() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    // 51 is the example in X.690
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(51));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(2, length);
    byte[] expectedBytes = new byte[] { 0x01, 0x33 };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 40 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding2.

@Test
public void implicitEncoding2() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(256));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(3, length);
    byte[] expectedBytes = new byte[] { 0x02, 0x01, 0x00 };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)44 Test (org.junit.Test)38 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerOctetString (org.openmuc.jasn1.ber.types.BerOctetString)4 BerUTF8String (org.openmuc.jasn1.ber.types.string.BerUTF8String)4 ProfileElement (org.openmuc.jasn1.compiler.pedefinitions.ProfileElement)4 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 BerNull (org.openmuc.jasn1.ber.types.BerNull)3 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 PEHeader (org.openmuc.jasn1.compiler.pedefinitions.PEHeader)2 UInt15 (org.openmuc.jasn1.compiler.pedefinitions.UInt15)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 ChildInformation (org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation)2 Date (org.openmuc.jasn1.compiler.x690_ber_example.Date)2 EmployeeNumber (org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber)2