Expose SOP revision info more fine-grained

This commit is contained in:
Paul Schaub 2023-04-14 15:56:52 +02:00
parent 90c77706a8
commit 8425665fa7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 96 additions and 4 deletions

View file

@ -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"};

View file

@ -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 <pre>true</pre>, 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 <pre>null</pre>.
*
* @return remarks or null
*/
String getSopSpecImplementationIncompletenessRemarks();
/**
* Return the revision of the SOP specification that this implementation is implementing, for example,
* <pre>draft-dkg-openpgp-stateless-cli-06</pre>.
* 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: <pre>~draft-dkg-openpgp-stateless-cli-06</pre>.
* it should prefix the draft title with a "~" (TILDE, U+007E), for example:
* <pre>~draft-dkg-openpgp-stateless-cli-06</pre>.
* 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();
}
}

View file

@ -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));
}
}