Search in sources :

Example 6 with BerInteger

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 7 with BerInteger

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 8 with BerInteger

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());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 9 with BerInteger

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()));
}
Also used : ExplicitlyTaggedSeqOf(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSeqOf) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 10 with BerInteger

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()));
}
Also used : SeqOfExplicitlyTaggedType(org.openmuc.jasn1.compiler.tagging_test.SeqOfExplicitlyTaggedType) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 TaggedChoice (org.openmuc.jasn1.compiler.tagging_test.TaggedChoice)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 BerLength (org.openmuc.jasn1.ber.BerLength)1 BerEmbeddedPdv (org.openmuc.jasn1.ber.types.BerEmbeddedPdv)1 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)1 AbstractSyntaxName (org.openmuc.jasn1.compiler.iso8823_presentation.AbstractSyntaxName)1 CPType (org.openmuc.jasn1.compiler.iso8823_presentation.CPType)1 CalledPresentationSelector (org.openmuc.jasn1.compiler.iso8823_presentation.CalledPresentationSelector)1 CallingPresentationSelector (org.openmuc.jasn1.compiler.iso8823_presentation.CallingPresentationSelector)1