Search in sources :

Example 26 with BerTag

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

the class SubjectDirectoryAttributes method decode.

public int decode(InputStream is, boolean withTag) throws IOException {
    int codeLength = 0;
    int subCodeLength = 0;
    BerTag berTag = new BerTag();
    if (withTag) {
        codeLength += tag.decodeAndCheck(is);
    }
    BerLength length = new BerLength();
    codeLength += length.decode(is);
    int totalLength = length.val;
    if (length.val == -1) {
        while (true) {
            subCodeLength += berTag.decode(is);
            if (berTag.tagNumber == 0 && berTag.tagClass == 0 && berTag.primitive == 0) {
                int nextByte = is.read();
                if (nextByte != 0) {
                    if (nextByte == -1) {
                        throw new EOFException("Unexpected end of input stream.");
                    }
                    throw new IOException("Decoded sequence has wrong end of contents octets");
                }
                codeLength += subCodeLength + 1;
                return codeLength;
            }
            Attribute element = new Attribute();
            subCodeLength += element.decode(is, false);
            seqOf.add(element);
        }
    }
    while (subCodeLength < totalLength) {
        Attribute element = new Attribute();
        subCodeLength += element.decode(is, true);
        seqOf.add(element);
    }
    if (subCodeLength != totalLength) {
        throw new IOException("Decoded SequenceOf or SetOf has wrong length. Expected " + totalLength + " but has " + subCodeLength);
    }
    codeLength += subCodeLength;
    return codeLength;
}
Also used : Attribute(org.openmuc.jasn1.compiler.pkix1explicit88.Attribute) EOFException(java.io.EOFException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)14 BerTag (org.openmuc.jasn1.ber.BerTag)12 AsnBitString (org.openmuc.jasn1.compiler.model.AsnBitString)11 AsnCharacterString (org.openmuc.jasn1.compiler.model.AsnCharacterString)11 AsnOctetString (org.openmuc.jasn1.compiler.model.AsnOctetString)11 EOFException (java.io.EOFException)10 AsnTag (org.openmuc.jasn1.compiler.model.AsnTag)9 AsnElementType (org.openmuc.jasn1.compiler.model.AsnElementType)8 Certificate (org.openmuc.jasn1.compiler.pkix1explicit88.Certificate)5 BerLength (org.openmuc.jasn1.ber.BerLength)2 AsnConstructedType (org.openmuc.jasn1.compiler.model.AsnConstructedType)2 AsnParameter (org.openmuc.jasn1.compiler.model.AsnParameter)2 RelativeDistinguishedName (org.openmuc.jasn1.compiler.pkix1explicit88.RelativeDistinguishedName)2 SubjectKeyIdentifier (org.openmuc.jasn1.compiler.pkix1implicit88.SubjectKeyIdentifier)2 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)1 BerObjectDescriptor (org.openmuc.jasn1.ber.types.string.BerObjectDescriptor)1 EmployeeNumberZ (org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ)1 Attribute (org.openmuc.jasn1.compiler.pkix1explicit88.Attribute)1 CertificateList (org.openmuc.jasn1.compiler.pkix1explicit88.CertificateList)1 CertificateSerialNumber (org.openmuc.jasn1.compiler.pkix1explicit88.CertificateSerialNumber)1