Browse Source

PushCertificate: Add toTextWithSignature() method

Change-Id: Ic0129373cc0c0321ffa43dc11a658d4f891ec2c2
stable-4.1
Dave Borowitz 9 years ago
parent
commit
39dc898dca
  1. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java
  2. 17
      org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushCertificateParserTest.java

@ -215,6 +215,7 @@ public class PushCertificateParserTest {
cmd.getNewId().name());
assertEquals(concatPacketLines(INPUT, 0, 6), cert.toText());
assertEquals(concatPacketLines(INPUT, 0, 17), cert.toTextWithSignature());
String signature = concatPacketLines(INPUT, 6, 17);
assertTrue(signature.startsWith(PushCertificateParser.BEGIN_SIGNATURE));

17
org.eclipse.jgit/src/org/eclipse/jgit/transport/PushCertificate.java

@ -203,6 +203,19 @@ public class PushCertificate {
* @since 4.1
*/
public String toText() {
return toStringBuilder().toString();
}
/**
* @return original text payload plus signature; the final output will be
* valid as input to {@link PushCertificateParser#fromString(String)}.
* @since 4.1
*/
public String toTextWithSignature() {
return toStringBuilder().append(signature).toString();
}
private StringBuilder toStringBuilder() {
StringBuilder sb = new StringBuilder()
.append(VERSION).append(' ').append(version).append('\n')
.append(PUSHER).append(' ').append(getPusher())
@ -215,7 +228,7 @@ public class PushCertificate {
.append(' ').append(cmd.getNewId().name())
.append(' ').append(cmd.getRefName()).append('\n');
}
return sb.toString();
return sb;
}
@Override
@ -256,6 +269,6 @@ public class PushCertificate {
@Override
public String toString() {
return getClass().getSimpleName() + '['
+ toText() + signature + ']';
+ toTextWithSignature() + ']';
}
}

Loading…
Cancel
Save