From 8425665fa7f5a954002325d7a68fc72882722fdc Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 14 Apr 2023 15:56:52 +0200 Subject: [PATCH] Expose SOP revision info more fine-grained --- .../external/operation/VersionExternal.java | 36 +++++++++++++ .../src/main/java/sop/operation/Version.java | 53 ++++++++++++++++++- .../sop/testsuite/operation/VersionTest.java | 11 +++- 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/external-sop/src/main/java/sop/external/operation/VersionExternal.java b/external-sop/src/main/java/sop/external/operation/VersionExternal.java index 95dc8f5..3b21792 100644 --- a/external-sop/src/main/java/sop/external/operation/VersionExternal.java +++ b/external-sop/src/main/java/sop/external/operation/VersionExternal.java @@ -100,6 +100,42 @@ public class VersionExternal implements Version { } } + @Override + public int getSopSpecVersionNumber() { + String revision = getSopSpecVersion(); + String firstLine; + if (revision.contains("\n")) { + firstLine = revision.substring(0, revision.indexOf("\n")); + } else { + firstLine = revision; + } + + if (!firstLine.contains("-")) { + return -1; + } + + return Integer.parseInt(firstLine.substring(firstLine.lastIndexOf("-") + 1)); + } + + @Override + public boolean isSopSpecImplementationIncomplete() { + String revision = getSopSpecVersion(); + return revision.startsWith("~"); + } + + @Override + public String getSopSpecImplementationIncompletenessRemarks() { + String revision = getSopSpecVersion(); + if (revision.contains("\n")) { + String tail = revision.substring(revision.indexOf("\n") + 1).trim(); + + if (!tail.isEmpty()) { + return tail; + } + } + return null; + } + @Override public String getSopSpecVersion() { String[] command = new String[] {binary, "version", "--sop-spec"}; diff --git a/sop-java/src/main/java/sop/operation/Version.java b/sop-java/src/main/java/sop/operation/Version.java index 1cd2698..95b2fe1 100644 --- a/sop-java/src/main/java/sop/operation/Version.java +++ b/sop-java/src/main/java/sop/operation/Version.java @@ -47,13 +47,62 @@ public interface Version { */ String getExtendedVersion(); + /** + * Return the version number of the latest targeted SOP spec revision. + * + * @return SOP spec revision number + */ + int getSopSpecVersionNumber(); + + /** + * Return the latest targeted revision of the SOP spec. + * + * @return SOP spec revision string + */ + default String getSopSpecRevisionString() { + return "draft-dkg-openpgp-stateless-cli-" + String.format("%02d", getSopSpecVersionNumber()); + } + + /** + * Return
true
, if this implementation of the SOP spec is known to be incomplete or defective. + * + * @return true if incomplete, false otherwise + */ + boolean isSopSpecImplementationIncomplete(); + + /** + * Return free-form text containing remarks about the completeness of the SOP implementation. + * If no remarks are known, this method returns
null
. + * + * @return remarks or null + */ + String getSopSpecImplementationIncompletenessRemarks(); + /** * Return the revision of the SOP specification that this implementation is implementing, for example, *
draft-dkg-openpgp-stateless-cli-06
. * If the implementation targets a specific draft but the implementer knows the implementation is incomplete, - * it should prefix the draft title with a "~" (TILDE, U+007E), for example:
~draft-dkg-openpgp-stateless-cli-06
. + * it should prefix the draft title with a "~" (TILDE, U+007E), for example: + *
~draft-dkg-openpgp-stateless-cli-06
. + * The implementation MAY emit additional text about its relationship to the targeted draft on the lines following + * the versioned title. * * @return implemented SOP spec version */ - String getSopSpecVersion(); + default String getSopSpecVersion() { + StringBuilder sb = new StringBuilder(); + if (isSopSpecImplementationIncomplete()) { + sb.append('~'); + } + + sb.append(getSopSpecRevisionString()); + + if (getSopSpecImplementationIncompletenessRemarks() != null) { + sb.append('\n') + .append('\n') + .append(getSopSpecImplementationIncompletenessRemarks()); + } + + return sb.toString(); + } } diff --git a/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java b/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java index 5ad1a52..8dc958e 100644 --- a/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java +++ b/sop-java/src/testFixtures/java/sop/testsuite/operation/VersionTest.java @@ -14,6 +14,7 @@ import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @EnabledIf("sop.testsuite.operation.AbstractSOPTest#hasBackends") @@ -56,7 +57,13 @@ public class VersionTest extends AbstractSOPTest { @MethodSource("provideInstances") public void sopSpecVersionTest(SOP sop) { String sopSpec = sop.version().getSopSpecVersion(); - assertTrue(sopSpec.startsWith("draft-dkg-openpgp-stateless-cli-") || - sopSpec.startsWith("~draft-dkg-openpgp-stateless-cli-")); + if (sop.version().isSopSpecImplementationIncomplete()) { + assertTrue(sopSpec.startsWith("~draft-dkg-openpgp-stateless-cli-")); + } else { + assertTrue(sopSpec.startsWith("draft-dkg-openpgp-stateless-cli-")); + } + + int sopRevision = sop.version().getSopSpecVersionNumber(); + assertTrue(sop.version().getSopSpecRevisionString().endsWith("" + sopRevision)); } }