not-yet-commons-ssl-0.3.11

ndex;
          }
          index++;
        }
        lastSwap = swapIndex;
      }
    }
  }
  
  protected void addObject(DEREncodable obj)
  {
    set.addElement(obj);
  }
  
  abstract void encode(DEROutputStream paramDEROutputStream)
    throws IOException;
  
  public String toString()
  {
    return set.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ASN1Set
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public abstract interface ASN1SetParser
  extends DEREncodable
{
  public abstract DEREncodable readObject()
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ASN1SetParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;

public class ASN1StreamParser
{
  InputStream _in;
  private int _limit;
  private boolean _eofFound;
  
  public ASN1StreamParser(InputStream in)
  {
    this(in, Integer.MAX_VALUE);
  }
  
  public ASN1StreamParser(InputStream in, int limit)
  {
    _in = in;
    _limit = limit;
  }
  
  public ASN1StreamParser(byte[] encoding)
  {
    this(new ByteArrayInputStream(encoding), encoding.length);
  }
  
  InputStream getParentStream()
  {
    return _in;
  }
  
  private int readLength()
    throws IOException
  {
    int length = _in.read();
    if (length < 0) {
      throw new EOFException("EOF found when length expected");
    }
    if (length == 128) {
      return -1;
    }
    if (length > 127)
    {
      int size = length & 0x7F;
      if (size > 4) {
        throw new IOException("DER length more than 4 bytes");
      }
      length = 0;
      for (int i = 0; i < size; i++)
      {
        int next = _in.read();
        if (next < 0) {
          throw new EOFException("EOF found reading length");
        }
        length = (length << 8) + next;
      }
      if (length < 0) {
        throw new IOException("corrupted stream - negative length found");
      }
      if (length >= _limit) {
        throw new IOException("corrupted stream - out of bounds length found");
      }
    }
    return length;
  }
  
  public DEREncodable readObject()
    throws IOException
  {
    int tag = _in.read();
    if (tag == -1)
    {
      if (_eofFound) {
        throw new EOFException("attempt to read past end of file.");
      }
      _eofFound = true;
      
      return null;
    }
    set00Check(false);
    
    int baseTagNo = tag & 0xFFFFFFDF;
    int tagNo = baseTagNo;
    if ((tag & 0x80) != 0)
    {
      tagNo = tag & 0x1F;
      if (tagNo == 31)
      {
        tagNo = 0;
        
        int b = _in.read();
        while ((b >= 0) && ((b & 0x80) != 0))
        {
          tagNo |= b & 0x7F;
          tagNo <<= 7;
          b = _in.read();
        }
        if (b < 0)
        {
          _eofFound = true;
          
          throw new EOFException("EOF encountered inside tag value.");
        }
        tagNo |= b & 0x7F;
      }
    }
    int length = readLength();
    if (length < 0)
    {
      IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in);
      switch (baseTagNo)
      {
      case 5: 
        while (indIn.read() >= 0) {}
        return BERNull.INSTANCE;
      case 4: 
        return new BEROctetStringParser(new ASN1ObjectParser(tag, tagNo, indIn));
      case 16: 
        return new BERSequenceParser(new ASN1ObjectParser(tag, tagNo, indIn));
      case 17: 
        return new BERSetParser(new ASN1ObjectParser(tag, tagNo, indIn));
      }
      return new BERTaggedObjectParser(tag, tagNo, indIn);
    }
    DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length);
    switch (baseTagNo)
    {
    case 2: 
      return new DERInteger(defIn.toByteArray());
    case 5: 
      defIn.toByteArray();
      return DERNull.INSTANCE;
    case 6: 
      return new DERObjectIdentifier(defIn.toByteArray());
    case 4: 
      return new DEROctetString(defIn.toByteArray());
    case 16: 
      return new DERSequence(loadVector(defIn, length)).parser();
    case 17: 
      return new DERSet(loadVector(defIn, length)).parser();
    }
    return new BERTaggedObjectParser(tag, tagNo, defIn);
  }
  
  private void set00Check(boolean enabled)
  {
    if ((_in instanceof IndefiniteLengthInputStream)) {
      ((IndefiniteLengthInputStream)_in).setEofOn00(enabled);
    }
  }
  
  private ASN1EncodableVector loadVector(InputStream in, int length)
    throws IOException
  {
    ASN1InputStream aIn = new ASN1InputStream(in, length);
    ASN1EncodableVector v = new ASN1EncodableVector();
    DERObject obj;
    while ((obj = aIn.readObject()) != null) {
      v.add(obj);
    }
    return v;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ASN1StreamParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public abstract class ASN1TaggedObject
  extends ASN1Object
  implements ASN1TaggedObjectParser
{
  int tagNo;
  boolean empty = false;
  boolean explicit = true;
  DEREncodable obj = null;
  
  public static ASN1TaggedObject getInstance(ASN1TaggedObject obj, boolean explicit)
  {
    if (explicit) {
      return (ASN1TaggedObject)obj.getObject();
    }
    throw new IllegalArgumentException("implicitly tagged tagged object");
  }
  
  public static ASN1TaggedObject getInstance(Object obj)
  {
    if ((obj == null) || ((obj instanceof ASN1TaggedObject))) {
      return (ASN1TaggedObject)obj;
    }
    throw new IllegalArgumentException("unknown object in getInstance");
  }
  
  public ASN1TaggedObject(int tagNo, DEREncodable obj)
  {
    explicit = true;
    this.tagNo = tagNo;
    this.obj = obj;
  }
  
  public ASN1TaggedObject(boolean explicit, int tagNo, DEREncodable obj)
  {
    if ((obj instanceof ASN1Choice)) {
      this.explicit = true;
    } else {
      this.explicit = explicit;
    }
    this.tagNo = tagNo;
    this.obj = obj;
  }
  
  boolean asn1Equals(DERObject o)
  {
    if (!(o instanceof ASN1TaggedObject)) {
      return false;
    }
    ASN1TaggedObject other = (ASN1TaggedObject)o;
    if ((tagNo != tagNo) || (empty != empty) || (explicit != explicit)) {
      return false;
    }
    if (obj == null)
    {
      if (obj != null) {
        return false;
      }
    }
    else if (!obj.getDERObject().equals(obj.getDERObject())) {
      return false;
    }
    return true;
  }
  
  public int hashCode()
  {
    int code = tagNo;
    if (obj != null) {
      code ^= obj.hashCode();
    }
    return code;
  }
  
  public int getTagNo()
  {
    return tagNo;
  }
  
  public boolean isExplicit()
  {
    return explicit;
  }
  
  public boolean isEmpty()
  {
    return empty;
  }
  
  public DERObject getObject()
  {
    if (obj != null) {
      return obj.getDERObject();
    }
    return null;
  }
  
  public DEREncodable getObjectParser(int tag, boolean isExplicit)
  {
    switch (tag)
    {
    case 17: 
      return ASN1Set.getInstance(this, isExplicit).parser();
    case 16: 
      return ASN1Sequence.getInstance(this, isExplicit).parser();
    case 4: 
      return ASN1OctetString.getInstance(this, isExplicit).parser();
    }
    if (isExplicit) {
      return getObject();
    }
    throw new RuntimeException("implicit tagging not implemented for tag: " + tag);
  }
  
  abstract void encode(DEROutputStream paramDEROutputStream)
    throws IOException;
  
  public String toString()
  {
    return "[" + tagNo + "]" + obj;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ASN1TaggedObject
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public abstract interface ASN1TaggedObjectParser
  extends DEREncodable
{
  public abstract int getTagNo();
  
  public abstract DEREncodable getObjectParser(int paramInt, boolean paramBoolean)
    throws IOException;
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ASN1TaggedObjectParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

public class BERConstructedOctetString
  extends DEROctetString
{
  private static final int MAX_LENGTH = 1000;
  private Vector octs;
  
  private static byte[] toBytes(Vector octs)
  {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    for (int i = 0; i != octs.size(); i++) {
      try
      {
        DEROctetString o = (DEROctetString)octs.elementAt(i);
        
        bOut.write(o.getOctets());
      }
      catch (ClassCastException e)
      {
        throw new IllegalArgumentException(octs.elementAt(i).getClass().getName() + " found in input should only contain DEROctetString");
      }
      catch (IOException e)
      {
        throw new IllegalArgumentException("exception converting octets " + e.toString());
      }
    }
    return bOut.toByteArray();
  }
  
  public BERConstructedOctetString(byte[] string)
  {
    super(string);
  }
  
  public BERConstructedOctetString(Vector octs)
  {
    super(toBytes(octs));
    
    this.octs = octs;
  }
  
  public BERConstructedOctetString(DERObject obj)
  {
    super(obj);
  }
  
  public BERConstructedOctetString(DEREncodable obj)
  {
    super(obj.getDERObject());
  }
  
  public byte[] getOctets()
  {
    return string;
  }
  
  public Enumeration getObjects()
  {
    if (octs == null) {
      return generateOcts().elements();
    }
    return octs.elements();
  }
  
  private Vector generateOcts()
  {
    int start = 0;
    int end = 0;
    Vector vec = new Vector();
    while (end + 1 < string.length)
    {
      if ((string[end] == 0) && (string[(end + 1)] == 0))
      {
        byte[] nStr = new byte[end - start + 1];
        
        System.arraycopy(string, start, nStr, 0, nStr.length);
        
        vec.addElement(new DEROctetString(nStr));
        start = end + 1;
      }
      end++;
    }
    byte[] nStr = new byte[string.length - start];
    
    System.arraycopy(string, start, nStr, 0, nStr.length);
    
    vec.addElement(new DEROctetString(nStr));
    
    return vec;
  }
  
  public void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream)))
    {
      out.write(36);
      
      out.write(128);
      if (octs != null) {
        for (int i = 0; i != octs.size(); i++) {
          out.writeObject(octs.elementAt(i));
        }
      } else {
        for (int i = 0; i < string.length; i += 1000)
        {
          int end;
          int end;
          if (i + 1000 > string.length) {
            end = string.length;
          } else {
            end = i + 1000;
          }
          byte[] nStr = new byte[end - i];
          
          System.arraycopy(string, i, nStr, 0, nStr.length);
          
          out.writeObject(new DEROctetString(nStr));
        }
      }
      out.write(0);
      out.write(0);
    }
    else
    {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERConstructedOctetString
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.util.Enumeration;

/**
 * @deprecated
 */
public class BERConstructedSequence
  extends DERConstructedSequence
{
  void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream)))
    {
      out.write(48);
      out.write(128);
      
      Enumeration e = getObjects();
      while (e.hasMoreElements()) {
        out.writeObject(e.nextElement());
      }
      out.write(0);
      out.write(0);
    }
    else
    {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERConstructedSequence
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

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

public class BERGenerator
  extends ASN1Generator
{
  private boolean _tagged = false;
  private boolean _isExplicit;
  private int _tagNo;
  
  protected BERGenerator(OutputStream out)
  {
    super(out);
  }
  
  public BERGenerator(OutputStream out, int tagNo, boolean isExplicit)
  {
    super(out);
    
    _tagged = true;
    _isExplicit = isExplicit;
    _tagNo = tagNo;
  }
  
  public OutputStream getRawOutputStream()
  {
    return _out;
  }
  
  private void writeHdr(int tag)
    throws IOException
  {
    _out.write(tag);
    _out.write(128);
  }
  
  protected void writeBERHeader(int tag)
    throws IOException
  {
    if (_tagged)
    {
      int tagNum = _tagNo | 0x80;
      if (_isExplicit)
      {
        writeHdr(tagNum | 0x20);
        writeHdr(tag);
      }
      else if ((tag & 0x20) != 0)
      {
        writeHdr(tagNum | 0x20);
      }
      else
      {
        writeHdr(tagNum);
      }
    }
    else
    {
      writeHdr(tag);
    }
  }
  
  protected void writeBERBody(InputStream contentStream)
    throws IOException
  {
    int ch;
    while ((ch = contentStream.read()) >= 0) {
      _out.write(ch);
    }
  }
  
  protected void writeBEREnd()
    throws IOException
  {
    _out.write(0);
    _out.write(0);
    if ((_tagged) && (_isExplicit))
    {
      _out.write(0);
      _out.write(0);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERGenerator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

class BERInputStream$1
  extends DERObject
{
  BERInputStream$1()
    throws IOException
  {}
  
  void encode(DEROutputStream out)
    throws IOException
  {
    throw new IOException("Eeek!");
  }
  
  public int hashCode()
  {
    return 0;
  }
  
  public boolean equals(Object o)
  {
    return o == this;
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERInputStream.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

/**
 * @deprecated
 */
public class BERInputStream
  extends DERInputStream
{
  private static final DERObject END_OF_STREAM = new DERObject()
  {
    void encode(DEROutputStream out)
      throws IOException
    {
      throw new IOException("Eeek!");
    }
    
    public int hashCode()
    {
      return 0;
    }
    
    public boolean equals(Object o)
    {
      return o == this;
    }
  };
  
  public BERInputStream(InputStream is)
  {
    super(is);
  }
  
  private byte[] readIndefiniteLengthFully()
    throws IOException
  {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    
    int b1 = read();
    int b;
    while (((b = read()) >= 0) && (
      (b1 != 0) || (b != 0)))
    {
      bOut.write(b1);
      b1 = b;
    }
    return bOut.toByteArray();
  }
  
  private BERConstructedOctetString buildConstructedOctetString()
    throws IOException
  {
    Vector octs = new Vector();
    for (;;)
    {
      DERObject o = readObject();
      if (o == END_OF_STREAM) {
        break;
      }
      octs.addElement(o);
    }
    return new BERConstructedOctetString(octs);
  }
  
  public DERObject readObject()
    throws IOException
  {
    int tag = read();
    if (tag == -1) {
      throw new EOFException();
    }
    int length = readLength();
    if (length < 0)
    {
      switch (tag)
      {
      case 5: 
        return null;
      case 48: 
        BERConstructedSequence seq = new BERConstructedSequence();
        for (;;)
        {
          DERObject obj = readObject();
          if (obj == END_OF_STREAM) {
            break;
          }
          seq.addObject(obj);
        }
        return seq;
      case 36: 
        return buildConstructedOctetString();
      case 49: 
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (;;)
        {
          DERObject obj = readObject();
          if (obj == END_OF_STREAM) {
            break;
          }
          v.add(obj);
        }
        return new BERSet(v);
      }
      if ((tag & 0x80) != 0)
      {
        if ((tag & 0x1F) == 31) {
          throw new IOException("unsupported high tag encountered");
        }
        if ((tag & 0x20) == 0)
        {
          byte[] bytes = readIndefiniteLengthFully();
          
          return new BERTaggedObject(false, tag & 0x1F, new DEROctetString(bytes));
        }
        DERObject dObj = readObject();
        if (dObj == END_OF_STREAM) {
          return new DERTaggedObject(tag & 0x1F);
        }
        DERObject next = readObject();
        if (next == END_OF_STREAM) {
          return new BERTaggedObject(tag & 0x1F, dObj);
        }
        BERConstructedSequence seq = new BERConstructedSequence();
        
        seq.addObject(dObj);
        do
        {
          seq.addObject(next);
          next = readObject();
        } while (next != END_OF_STREAM);
        return new BERTaggedObject(false, tag & 0x1F, seq);
      }
      throw new IOException("unknown BER object encountered");
    }
    if ((tag == 0) && (length == 0)) {
      return END_OF_STREAM;
    }
    byte[] bytes = new byte[length];
    
    readFully(bytes);
    
    return buildObject(tag, bytes);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERInputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public class BERNull
  extends DERNull
{
  public static final BERNull INSTANCE = new BERNull();
  
  void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream))) {
      out.write(5);
    } else {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERNull
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.io.OutputStream;

class BEROctetStringGenerator$BufferedBEROctetStream
  extends OutputStream
{
  private byte[] _buf;
  private int _off;
  private final BEROctetStringGenerator this$0;
  
  BEROctetStringGenerator$BufferedBEROctetStream(BEROctetStringGenerator this$0, byte[] buf)
  {
    this.this$0 = this$0;
    _buf = buf;
    _off = 0;
  }
  
  public void write(int b)
    throws IOException
  {
    _buf[(_off++)] = ((byte)b);
    if (_off == _buf.length)
    {
      this$0._out.write(new DEROctetString(_buf).getEncoded());
      _off = 0;
    }
  }
  
  public void write(byte[] b, int off, int len)
    throws IOException
  {
    while (len > 0)
    {
      int numToCopy = Math.min(len, _buf.length - _off);
      System.arraycopy(b, off, _buf, _off, numToCopy);
      
      _off += numToCopy;
      if (_off < _buf.length) {
        break;
      }
      this$0._out.write(new DEROctetString(_buf).getEncoded());
      _off = 0;
      
      off += numToCopy;
      len -= numToCopy;
    }
  }
  
  public void close()
    throws IOException
  {
    if (_off != 0)
    {
      byte[] bytes = new byte[_off];
      System.arraycopy(_buf, 0, bytes, 0, _off);
      
      this$0._out.write(new DEROctetString(bytes).getEncoded());
    }
    this$0.writeBEREnd();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BEROctetStringGenerator.BufferedBEROctetStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.io.OutputStream;

public class BEROctetStringGenerator
  extends BERGenerator
{
  public BEROctetStringGenerator(OutputStream out)
    throws IOException
  {
    super(out);
    
    writeBERHeader(36);
  }
  
  public BEROctetStringGenerator(OutputStream out, int tagNo, boolean isExplicit)
    throws IOException
  {
    super(out, tagNo, isExplicit);
    
    writeBERHeader(36);
  }
  
  public OutputStream getOctetOutputStream()
  {
    return getOctetOutputStream(new byte['?']);
  }
  
  public OutputStream getOctetOutputStream(byte[] buf)
  {
    return new BufferedBEROctetStream(buf);
  }
  
  private class BufferedBEROctetStream
    extends OutputStream
  {
    private byte[] _buf;
    private int _off;
    
    BufferedBEROctetStream(byte[] buf)
    {
      _buf = buf;
      _off = 0;
    }
    
    public void write(int b)
      throws IOException
    {
      _buf[(_off++)] = ((byte)b);
      if (_off == _buf.length)
      {
        _out.write(new DEROctetString(_buf).getEncoded());
        _off = 0;
      }
    }
    
    public void write(byte[] b, int off, int len)
      throws IOException
    {
      while (len > 0)
      {
        int numToCopy = Math.min(len, _buf.length - _off);
        System.arraycopy(b, off, _buf, _off, numToCopy);
        
        _off += numToCopy;
        if (_off < _buf.length) {
          break;
        }
        _out.write(new DEROctetString(_buf).getEncoded());
        _off = 0;
        
        off += numToCopy;
        len -= numToCopy;
      }
    }
    
    public void close()
      throws IOException
    {
      if (_off != 0)
      {
        byte[] bytes = new byte[_off];
        System.arraycopy(_buf, 0, bytes, 0, _off);
        
        _out.write(new DEROctetString(bytes).getEncoded());
      }
      writeBEREnd();
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BEROctetStringGenerator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

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

public class BEROctetStringParser
  implements ASN1OctetStringParser
{
  private ASN1ObjectParser _parser;
  
  protected BEROctetStringParser(ASN1ObjectParser parser)
  {
    _parser = parser;
  }
  
  public InputStream getOctetStream()
  {
    return new ConstructedOctetStream(_parser);
  }
  
  public DERObject getDERObject()
  {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    InputStream in = getOctetStream();
    try
    {
      int ch;
      while ((ch = in.read()) >= 0) {
        bOut.write(ch);
      }
    }
    catch (IOException e)
    {
      throw new IllegalStateException("IOException converting stream to byte array: " + e.getMessage());
    }
    int ch;
    return new BERConstructedOctetString(bOut.toByteArray());
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BEROctetStringParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.io.OutputStream;

public class BEROutputStream
  extends DEROutputStream
{
  public BEROutputStream(OutputStream os)
  {
    super(os);
  }
  
  public void writeObject(Object obj)
    throws IOException
  {
    if (obj == null) {
      writeNull();
    } else if ((obj instanceof DERObject)) {
      ((DERObject)obj).encode(this);
    } else if ((obj instanceof DEREncodable)) {
      ((DEREncodable)obj).getDERObject().encode(this);
    } else {
      throw new IOException("object not BEREncodable");
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BEROutputStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.util.Enumeration;

public class BERSequence
  extends DERSequence
{
  public BERSequence() {}
  
  public BERSequence(DEREncodable obj)
  {
    super(obj);
  }
  
  public BERSequence(DEREncodableVector v)
  {
    super(v);
  }
  
  void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream)))
    {
      out.write(48);
      out.write(128);
      
      Enumeration e = getObjects();
      while (e.hasMoreElements()) {
        out.writeObject(e.nextElement());
      }
      out.write(0);
      out.write(0);
    }
    else
    {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERSequence
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.io.OutputStream;

public class BERSequenceGenerator
  extends BERGenerator
{
  public BERSequenceGenerator(OutputStream out)
    throws IOException
  {
    super(out);
    
    writeBERHeader(48);
  }
  
  public BERSequenceGenerator(OutputStream out, int tagNo, boolean isExplicit)
    throws IOException
  {
    super(out, tagNo, isExplicit);
    
    writeBERHeader(48);
  }
  
  public void addObject(DEREncodable object)
    throws IOException
  {
    object.getDERObject().encode(new DEROutputStream(_out));
  }
  
  public void close()
    throws IOException
  {
    writeBEREnd();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERSequenceGenerator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public class BERSequenceParser
  implements ASN1SequenceParser
{
  private ASN1ObjectParser _parser;
  
  BERSequenceParser(ASN1ObjectParser parser)
  {
    _parser = parser;
  }
  
  public DEREncodable readObject()
    throws IOException
  {
    return _parser.readObject();
  }
  
  public DERObject getDERObject()
  {
    return new BERSequence(_parser.readVector());
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERSequenceParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.util.Enumeration;

public class BERSet
  extends DERSet
{
  public BERSet() {}
  
  public BERSet(DEREncodable obj)
  {
    super(obj);
  }
  
  public BERSet(DEREncodableVector v)
  {
    super(v, false);
  }
  
  BERSet(DEREncodableVector v, boolean needsSorting)
  {
    super(v, needsSorting);
  }
  
  void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream)))
    {
      out.write(49);
      out.write(128);
      
      Enumeration e = getObjects();
      while (e.hasMoreElements()) {
        out.writeObject(e.nextElement());
      }
      out.write(0);
      out.write(0);
    }
    else
    {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERSet
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public class BERSetParser
  implements ASN1SetParser
{
  private ASN1ObjectParser _parser;
  
  BERSetParser(ASN1ObjectParser parser)
  {
    _parser = parser;
  }
  
  public DEREncodable readObject()
    throws IOException
  {
    return _parser.readObject();
  }
  
  public DERObject getDERObject()
  {
    return new BERSet(_parser.readVector());
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERSetParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;
import java.util.Enumeration;

public class BERTaggedObject
  extends DERTaggedObject
{
  public BERTaggedObject(int tagNo, DEREncodable obj)
  {
    super(tagNo, obj);
  }
  
  public BERTaggedObject(boolean explicit, int tagNo, DEREncodable obj)
  {
    super(explicit, tagNo, obj);
  }
  
  public BERTaggedObject(int tagNo)
  {
    super(false, tagNo, new BERSequence());
  }
  
  void encode(DEROutputStream out)
    throws IOException
  {
    if (((out instanceof ASN1OutputStream)) || ((out instanceof BEROutputStream)))
    {
      out.write(0xA0 | tagNo);
      out.write(128);
      if (!empty) {
        if (!explicit)
        {
          if ((obj instanceof ASN1OctetString))
          {
            Enumeration e;
            Enumeration e;
            if ((obj instanceof BERConstructedOctetString))
            {
              e = ((BERConstructedOctetString)obj).getObjects();
            }
            else
            {
              ASN1OctetString octs = (ASN1OctetString)obj;
              BERConstructedOctetString berO = new BERConstructedOctetString(octs.getOctets());
              
              e = berO.getObjects();
            }
            while (e.hasMoreElements()) {
              out.writeObject(e.nextElement());
            }
          }
          else if ((obj instanceof ASN1Sequence))
          {
            Enumeration e = ((ASN1Sequence)obj).getObjects();
            while (e.hasMoreElements()) {
              out.writeObject(e.nextElement());
            }
          }
          else if ((obj instanceof ASN1Set))
          {
            Enumeration e = ((ASN1Set)obj).getObjects();
            while (e.hasMoreElements()) {
              out.writeObject(e.nextElement());
            }
          }
          else
          {
            throw new RuntimeException("not implemented: " + obj.getClass().getName());
          }
        }
        else {
          out.writeObject(obj);
        }
      }
      out.write(0);
      out.write(0);
    }
    else
    {
      super.encode(out);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERTaggedObject
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

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

public class BERTaggedObjectParser
  implements ASN1TaggedObjectParser
{
  private int _baseTag;
  private int _tagNumber;
  private InputStream _contentStream;
  private boolean _indefiniteLength;
  
  protected BERTaggedObjectParser(int baseTag, int tagNumber, InputStream contentStream)
  {
    _baseTag = baseTag;
    _tagNumber = tagNumber;
    _contentStream = contentStream;
    _indefiniteLength = (contentStream instanceof IndefiniteLengthInputStream);
  }
  
  public boolean isConstructed()
  {
    return (_baseTag & 0x20) != 0;
  }
  
  public int getTagNo()
  {
    return _tagNumber;
  }
  
  public DEREncodable getObjectParser(int tag, boolean isExplicit)
    throws IOException
  {
    if (isExplicit) {
      return new ASN1StreamParser(_contentStream).readObject();
    }
    switch (tag)
    {
    case 17: 
      if (_indefiniteLength) {
        return new BERSetParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
      }
      return new DERSet(loadVector(_contentStream)).parser();
    case 16: 
      if (_indefiniteLength) {
        return new BERSequenceParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
      }
      return new DERSequence(loadVector(_contentStream)).parser();
    case 4: 
      if ((_indefiniteLength) || (isConstructed())) {
        return new BEROctetStringParser(new ASN1ObjectParser(_baseTag, _tagNumber, _contentStream));
      }
      return new DEROctetString(((DefiniteLengthInputStream)_contentStream).toByteArray()).parser();
    }
    throw new RuntimeException("implicit tagging not implemented");
  }
  
  private ASN1EncodableVector loadVector(InputStream in)
    throws IOException
  {
    ASN1StreamParser aIn = new ASN1StreamParser(in);
    ASN1EncodableVector v = new ASN1EncodableVector();
    DEREncodable obj = aIn.readObject();
    while (obj != null)
    {
      v.add(obj.getDERObject());
      obj = aIn.readObject();
    }
    return v;
  }
  
  private ASN1EncodableVector rLoadVector(InputStream in)
  {
    try
    {
      return loadVector(in);
    }
    catch (IOException e)
    {
      throw new IllegalStateException(e.getMessage());
    }
  }
  
  public DERObject getDERObject()
  {
    if (_indefiniteLength)
    {
      ASN1EncodableVector v = rLoadVector(_contentStream);
      if (v.size() > 1) {
        return new BERTaggedObject(false, _tagNumber, new BERSequence(v));
      }
      if (v.size() == 1) {
        return new BERTaggedObject(true, _tagNumber, v.get(0));
      }
      return new BERTaggedObject(false, _tagNumber, new BERSequence());
    }
    if (isConstructed())
    {
      ASN1EncodableVector v = rLoadVector(_contentStream);
      if (v.size() == 1) {
        return new DERTaggedObject(true, _tagNumber, v.get(0));
      }
      return new DERTaggedObject(false, _tagNumber, new DERSequence(v));
    }
    try
    {
      return new DERTaggedObject(false, _tagNumber, new DEROctetString(((DefiniteLengthInputStream)_contentStream).toByteArray()));
    }
    catch (IOException e)
    {
      throw new IllegalStateException(e.getMessage());
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.BERTaggedObjectParser
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

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

class ConstructedOctetStream
  extends InputStream
{
  private final ASN1ObjectParser _parser;
  private boolean _first = true;
  private InputStream _currentStream;
  
  ConstructedOctetStream(ASN1ObjectParser parser)
  {
    _parser = parser;
  }
  
  public int read(byte[] b, int off, int len)
    throws IOException
  {
    if (_currentStream == null)
    {
      if (!_first) {
        return -1;
      }
      ASN1OctetStringParser s = (ASN1OctetStringParser)_parser.readObject();
      if (s == null) {
        return -1;
      }
      _first = false;
      _currentStream = s.getOctetStream();
    }
    int totalRead = 0;
    for (;;)
    {
      int numRead = _currentStream.read(b, off + totalRead, len - totalRead);
      if (numRead >= 0)
      {
        totalRead += numRead;
        if (totalRead == len) {
          return totalRead;
        }
      }
      else
      {
        ASN1OctetStringParser aos = (ASN1OctetStringParser)_parser.readObject();
        if (aos == null)
        {
          _currentStream = null;
          return totalRead < 1 ? -1 : totalRead;
        }
        _currentStream = aos.getOctetStream();
      }
    }
  }
  
  public int read()
    throws IOException
  {
    if (_currentStream == null)
    {
      if (!_first) {
        return -1;
      }
      ASN1OctetStringParser s = (ASN1OctetStringParser)_parser.readObject();
      if (s == null) {
        return -1;
      }
      _first = false;
      _currentStream = s.getOctetStream();
    }
    for (;;)
    {
      int b = _currentStream.read();
      if (b >= 0) {
        return b;
      }
      ASN1OctetStringParser s = (ASN1OctetStringParser)_parser.readObject();
      if (s == null)
      {
        _currentStream = null;
        return -1;
      }
      _currentStream = s.getOctetStream();
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.ConstructedOctetStream
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class DERApplicationSpecific
  extends ASN1Object
{
  private int tag;
  private byte[] octets;
  
  public DERApplicationSpecific(int tag, byte[] octets)
  {
    this.tag = tag;
    this.octets = octets;
  }
  
  public DERApplicationSpecific(int tag, DEREncodable object)
    throws IOException
  {
    this(true, tag, object);
  }
  
  public DERApplicationSpecific(boolean explicit, int tag, DEREncodable object)
    throws IOException
  {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dos = new DEROutputStream(bOut);
    
    dos.writeObject(object);
    
    byte[] data = bOut.toByteArray();
    if (tag >= 31) {
      throw new IOException("unsupported tag number");
    }
    if (explicit)
    {
      this.tag = (tag | 0x20);
      octets = data;
    }
    else
    {
      this.tag = tag;
      int lenBytes = getLengthOfLength(data);
      byte[] tmp = new byte[data.length - lenBytes];
      System.arraycopy(data, lenBytes, tmp, 0, tmp.length);
      octets = tmp;
    }
  }
  
  private int getLengthOfLength(byte[] data)
  {
    int count = 2;
    while ((data[(count - 1)] & 0x80) != 0) {
      count++;
    }
    return count;
  }
  
  public boolean isConstructed()
  {
    return (tag & 0x20) != 0;
  }
  
  public byte[] getContents()
  {
    return octets;
  }
  
  public int getApplicationTag()
  {
    return tag;
  }
  
  public DERObject getObject()
    throws IOException
  {
    return new ASN1InputStream(getContents()).readObject();
  }
  
  public DERObject getObject(int derTagNo)
    throws IOException
  {
    if (tag >= 31) {
      throw new IOException("unsupported tag number");
    }
    byte[] tmp = getEncoded();
    
    tmp[0] = ((byte)derTagNo);
    
    return new ASN1InputStream(tmp).readObject();
  }
  
  void encode(DEROutputStream out)
    throws IOException
  {
    out.writeEncoded(0x40 | tag, octets);
  }
  
  boolean asn1Equals(DERObject o)
  {
    if (!(o instanceof DERApplicationSpecific)) {
      return false;
    }
    DERApplicationSpecific other = (DERApplicationSpecific)o;
    if (tag != tag) {
      return false;
    }
    if (octets.length != octets.length) {
      return false;
    }
    for (int i = 0; i < octets.length; i++) {
      if (octets[i] != octets[i]) {
        return false;
      }
    }
    return true;
  }
  
  public int hashCode()
  {
    byte[] b = getContents();
    int value = 0;
    for (int i = 0; i != b.length; i++) {
      value ^= (b[i] & 0xFF) << i % 4;
    }
    return value ^ getApplicationTag();
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.DERApplicationSpecific
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.commons.ssl.asn1;

import java.io.IOException;

public class DERBMPString
  extends ASN1Object
  implements DERString
{
  String string;
  
  public static DERBMPString getInstance(Object obj)
  {
    if ((obj == null) || ((obj instanceof DERBMPString))) {
      return (DERBMPString)obj;
    }
    if ((obj instanceof ASN1OctetString)) {
      return new DERBMPString(((ASN1OctetString)obj).getOctets());
    }
    if ((obj instanceof ASN1TaggedObject)) {
      return getInstance(((ASN1TaggedObject)obj).getObject());
    }
    throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName());
  }
  
  public static DERBMPString getInstance(ASN1TaggedObject obj, boolean explicit)
  {
    return getInstance(obj.getObject());
  }
  
  public DERBMPString(byte[] string)
  {
    char[] cs = new char[string.length / 2];
    for (int i = 0; i != cs.length; i++) {
      cs[i] = ((char)(string[(2 * i)] << 8 | string[(2 * i + 1)] & 0xFF));
    }
    this.string = new String(cs);
  }
  
  public DERBMPString(String string)
  {
    this.string = string;
  }
  
  public String getString()
  {
    return string;
  }
  
  public String toString()
  {
    return string;
  }
  
  public int hashCode()
  {
    return getString().hashCode();
  }
  
  protected boolean asn1Equals(DERObject o)
  {
    if (!(o instanceof DERBMPString)) {
      return false;
    }
    DERBMPString s = (DERBMPString)o;
    
    return getString().equals(s.getString());
  }
  
  void encode(DEROutputStream out)
    throws IOException
  {
    char[] c = string.toCharArray();
    byte[] b = new byte[c.length * 2];
    for (int i = 0; i != c.length; i++)
    {
      b[(2 * i)] = ((byte)(c[i] >> '\b'));
      b[(2 * i + 1)] = ((byte)c[i]);
    }
    out.writeEncoded(30, b);
  }
}

/* Location:
 * Qualified Name:     org.apache.commons.ssl.asn1.DERBMPString
 * Jav
1 2 3 4 5 6 7 8 9 10 11 12 13

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd