Class DERWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class DERWriter
    extends java.io.FilterOutputStream
    A bare-minimum DER encoder - just enough so we can encoder signatures and keys data
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] lenBytes  
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      DERWriter()  
      DERWriter​(int initialSize)  
      DERWriter​(java.io.OutputStream stream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean isPositive​(byte b)  
      DERWriter startSequence()  
      byte[] toByteArray()  
      void writeBigInteger​(byte... bytes)
      The integer is always considered to be positive, so if the first byte is < 0, we pad with a zero to make it positive
      void writeBigInteger​(byte[] bytes, int off, int len)
      The integer is always considered to be positive, so if the first byte is < 0, we pad with a zero to make it positive
      void writeBigInteger​(java.math.BigInteger value)  
      void writeLength​(int len)  
      void writeObject​(byte tag, int len, byte... data)  
      void writeObject​(ASN1Object obj)  
      • Methods inherited from class java.io.FilterOutputStream

        close, flush, write, write, write
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lenBytes

        private final byte[] lenBytes
    • Constructor Detail

      • DERWriter

        public DERWriter()
      • DERWriter

        public DERWriter​(int initialSize)
      • DERWriter

        public DERWriter​(java.io.OutputStream stream)
    • Method Detail

      • startSequence

        public DERWriter startSequence()
      • writeBigInteger

        public void writeBigInteger​(java.math.BigInteger value)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBigInteger

        public void writeBigInteger​(byte... bytes)
                             throws java.io.IOException
        The integer is always considered to be positive, so if the first byte is < 0, we pad with a zero to make it positive
        Parameters:
        bytes - BigInteger bytes
        Throws:
        java.io.IOException - If failed to write the bytes
      • writeBigInteger

        public void writeBigInteger​(byte[] bytes,
                                    int off,
                                    int len)
                             throws java.io.IOException
        The integer is always considered to be positive, so if the first byte is < 0, we pad with a zero to make it positive
        Parameters:
        bytes - BigInteger bytes
        off - Offset in bytes data
        len - Number of bytes to write
        Throws:
        java.io.IOException - If failed to write the bytes
      • isPositive

        private boolean isPositive​(byte b)
      • writeObject

        public void writeObject​(ASN1Object obj)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • writeObject

        public void writeObject​(byte tag,
                                int len,
                                byte... data)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • writeLength

        public void writeLength​(int len)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • toByteArray

        public byte[] toByteArray()
                           throws java.io.IOException
        Throws:
        java.io.IOException