1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

version --extended: Include sop-java version

Fixes #454
This commit is contained in:
Paul Schaub 2024-12-21 13:41:37 +01:00
parent 5018386318
commit 4dbc633d7d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -8,6 +8,7 @@ import java.io.IOException
import java.io.InputStream
import java.util.*
import org.bouncycastle.jce.provider.BouncyCastleProvider
import sop.SOP
import sop.operation.Version
/** Implementation of the `version` operation using PGPainless. */
@ -32,7 +33,7 @@ https://datatracker.ietf.org/doc/html/draft-dkg-openpgp-stateless-cli-$specVersi
Based on pgpainless-core ${getVersion()}
https://pgpainless.org
${formatSopJavaVersion()}
Using $bcVersion
https://www.bouncycastle.org/java.html"""
}
@ -49,8 +50,8 @@ https://www.bouncycastle.org/java.html"""
// See https://stackoverflow.com/a/50119235
return try {
val resourceIn: InputStream =
javaClass.getResourceAsStream("/pgpainless-sop.properties")
?: throw IOException("File version.properties not found.")
SOP::class.java.getResourceAsStream("/pgpainless-sop.properties")
?: throw IOException("File pgpainless-sop.properties not found.")
val properties = Properties().apply { load(resourceIn) }
properties.getProperty("pgpainless-sop-version")
@ -59,5 +60,29 @@ https://www.bouncycastle.org/java.html"""
}
}
private fun formatSopJavaVersion(): String {
return getSopJavaVersion()?.let {
"""
sop-java $it
"""
.trimIndent()
}
?: ""
}
private fun getSopJavaVersion(): String? {
return try {
val resourceIn: InputStream =
javaClass.getResourceAsStream("/sop-java-version.properties")
?: throw IOException("File sop-java-version.properties not found.")
val properties = Properties().apply { load(resourceIn) }
properties.getProperty("sop-java-version")
} catch (e: IOException) {
null
}
}
override fun isSopSpecImplementationIncomplete(): Boolean = false
}