All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pgpainless.sop.VerificationHelper.kt Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
// SPDX-FileCopyrightText: 2024 Paul Schaub 
//
// SPDX-License-Identifier: Apache-2.0

package org.pgpainless.sop

import org.bouncycastle.openpgp.PGPSignature
import org.pgpainless.decryption_verification.SignatureVerification
import sop.Verification
import sop.enums.SignatureMode

/** Helper class for shared methods related to [Verification] objects. */
class VerificationHelper {

    companion object {

        /**
         * Map a [SignatureVerification] object to a [Verification].
         *
         * @param sigVerification signature verification
         * @return verification
         */
        @JvmStatic
        fun mapVerification(sigVerification: SignatureVerification): Verification =
            Verification(
                sigVerification.signature.creationTime,
                sigVerification.signingKey.subkeyFingerprint.toString(),
                sigVerification.signingKey.primaryKeyFingerprint.toString(),
                getMode(sigVerification.signature),
                null)

        /**
         * Map an OpenPGP signature type to a [SignatureMode] enum. Note: This method only maps
         * [PGPSignature.BINARY_DOCUMENT] and [PGPSignature.CANONICAL_TEXT_DOCUMENT]. Other values
         * are mapped to `null`.
         *
         * @param signature signature
         * @return signature mode enum or null
         */
        @JvmStatic
        fun getMode(signature: PGPSignature): SignatureMode? =
            when (signature.signatureType) {
                PGPSignature.BINARY_DOCUMENT -> SignatureMode.binary
                PGPSignature.CANONICAL_TEXT_DOCUMENT -> SignatureMode.text
                else -> null
            }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy