mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 18:29:48 +02:00
Compare commits
No commits in common. "038a68f93cef7f060d3ebd420c9abf69db21a336" and "b66888f695837b238e67d551fc454d846f078642" have entirely different histories.
038a68f93c
...
b66888f695
2 changed files with 4 additions and 87 deletions
|
@ -45,12 +45,12 @@ public final class VerificationAssert {
|
||||||
}
|
}
|
||||||
|
|
||||||
public VerificationAssert hasDescription(String description) {
|
public VerificationAssert hasDescription(String description) {
|
||||||
assertEquals(description, verification.getJsonOrDescription().get());
|
assertEquals(description, verification.getDescription().get());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VerificationAssert hasDescriptionOrNull(String description) {
|
public VerificationAssert hasDescriptionOrNull(String description) {
|
||||||
if (verification.getJsonOrDescription().isEmpty()) {
|
if (verification.getDescription().isEmpty()) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,8 @@ data class Verification(
|
||||||
val signingKeyFingerprint: String,
|
val signingKeyFingerprint: String,
|
||||||
val signingCertFingerprint: String,
|
val signingCertFingerprint: String,
|
||||||
val signatureMode: Optional<SignatureMode>,
|
val signatureMode: Optional<SignatureMode>,
|
||||||
val jsonOrDescription: Optional<String>
|
val description: Optional<String>
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(
|
constructor(
|
||||||
creationTime: Date,
|
creationTime: Date,
|
||||||
|
@ -32,48 +31,10 @@ data class Verification(
|
||||||
Optional.ofNullable(signatureMode),
|
Optional.ofNullable(signatureMode),
|
||||||
Optional.ofNullable(description?.trim()))
|
Optional.ofNullable(description?.trim()))
|
||||||
|
|
||||||
@JvmOverloads
|
|
||||||
constructor(
|
|
||||||
creationTime: Date,
|
|
||||||
signingKeyFingerprint: String,
|
|
||||||
signingCertFingerprint: String,
|
|
||||||
signatureMode: SignatureMode? = null,
|
|
||||||
json: JSON,
|
|
||||||
jsonSerializer: JSONSerializer
|
|
||||||
) : this(
|
|
||||||
creationTime,
|
|
||||||
signingKeyFingerprint,
|
|
||||||
signingCertFingerprint,
|
|
||||||
Optional.ofNullable(signatureMode),
|
|
||||||
Optional.of(jsonSerializer.serialize(json)))
|
|
||||||
|
|
||||||
@Deprecated("Replaced by jsonOrDescription",
|
|
||||||
replaceWith = ReplaceWith("jsonOrDescription")
|
|
||||||
)
|
|
||||||
val description = jsonOrDescription
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attempt to parse the [jsonOrDescription] field using the provided [JSONParser] and return the result.
|
|
||||||
* This method returns `null` if parsing fails.
|
|
||||||
*
|
|
||||||
* @param parser [JSONParser] implementation
|
|
||||||
* @return successfully parsed [JSON] POJO or `null`.
|
|
||||||
*/
|
|
||||||
fun getJson(parser: JSONParser): JSON? {
|
|
||||||
return jsonOrDescription.get()
|
|
||||||
?.let {
|
|
||||||
try {
|
|
||||||
parser.parse(it)
|
|
||||||
} catch (e: ParseException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
"${UTCUtil.formatUTCDate(creationTime)} $signingKeyFingerprint $signingCertFingerprint" +
|
"${UTCUtil.formatUTCDate(creationTime)} $signingKeyFingerprint $signingCertFingerprint" +
|
||||||
(if (signatureMode.isPresent) " mode:${signatureMode.get()}" else "") +
|
(if (signatureMode.isPresent) " mode:${signatureMode.get()}" else "") +
|
||||||
(if (jsonOrDescription.isPresent) " ${jsonOrDescription.get()}" else "")
|
(if (description.isPresent) " ${description.get()}" else "")
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -112,48 +73,4 @@ data class Verification(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* POJO data class representing JSON metadata.
|
|
||||||
*
|
|
||||||
* @param signers list of supplied CERTS objects that could have issued the signature, identified by
|
|
||||||
* the name given on the command line.
|
|
||||||
* @param comment a freeform UTF-8 encoded text describing the verification
|
|
||||||
* @param ext an extension object containing arbitrary, implementation-specific data
|
|
||||||
*/
|
|
||||||
data class JSON(
|
|
||||||
val signers: List<String>,
|
|
||||||
val comment: String?,
|
|
||||||
val ext: Any?)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface abstracting a JSON parser that parses [JSON] POJOs from single-line strings.
|
|
||||||
*/
|
|
||||||
fun interface JSONParser {
|
|
||||||
/**
|
|
||||||
* Parse a [JSON] POJO from the given single-line [string].
|
|
||||||
* If the string does not represent a JSON object matching the [JSON] definition,
|
|
||||||
* this method throws a [ParseException].
|
|
||||||
*
|
|
||||||
* @param string [String] representation of the [JSON] object.
|
|
||||||
* @return parsed [JSON] POJO
|
|
||||||
* @throws ParseException if the [string] is not a JSON string representing the [JSON] object.
|
|
||||||
*/
|
|
||||||
@Throws(ParseException::class)
|
|
||||||
fun parse(string: String): JSON
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interface abstracting a JSON serializer that converts [JSON] POJOs into single-line JSON strings.
|
|
||||||
*/
|
|
||||||
fun interface JSONSerializer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Serialize the given [JSON] object into a single-line JSON string.
|
|
||||||
*
|
|
||||||
* @param json JSON POJO
|
|
||||||
* @return JSON string
|
|
||||||
*/
|
|
||||||
fun serialize(json: JSON): String
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue