コード例 #1
0
  public void encode(OutputStream outStream) throws IOException {
    BCPGOutputStream out;

    if (outStream instanceof BCPGOutputStream) {
      out = (BCPGOutputStream) outStream;
    } else {
      out = new BCPGOutputStream(outStream);
    }

    out.writePacket(secret);
    if (pub.trustPk != null) {
      out.writePacket(pub.trustPk);
    }

    if (pub.subSigs == null) // is not a sub key
    {
      for (int i = 0; i != pub.keySigs.size(); i++) {
        ((PGPSignature) pub.keySigs.get(i)).encode(out);
      }

      for (int i = 0; i != pub.ids.size(); i++) {
        if (pub.ids.get(i) instanceof UserIDPacket) {
          UserIDPacket id = (UserIDPacket) pub.ids.get(i);

          out.writePacket(id);
        } else {
          PGPUserAttributeSubpacketVector v = (PGPUserAttributeSubpacketVector) pub.ids.get(i);

          out.writePacket(new UserAttributePacket(v.toSubpacketArray()));
        }

        if (pub.idTrusts.get(i) != null) {
          out.writePacket((ContainedPacket) pub.idTrusts.get(i));
        }

        List sigs = (ArrayList) pub.idSigs.get(i);

        for (int j = 0; j != sigs.size(); j++) {
          ((PGPSignature) sigs.get(j)).encode(out);
        }
      }
    } else {
      for (int j = 0; j != pub.subSigs.size(); j++) {
        ((PGPSignature) pub.subSigs.get(j)).encode(out);
      }
    }
  }