FileDocCategorySizeDatePackage
DerGenerator.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)3020Wed Oct 01 10:55:30 BST 2008org.bouncycastle.sasn1

DerGenerator

public abstract class DerGenerator extends Asn1Generator
deprecated
use corresponsding classes in org.bouncycastle.asn1.

Fields Summary
private boolean
_tagged
private boolean
_isExplicit
private int
_tagNo
Constructors Summary
protected DerGenerator(OutputStream out)

    
     
         
    
        super(out);
    
public DerGenerator(OutputStream out, int tagNo, boolean isExplicit)

 
        super(out);
        
        _tagged = true;
        _isExplicit = isExplicit;
        _tagNo = tagNo;
    
Methods Summary
voidwriteDerEncoded(java.io.OutputStream out, int tag, byte[] bytes)

        out.write(tag);
        writeLength(out, bytes.length);
        out.write(bytes);
    
voidwriteDerEncoded(int tag, byte[] bytes)

        if (_tagged)
        {
            int tagNum = _tagNo | BerTag.TAGGED;
            
            if (_isExplicit)
            {
                int newTag = _tagNo | BerTag.CONSTRUCTED | BerTag.TAGGED;

                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                
                writeDerEncoded(bOut, tag, bytes);
                
                writeDerEncoded(_out, newTag, bOut.toByteArray());
            }
            else
            {   
                if ((tag & BerTag.CONSTRUCTED) != 0)
                {
                    writeDerEncoded(_out, tagNum | BerTag.CONSTRUCTED, bytes);
                }
                else
                {
                    writeDerEncoded(_out, tagNum, bytes);
                }
            }
        }
        else
        {
            writeDerEncoded(_out, tag, bytes);
        }
    
voidwriteDerEncoded(java.io.OutputStream out, int tag, java.io.InputStream in)

        out.write(tag);
        
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        
        int b = 0;
        while ((b = in.read()) >= 0)
        {
            bOut.write(b);
        }
        
        byte[] bytes = bOut.toByteArray();
        
        writeLength(out, bytes.length);
        out.write(bytes);
    
private voidwriteLength(java.io.OutputStream out, int length)

        if (length > 127)
        {
            int size = 1;
            int val = length;

            while ((val >>>= 8) != 0)
            {
                size++;
            }

            out.write((byte)(size | 0x80));

            for (int i = (size - 1) * 8; i >= 0; i -= 8)
            {
                out.write((byte)(length >> i));
            }
        }
        else
        {
            out.write((byte)length);
        }