@@ -452,21 +452,78 @@ protected String getType()
452
452
public String toAsciiArmoredString ()
453
453
throws IOException
454
454
{
455
- ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
456
- ArmoredOutputStream .Builder aBuilder = ArmoredOutputStream .builder ()
455
+ return toAsciiArmoredString (PacketFormat .ROUNDTRIP );
456
+ }
457
+
458
+ /**
459
+ * Return an ASCII armored String representation of the signature.
460
+ * If the signature contains issuer information, the fingerprint or key-id of the issuer will be added
461
+ * to the ASCII armor as a comment header.
462
+ *
463
+ * @param packetFormat decide, which packet format to use when encoding the signature
464
+ * @return ASCII armored signature
465
+ * @throws IOException if the signature cannot be encoded
466
+ */
467
+ public String toAsciiArmoredString (PacketFormat packetFormat )
468
+ throws IOException
469
+ {
470
+ ArmoredOutputStream .Builder armorBuilder = ArmoredOutputStream .builder ()
457
471
.clearHeaders ();
458
472
if (getKeyIdentifier () != null )
459
473
{
460
- aBuilder .addSplitMultilineComment (getKeyIdentifier ().toPrettyPrint ());
474
+ armorBuilder .addSplitMultilineComment (getKeyIdentifier ().toPrettyPrint ());
461
475
}
462
- ArmoredOutputStream aOut = aBuilder .build (bOut );
463
- BCPGOutputStream pOut = new BCPGOutputStream (aOut , PacketFormat .CURRENT );
464
- getSignature ().encode (pOut );
465
- pOut .close ();
476
+ return toAsciiArmoredString (packetFormat , armorBuilder );
477
+ }
478
+
479
+ /**
480
+ * Return an ASCII armored String representation of the signature.
481
+ * The ASCII armor can be configured using the passed {@link ArmoredOutputStream.Builder}.
482
+ *
483
+ * @param packetFormat decide, which packet format to use when encoding the signature
484
+ * @param armorBuilder builder for the ASCII armored output stream
485
+ * @return ASCII armored signature
486
+ * @throws IOException if the signature cannot be encoded
487
+ */
488
+ public String toAsciiArmoredString (PacketFormat packetFormat , ArmoredOutputStream .Builder armorBuilder )
489
+ throws IOException
490
+ {
491
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
492
+ ArmoredOutputStream aOut = armorBuilder .build (bOut );
493
+ aOut .write (getEncoded (packetFormat ));
466
494
aOut .close ();
467
495
return bOut .toString ();
468
496
}
469
497
498
+ /**
499
+ * Return the binary encoding of the signature.
500
+ *
501
+ * @return binary encoding
502
+ * @throws IOException if the signature cannot be encoded
503
+ */
504
+ public byte [] getEncoded ()
505
+ throws IOException
506
+ {
507
+ return getEncoded (PacketFormat .ROUNDTRIP );
508
+ }
509
+
510
+ /**
511
+ * Return the binary encoding of the signature.
512
+ *
513
+ * @param packetFormat decide, which packet format to use when encoding the signature
514
+ * @return binary encoding
515
+ * @throws IOException if the signature cannot be encoded
516
+ */
517
+ public byte [] getEncoded (PacketFormat packetFormat )
518
+ throws IOException
519
+ {
520
+ ByteArrayOutputStream bOut = new ByteArrayOutputStream ();
521
+ BCPGOutputStream pOut = new BCPGOutputStream (bOut , packetFormat );
522
+ signature .encode (pOut );
523
+ pOut .close ();
524
+ return bOut .toByteArray ();
525
+ }
526
+
470
527
/**
471
528
* {@link SignatureSubpacket} and the {@link OpenPGPSignature} that contains it.
472
529
*/
0 commit comments