All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.asn1.BERBitStringParser Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8. Note: this package includes the NTRU encryption algorithms.

The newest version!
package org.bouncycastle.asn1;

import java.io.IOException;
import java.io.InputStream;

import org.bouncycastle.util.io.Streams;

/**
 * A parser for indefinite-length BIT STRINGs.
 */
public class BERBitStringParser
    implements ASN1BitStringParser
{
    private ASN1StreamParser _parser;

    private ConstructedBitStream _bitStream;

    BERBitStringParser(
        ASN1StreamParser parser)
    {
        _parser = parser;
    }

    public InputStream getOctetStream() throws IOException
    {
        return _bitStream = new ConstructedBitStream(_parser, true);
    }

    public InputStream getBitStream() throws IOException
    {
        return _bitStream = new ConstructedBitStream(_parser, false);
    }

    public int getPadBits()
    {
        return _bitStream.getPadBits();
    }

    public ASN1Primitive getLoadedObject()
        throws IOException
    {
        return parse(_parser);
    }

    public ASN1Primitive toASN1Primitive()
    {
        try
        {
            return getLoadedObject();
        }
        catch (IOException e)
        {
            throw new ASN1ParsingException("IOException converting stream to byte array: " + e.getMessage(), e);
        }
    }

    static BERBitString parse(ASN1StreamParser sp) throws IOException
    {
        ConstructedBitStream bitStream = new ConstructedBitStream(sp, false);
        byte[] data = Streams.readAll(bitStream);
        int padBits = bitStream.getPadBits();
        return new BERBitString(data, padBits);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy