Search in sources :

Example 1 with BerOctetString

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

the class InAppAttribute method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int tlByteCount = 0;
    int vByteCount = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        tlByteCount += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    tlByteCount += length.decode(is);
    int lengthVal = length.val;
    vByteCount += berTag.decode(is);
    if (berTag.equals(BerInteger.tag)) {
        type = new BerInteger();
        vByteCount += type.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerInteger.tag)) {
        version = new BerInteger();
        vByteCount += version.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerOctetString.tag)) {
        value = new BerOctetString();
        vByteCount += value.decode(is, false);
        if (lengthVal >= 0 && vByteCount == lengthVal) {
            return tlByteCount + vByteCount;
        }
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (lengthVal < 0) {
        if (!berTag.equals(0, 0, 0)) {
            throw new IOException("Decoded sequence has wrong end of contents octets");
        }
        vByteCount += BerLength.readEocByte(is);
        return tlByteCount + vByteCount;
    }
    throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) IOException(java.io.IOException) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) BerTag(com.beanit.asn1bean.ber.BerTag)

Example 2 with BerOctetString

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

the class MobileTest method header.

@Test
public void header() throws Exception {
    ProfileElement headerProfileElement = new ProfileElement();
    ServicesList servicesList = new ServicesList();
    ProfileHeader.EUICCMandatoryGFSTEList GFSTEList = new ProfileHeader.EUICCMandatoryGFSTEList();
    GFSTEList.seqOf = Arrays.asList(new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 1 }), new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 4 }));
    servicesList.usim = new BerNull();
    servicesList.milenage = new BerNull();
    servicesList.javacard = new BerNull();
    headerProfileElement.header = new ProfileHeader(new UInt8(2), new UInt8(0), new BerUTF8String("SIMalliance Sample Profile"), new BerOctetString(HexString.toBytes("89019990001234567893")), null, servicesList, GFSTEList, null, null);
    ReverseByteArrayOutputStream reverseByteArrayOutputStream = new ReverseByteArrayOutputStream(2048, true);
    headerProfileElement.encode(reverseByteArrayOutputStream);
    byte[] code = reverseByteArrayOutputStream.getArray();
    ProfileElement rereadProfileElement = new ProfileElement();
    rereadProfileElement.decode(new ByteArrayInputStream(code), null);
    ReverseByteArrayOutputStream reverseOutputStream2 = new ReverseByteArrayOutputStream(2048, true);
    rereadProfileElement.encode(reverseOutputStream2);
    byte[] code2 = reverseOutputStream2.getArray();
    assertArrayEquals(code, code2);
    String expected = "A0 48 80 01 02 81 01 00 82 1A 53494D616C6C69616E63652053616D706C652050726F66696C65 83 0A 89019990001234567893 A5 06 81 00 84 00 8B 00 A6 10 06 06 67810F010201 06 06 67810F010204".replaceAll("\\s", "");
    assertEquals(expected, HexString.fromBytes(code));
}
Also used : BerObjectIdentifier(com.beanit.asn1bean.ber.types.BerObjectIdentifier) BerUTF8String(com.beanit.asn1bean.ber.types.string.BerUTF8String) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) BerUTF8String(com.beanit.asn1bean.ber.types.string.BerUTF8String) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) HexString(com.beanit.asn1bean.util.HexString) ProfileElement(com.beanit.asn1bean.compiler.pedefinitions.ProfileElement) UInt8(com.beanit.asn1bean.compiler.pedefinitions.UInt8) ProfileHeader(com.beanit.asn1bean.compiler.pedefinitions.ProfileHeader) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) ServicesList(com.beanit.asn1bean.compiler.pedefinitions.ServicesList) ByteArrayInputStream(java.io.ByteArrayInputStream) BerNull(com.beanit.asn1bean.ber.types.BerNull) Test(org.junit.jupiter.api.Test)

Example 3 with BerOctetString

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

the class ReceiptAttribute method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int tlByteCount = 0;
    int vByteCount = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        tlByteCount += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    tlByteCount += length.decode(is);
    int lengthVal = length.val;
    vByteCount += berTag.decode(is);
    if (berTag.equals(BerInteger.tag)) {
        type = new BerInteger();
        vByteCount += type.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerInteger.tag)) {
        version = new BerInteger();
        vByteCount += version.decode(is, false);
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (berTag.equals(BerOctetString.tag)) {
        value = new BerOctetString();
        vByteCount += value.decode(is, false);
        if (lengthVal >= 0 && vByteCount == lengthVal) {
            return tlByteCount + vByteCount;
        }
        vByteCount += berTag.decode(is);
    } else {
        throw new IOException("Tag does not match mandatory sequence component.");
    }
    if (lengthVal < 0) {
        if (!berTag.equals(0, 0, 0)) {
            throw new IOException("Decoded sequence has wrong end of contents octets");
        }
        vByteCount += BerLength.readEocByte(is);
        return tlByteCount + vByteCount;
    }
    throw new IOException("Unexpected end of sequence, length tag: " + lengthVal + ", bytes decoded: " + vByteCount);
}
Also used : BerLength(com.beanit.asn1bean.ber.BerLength) BerOctetString(com.beanit.asn1bean.ber.types.BerOctetString) IOException(java.io.IOException) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) BerTag(com.beanit.asn1bean.ber.BerTag)

Aggregations

BerOctetString (com.beanit.asn1bean.ber.types.BerOctetString)3 BerLength (com.beanit.asn1bean.ber.BerLength)2 BerTag (com.beanit.asn1bean.ber.BerTag)2 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)2 IOException (java.io.IOException)2 ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)1 BerNull (com.beanit.asn1bean.ber.types.BerNull)1 BerObjectIdentifier (com.beanit.asn1bean.ber.types.BerObjectIdentifier)1 BerUTF8String (com.beanit.asn1bean.ber.types.string.BerUTF8String)1 ProfileElement (com.beanit.asn1bean.compiler.pedefinitions.ProfileElement)1 ProfileHeader (com.beanit.asn1bean.compiler.pedefinitions.ProfileHeader)1 ServicesList (com.beanit.asn1bean.compiler.pedefinitions.ServicesList)1 UInt8 (com.beanit.asn1bean.compiler.pedefinitions.UInt8)1 HexString (com.beanit.asn1bean.util.HexString)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.jupiter.api.Test)1