1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-29 07:42:06 +01:00

SOP-CLI: Implement additional version flags

This commit is contained in:
Paul Schaub 2022-01-10 17:11:28 +01:00
parent fc432901ed
commit 19b6c8b1e3
2 changed files with 39 additions and 7 deletions

View file

@ -6,6 +6,7 @@ package org.pgpainless.sop;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.bouncycastle.jce.provider.BouncyCastleProvider;
@ -14,7 +15,7 @@ import sop.operation.Version;
public class VersionImpl implements Version { public class VersionImpl implements Version {
// draft version // draft version
private static final String SOP_VERSION = "3"; private static final String SOP_VERSION = "03";
@Override @Override
public String getName() { public String getName() {
@ -42,16 +43,21 @@ public class VersionImpl implements Version {
@Override @Override
public String getBackendVersion() { public String getBackendVersion() {
double bcVersion = new BouncyCastleProvider().getVersion(); double bcVersion = new BouncyCastleProvider().getVersion();
return String.format("Bouncy Castle %,.2f", bcVersion); return String.format(Locale.US, "Bouncy Castle %.2f", bcVersion);
} }
@Override @Override
public String getExtendedVersion() { public String getExtendedVersion() {
return getName() + " " + getVersion() + "\n" + return getName() + " " + getVersion() + "\n" +
"Based on PGPainless " + getVersion() + "\n" + "https://codeberg.org/PGPainless/pgpainless/src/branch/master/pgpainless-sop\n" +
"Using " + getBackendVersion() + "\n" + "\n" +
"See https://pgpainless.org\n" +
"Implementation of the Stateless OpenPGP Protocol Version " + SOP_VERSION + "\n" + "Implementation of the Stateless OpenPGP Protocol Version " + SOP_VERSION + "\n" +
"See https://datatracker.ietf.org/doc/html/draft-dkg-openpgp-stateless-cli-03"; "https://datatracker.ietf.org/doc/html/draft-dkg-openpgp-stateless-cli-" + SOP_VERSION + "\n" +
"\n" +
"Based on pgpainless-core " + getVersion() + "\n" +
"https://pgpainless.org\n" +
"\n" +
"Using " + getBackendVersion() + "\n" +
"https://www.bouncycastle.org/java.html";
} }
} }

View file

@ -14,6 +14,19 @@ import sop.operation.Version;
exitCodeOnInvalidInput = 37) exitCodeOnInvalidInput = 37)
public class VersionCmd implements Runnable { public class VersionCmd implements Runnable {
@CommandLine.ArgGroup()
Exclusive exclusive;
static class Exclusive {
@CommandLine.Option(names = "--extended", description = "Print an extended version string.")
boolean extended;
@CommandLine.Option(names = "--backend", description = "Print information about the cryptographic backend.")
boolean backend;
}
@Override @Override
public void run() { public void run() {
Version version = SopCLI.getSop().version(); Version version = SopCLI.getSop().version();
@ -21,6 +34,19 @@ public class VersionCmd implements Runnable {
throw new SOPGPException.UnsupportedSubcommand("Command 'version' not implemented."); throw new SOPGPException.UnsupportedSubcommand("Command 'version' not implemented.");
} }
Print.outln(version.getName() + " " + version.getVersion()); if (exclusive == null) {
Print.outln(version.getName() + " " + version.getVersion());
return;
}
if (exclusive.extended) {
Print.outln(version.getExtendedVersion());
return;
}
if (exclusive.backend) {
Print.outln(version.getBackendVersion());
return;
}
} }
} }