Java 类org.bouncycastle.asn1.BEROctetStringGenerator 实例源码

项目:ipack    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:gwt-crypto    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:Aki-SSL    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:irma_future_id    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:irma_future_id    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:irma_future_id    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:irma_future_id    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:irma_future_id    文件:OctetStringTest.java   
public void testReadingWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);

   OutputStream out = octGen.getOctetOutputStream();

   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[4]);

   out.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();

   InputStream in = s.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(8, count);
}
项目:irma_future_id    文件:OctetStringTest.java   
public void testReadingWritingZeroInLength()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);

   OutputStream out = octGen.getOctetOutputStream();

   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[512]);  // forces a zero to appear in length

   out.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();

   InputStream in = s.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(516, count);
}
项目:bc-java    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:bc-java    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:bc-java    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:bc-java    文件:CMSUtils.java   
static OutputStream createBEROctetOutputStream(OutputStream s,
        int tagNo, boolean isExplicit, int bufferSize) throws IOException
{
    BEROctetStringGenerator octGen = new BEROctetStringGenerator(s, tagNo, isExplicit);

    if (bufferSize != 0)
    {
        return octGen.getOctetOutputStream(new byte[bufferSize]);
    }

    return octGen.getOctetOutputStream();
}
项目:bc-java    文件:OctetStringTest.java   
public void testReadingWriting()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);

   OutputStream out = octGen.getOctetOutputStream();

   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[4]);

   out.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();

   InputStream in = s.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(8, count);
}
项目:bc-java    文件:OctetStringTest.java   
public void testReadingWritingZeroInLength()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(bOut);

   OutputStream out = octGen.getOctetOutputStream();

   out.write(new byte[] { 1, 2, 3, 4 });
   out.write(new byte[512]);  // forces a zero to appear in length

   out.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1OctetStringParser s = (ASN1OctetStringParser)aIn.readObject();

   InputStream in = s.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(516, count);
}
项目:irma_future_id    文件:OctetStringTest.java   
public void testNestedStructure()
    throws Exception
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    BERSequenceGenerator sGen = new BERSequenceGenerator(bOut);

    sGen.addObject(new DERObjectIdentifier(CMSObjectIdentifiers.compressedData.getId()));

    BERSequenceGenerator cGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);

    cGen.addObject(new DERInteger(0));

    //
    // AlgorithmIdentifier
    //
    DERSequenceGenerator algGen = new DERSequenceGenerator(cGen.getRawOutputStream());

    algGen.addObject(new DERObjectIdentifier("1.2"));

    algGen.close();

    //
    // Encapsulated ContentInfo
    //
    BERSequenceGenerator eiGen = new BERSequenceGenerator(cGen.getRawOutputStream());

    eiGen.addObject(new DERObjectIdentifier("1.1"));

    BEROctetStringGenerator octGen = new BEROctetStringGenerator(eiGen.getRawOutputStream(), 0, true);

    //
    // output containing zeroes
    //
    OutputStream out = octGen.getOctetOutputStream();

    out.write(new byte[] { 1, 2, 3, 4 });
    out.write(new byte[4]);
    out.write(new byte[20]);

    out.close();
    eiGen.close();
    cGen.close();
    sGen.close();

    //
    // reading back
    //
    ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

    ContentInfoParser cp = new ContentInfoParser((ASN1SequenceParser)aIn.readObject());

    CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)cp.getContent(BERTags.SEQUENCE));
    ContentInfoParser     content = comData.getEncapContentInfo();

    ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING);

    InputStream in = bytes.getOctetStream();
    int         count = 0;

    while (in.read() >= 0)
    {
        count++;
    }

    assertEquals(28, count);
}
项目:bc-java    文件:OctetStringTest.java   
public void testNestedStructure()
    throws Exception
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    BERSequenceGenerator sGen = new BERSequenceGenerator(bOut);

    sGen.addObject(new DERObjectIdentifier(CMSObjectIdentifiers.compressedData.getId()));

    BERSequenceGenerator cGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);

    cGen.addObject(new DERInteger(0));

    //
    // AlgorithmIdentifier
    //
    DERSequenceGenerator algGen = new DERSequenceGenerator(cGen.getRawOutputStream());

    algGen.addObject(new DERObjectIdentifier("1.2"));

    algGen.close();

    //
    // Encapsulated ContentInfo
    //
    BERSequenceGenerator eiGen = new BERSequenceGenerator(cGen.getRawOutputStream());

    eiGen.addObject(new DERObjectIdentifier("1.1"));

    BEROctetStringGenerator octGen = new BEROctetStringGenerator(eiGen.getRawOutputStream(), 0, true);

    //
    // output containing zeroes
    //
    OutputStream out = octGen.getOctetOutputStream();

    out.write(new byte[] { 1, 2, 3, 4 });
    out.write(new byte[4]);
    out.write(new byte[20]);

    out.close();
    eiGen.close();
    cGen.close();
    sGen.close();

    //
    // reading back
    //
    ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

    ContentInfoParser cp = new ContentInfoParser((ASN1SequenceParser)aIn.readObject());

    CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)cp.getContent(BERTags.SEQUENCE));
    ContentInfoParser     content = comData.getEncapContentInfo();

    ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING);

    InputStream in = bytes.getOctetStream();
    int         count = 0;

    while (in.read() >= 0)
    {
        count++;
    }

    assertEquals(28, count);
}
项目:irma_future_id    文件:OctetStringTest.java   
public void testReadingWritingNested()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BERSequenceGenerator sGen = new BERSequenceGenerator(bOut);
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(sGen.getRawOutputStream());

   OutputStream out = octGen.getOctetOutputStream();

   BERSequenceGenerator inSGen = new BERSequenceGenerator(out);

   BEROctetStringGenerator inOctGen = new BEROctetStringGenerator(inSGen.getRawOutputStream());

   OutputStream inOut = inOctGen.getOctetOutputStream();

   inOut.write(new byte[] { 1, 2, 3, 4 });
   inOut.write(new byte[10]);

   inOut.close();

   inSGen.close();

   out.close();

   sGen.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1SequenceParser sq = (ASN1SequenceParser)aIn.readObject();

   ASN1OctetStringParser s = (ASN1OctetStringParser)sq.readObject();

   ASN1StreamParser aIn2 = new ASN1StreamParser(s.getOctetStream());

   ASN1SequenceParser sq2 = (ASN1SequenceParser)aIn2.readObject();

   ASN1OctetStringParser inS = (ASN1OctetStringParser)sq2.readObject();

   InputStream in = inS.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(14, count);
}
项目:bc-java    文件:OctetStringTest.java   
public void testReadingWritingNested()
    throws Exception
{
   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
   BERSequenceGenerator sGen = new BERSequenceGenerator(bOut);
   BEROctetStringGenerator octGen = new BEROctetStringGenerator(sGen.getRawOutputStream());

   OutputStream out = octGen.getOctetOutputStream();

   BERSequenceGenerator inSGen = new BERSequenceGenerator(out);

   BEROctetStringGenerator inOctGen = new BEROctetStringGenerator(inSGen.getRawOutputStream());

   OutputStream inOut = inOctGen.getOctetOutputStream();

   inOut.write(new byte[] { 1, 2, 3, 4 });
   inOut.write(new byte[10]);

   inOut.close();

   inSGen.close();

   out.close();

   sGen.close();

   ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray());

   ASN1SequenceParser sq = (ASN1SequenceParser)aIn.readObject();

   ASN1OctetStringParser s = (ASN1OctetStringParser)sq.readObject();

   ASN1StreamParser aIn2 = new ASN1StreamParser(s.getOctetStream());

   ASN1SequenceParser sq2 = (ASN1SequenceParser)aIn2.readObject();

   ASN1OctetStringParser inS = (ASN1OctetStringParser)sq2.readObject();

   InputStream in = inS.getOctetStream();
   int         count = 0;

   while (in.read() >= 0)
   {
       count++;
   }

   assertEquals(14, count);
}