public x509certificateobject(org.ripple.bouncycastle.asn1.x509.certificate c)
      throws certificateparsingexception {
    this.c = c;

    try {
      byte[] bytes = this.getextensionbytes("2.5.29.19");

      if (bytes != null) {
        basicconstraints = basicconstraints.getinstance(asn1primitive.frombytearray(bytes));
      }
    } catch (exception e) {
      throw new certificateparsingexception("cannot construct basicconstraints: " + e);
    }

    try {
      byte[] bytes = this.getextensionbytes("2.5.29.15");
      if (bytes != null) {
        derbitstring bits = derbitstring.getinstance(asn1primitive.frombytearray(bytes));

        bytes = bits.getbytes();
        int length = (bytes.length * 8) - bits.getpadbits();

        keyusage = new boolean[(length < 9) ? 9 : length];

        for (int i = 0; i != length; i++) {
          keyusage[i] = (bytes[i / 8] & (0x80 >>> (i % 8))) != 0;
        }
      } else {
        keyusage = null;
      }
    } catch (exception e) {
      throw new certificateparsingexception("cannot construct keyusage: " + e);
    }
  }
  public string tostring() {
    stringbuffer buf = new stringbuffer();
    string nl = system.getproperty("line.separator");

    buf.append("  [0]         version: ").append(this.getversion()).append(nl);
    buf.append("         serialnumber: ").append(this.getserialnumber()).append(nl);
    buf.append("             issuerdn: ").append(this.getissuerdn()).append(nl);
    buf.append("           start date: ").append(this.getnotbefore()).append(nl);
    buf.append("           final date: ").append(this.getnotafter()).append(nl);
    buf.append("            subjectdn: ").append(this.getsubjectdn()).append(nl);
    buf.append("           public key: ").append(this.getpublickey()).append(nl);
    buf.append("  signature algorithm: ").append(this.getsigalgname()).append(nl);

    byte[] sig = this.getsignature();

    buf.append("            signature: ").append(new string(hex.encode(sig, 0, 20))).append(nl);
    for (int i = 20; i < sig.length; i += 20) {
      if (i < sig.length - 20) {
        buf.append("                       ").append(new string(hex.encode(sig, i, 20))).append(nl);
      } else {
        buf.append("                       ")
            .append(new string(hex.encode(sig, i, sig.length - i)))
            .append(nl);
      }
    }

    extensions extensions = c.gettbscertificate().getextensions();

    if (extensions != null) {
      enumeration e = extensions.oids();

      if (e.hasmoreelements()) {
        buf.append("       extensions: \n");
      }

      while (e.hasmoreelements()) {
        asn1objectidentifier oid = (asn1objectidentifier) e.nextelement();
        extension ext = extensions.getextension(oid);

        if (ext.getextnvalue() != null) {
          byte[] octs = ext.getextnvalue().getoctets();
          asn1inputstream din = new asn1inputstream(octs);
          buf.append("                       critical(").append(ext.iscritical()).append(") ");
          try {
            if (oid.equals(extension.basicconstraints)) {
              buf.append(basicconstraints.getinstance(din.readobject())).append(nl);
            } else if (oid.equals(extension.keyusage)) {
              buf.append(keyusage.getinstance(din.readobject())).append(nl);
            } else if (oid.equals(miscobjectidentifiers.netscapecerttype)) {
              buf.append(new netscapecerttype((derbitstring) din.readobject())).append(nl);
            } else if (oid.equals(miscobjectidentifiers.netscaperevocationurl)) {
              buf.append(new netscaperevocationurl((deria5string) din.readobject())).append(nl);
            } else if (oid.equals(miscobjectidentifiers.verisignczagextension)) {
              buf.append(new verisignczagextension((deria5string) din.readobject())).append(nl);
            } else {
              buf.append(oid.getid());
              buf.append(" value = ").append(asn1dump.dumpasstring(din.readobject())).append(nl);
              // buf.append(" value = ").append("*****").append(nl);
            }
          } catch (exception ex) {
            buf.append(oid.getid());
            //     buf.append(" value = ").append(new
            // string(hex.encode(ext.getextnvalue().getoctets()))).append(nl);
            buf.append(" value = ").append("*****").append(nl);
          }
        } else {
          buf.append(nl);
        }
      }
    }

    return buf.tostring();
  }