Search in sources :

Example 1 with BerBoolean

use of org.openmuc.jasn1.ber.types.BerBoolean in project jasn1 by openmuc.

the class TaggingTest method explicitlyTaggedSequenceTest.

@Test
public void explicitlyTaggedSequenceTest() throws Exception {
    ExplicitlyTaggedSequence sequence = new ExplicitlyTaggedSequence();
    sequence.setMyInteger(new BerInteger(1));
    sequence.setMyBoolean(new BerBoolean(true));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    sequence.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210830060201010101FF"), os.getArray());
    sequence = new ExplicitlyTaggedSequence();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(sequence.getMyInteger());
    Assert.assertNotNull(sequence.getMyBoolean());
}
Also used : ExplicitlyTaggedSequence(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSequence) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 2 with BerBoolean

use of org.openmuc.jasn1.ber.types.BerBoolean in project jasn1 by openmuc.

the class BerBoolean method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int codeLength = 0;
    if (withTag) {
        codeLength += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    codeLength += length.decode(is);
    if (length.val != 1) {
        throw new IOException("Decoded length of BerBoolean is not correct");
    }
    int nextByte = is.read();
    if (nextByte == -1) {
        throw new EOFException("Unexpected end of input stream.");
    }
    codeLength++;
    if (nextByte == 0) {
        value = false;
    } else {
        value = true;
    }
    return codeLength;
}
Also used : BerLength(org.openmuc.jasn1.ber.BerLength) EOFException(java.io.EOFException) IOException(java.io.IOException)

Example 3 with BerBoolean

use of org.openmuc.jasn1.ber.types.BerBoolean in project jasn1 by openmuc.

the class TaggingTest method explicitlyTaggedSetTest.

@Test
public void explicitlyTaggedSetTest() throws Exception {
    ExplicitlyTaggedSet set = new ExplicitlyTaggedSet();
    set.setMyInteger(new BerInteger(1));
    set.setMyBoolean(new BerBoolean(true));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    set.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF210831060201010101FF"), os.getArray());
    set = new ExplicitlyTaggedSet();
    set.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertNotNull(set.getMyInteger());
    Assert.assertNotNull(set.getMyBoolean());
}
Also used : ExplicitlyTaggedSet(org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSet) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 4 with BerBoolean

use of org.openmuc.jasn1.ber.types.BerBoolean in project jasn1 by openmuc.

the class TaggingTest method sequenceOfDirectTypesTest.

@Test
public void sequenceOfDirectTypesTest() throws Exception {
    SequenceOfDirectTypes sequence = new SequenceOfDirectTypes();
    sequence.setUntaggedInt(new BerInteger(1));
    sequence.setExplicitlyTaggedInt(new BerInteger(2));
    sequence.setImplicitlyTaggedInt(new BerInteger(3));
    UntaggedChoice untaggedChoice = new UntaggedChoice();
    untaggedChoice.setMyBoolean(new BerBoolean(true));
    sequence.setUntaggedChoice(untaggedChoice);
    SequenceOfDirectTypes.TaggedChoice taggedChoice = new SequenceOfDirectTypes.TaggedChoice();
    taggedChoice.setMyInteger(new BerInteger(4));
    sequence.setTaggedChoice(taggedChoice);
    sequence.setTaggedAny(new BerAny(new byte[] { 2, 1, 1 }));
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(1000);
    sequence.encode(os);
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("BF2B18020101A1030201028201038401FFA503830104A603020101"), os.getArray());
    sequence = new SequenceOfDirectTypes();
    sequence.decode(new ByteArrayInputStream(os.getArray()));
    Assert.assertEquals(1, sequence.getUntaggedInt().value.intValue());
    Assert.assertEquals(2, sequence.getExplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(3, sequence.getImplicitlyTaggedInt().value.intValue());
    Assert.assertEquals(true, untaggedChoice.getMyBoolean().value);
    Assert.assertEquals(4, sequence.getTaggedChoice().getMyInteger().value.intValue());
    System.out.println(DatatypeConverter.printHexBinary(sequence.getTaggedAny().value));
    Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("020101"), sequence.getTaggedAny().value);
    Assert.assertNull(sequence.getUntaggedChoice2());
}
Also used : SequenceOfDirectTypes(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes) BerBoolean(org.openmuc.jasn1.ber.types.BerBoolean) UntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes.UntaggedChoice) RetaggedUntaggedChoice(org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice) TaggedChoice(org.openmuc.jasn1.compiler.tagging_test.TaggedChoice) ImplicitlyRetaggedTaggedChoice(org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice) ByteArrayInputStream(java.io.ByteArrayInputStream) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) BerAny(org.openmuc.jasn1.ber.types.BerAny) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.Test)3 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)3 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)3 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 BerLength (org.openmuc.jasn1.ber.BerLength)1 BerAny (org.openmuc.jasn1.ber.types.BerAny)1 ExplicitlyTaggedSequence (org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSequence)1 ExplicitlyTaggedSet (org.openmuc.jasn1.compiler.tagging_test.ExplicitlyTaggedSet)1 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)1 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)1 SequenceOfDirectTypes (org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes)1 UntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.SequenceOfDirectTypes.UntaggedChoice)1 TaggedChoice (org.openmuc.jasn1.compiler.tagging_test.TaggedChoice)1