/**
   * @param sigType specifies the type of the Signature
   * @param pubKeyAlgo specifies the used PublicKey Algorithm, has to be the same as in the first
   *     public key
   * @param hashAlgo specifies the type of Hash Alogrithm used
   * @param hashedSubPackets is an ArrayList<SignatureSubPacket> of all SignatureSubPacket which are
   *     to be hashed
   * @param unHashedSubPackets is an ArrayList<SignatureSubPacket> of all SignatureSubPacket which
   *     are NOT to be hashed
   */
  public SignaturePacket(
      int version,
      SignatureTypes sigType,
      PubKeyAlgos pubKeyAlgo,
      HashAlgorithms hashAlgo,
      ArrayList<SignatureSubPacket> hashedSubPackets,
      ArrayList<SignatureSubPacket> unHashedSubPackets,
      byte[] payload,
      Packet pack,
      PubKeyPacket pubKey) {
    this.version = version;
    this.unHashedSubPackets = unHashedSubPackets;
    this.hashedSubPackets = hashedSubPackets;
    bSetVersionNum((byte) version);

    /*
     * set keyid
     */
    this.keyID = pubKey.getKeyID();

    // md is used for the signature generation
    MessageDigest md = null; // create a new instance of an messagedigest
    try {
      md = MessageDigest.getInstance(hashAlgo.toString());
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      System.err.println(
          "This cannot hapen, since only supported hashAlgos are specified in HashAlgorithms class");
    }

    if (version == 3) {
      body.add((byte) 0x05); // fix size of 5 for hashed material

      body.add((byte) sigType.getNum()); // wirte signature type

      body.add((byte) 0x01); // begin creation time
      body.add((byte) 0x02);
      body.add((byte) 0x03);
      body.add((byte) 0x04); // end creation time

      for (int i = 0; i < 8; i++) { // add 8 byte key id
        body.add((byte) pubKey.getKeyID()[i]);
      }

      body.add((byte) pubKeyAlgo.getNum()); // public-key algorithm
      body.add((byte) hashAlgo.getNum()); // hash algorithm

    } else if (version == 4) {
      bSetSigType(sigType);
      bSetPubKeyAlgo(pubKeyAlgo);
      bsetHashAlgo(hashAlgo);

      System.out.println("before scalar hashedsubPackets: " + Arrays.toString(this.getBody()));
      bWriteScalar(hashedSubPackets);
      System.out.println("before  hashedsubPackets: " + Arrays.toString(this.getBody()));
      bWriteSubPackets(hashedSubPackets);
      bOffsetSizeUnhashed = body.size();
      System.out.println("before scalar U N hashedsubPackets: " + Arrays.toString(this.getBody()));
      bWriteScalar(unHashedSubPackets);
      System.out.println("before U N hashedsubPackets: " + Arrays.toString(this.getBody()));
      bWriteSubPackets(unHashedSubPackets);

    } else {
      System.err.println("signature pack generation invalid verion number speicified");
    }

    bWriteSignature(md, sigType, pack);

    // body is complete
    // add header to whole
    head = new Header(PacketTags.SIG, body.size());
    for (int i = 0; i < head.getLength(); i++) {
      whole.add((byte) head.getWholeHeader()[i]);
    }
    System.out.println("header of signature: " + Util.ByteArr2String(getWholePacket()));

    // add body to whole
    for (int i = 0; i < body.size(); i++) {
      whole.add(body.get(i));
    }
    System.out.println("whole package: " + Util.ByteArr2String(getWholePacket()));
  }
 private void bSetPubKeyAlgo(PubKeyAlgos pubKeyAlgo) {
   this.body.add(pubKeyAlgo.getNum());
 }