mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 18:59:39 +02:00
Kotlin conversion: SignatureVerification
This commit is contained in:
parent
48af91efbf
commit
02511ac1ca
2 changed files with 48 additions and 106 deletions
|
@ -0,0 +1,48 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.decryption_verification
|
||||
|
||||
import org.bouncycastle.openpgp.PGPSignature
|
||||
import org.pgpainless.decryption_verification.SignatureVerification.Failure
|
||||
import org.pgpainless.exception.SignatureValidationException
|
||||
import org.pgpainless.key.SubkeyIdentifier
|
||||
import org.pgpainless.signature.SignatureUtils
|
||||
|
||||
/**
|
||||
* Tuple of a signature and an identifier of its corresponding verification key.
|
||||
* Semantic meaning of the signature verification (success, failure) is merely given by context.
|
||||
* E.g. [MessageMetadata.getVerifiedInlineSignatures] contains verified verifications,
|
||||
* while the class [Failure] contains failed verifications.
|
||||
*
|
||||
* @param signature PGPSignature object
|
||||
* @param signingKey [SubkeyIdentifier] of the (sub-) key that is used for signature verification.
|
||||
* Note, that this might be null, e.g. in case of a [Failure] due to missing verification key.
|
||||
*/
|
||||
data class SignatureVerification(
|
||||
val signature: PGPSignature,
|
||||
val signingKey: SubkeyIdentifier?
|
||||
) {
|
||||
|
||||
override fun toString(): String {
|
||||
return "Signature: ${SignatureUtils.getSignatureDigestPrefix(signature)};" +
|
||||
" Key: ${signingKey?.toString() ?: "null"};"
|
||||
}
|
||||
|
||||
/**
|
||||
* Tuple object of a [SignatureVerification] and the corresponding [SignatureValidationException]
|
||||
* that caused the verification to fail.
|
||||
*
|
||||
* @param signatureVerification verification (tuple of [PGPSignature] and corresponding [SubkeyIdentifier])
|
||||
* @param validationException exception that caused the verification to fail
|
||||
*/
|
||||
data class Failure(
|
||||
val signatureVerification: SignatureVerification,
|
||||
val validationException: SignatureValidationException
|
||||
) {
|
||||
override fun toString(): String {
|
||||
return "$signatureVerification Failure: ${validationException.message}"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue