summaryrefslogtreecommitdiff
path: root/crypto/pgpainless
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/pgpainless')
-rw-r--r--crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt8
-rw-r--r--crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt6
2 files changed, 14 insertions, 0 deletions
diff --git a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
index 8aa11803..41a797b6 100644
--- a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
+++ b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPKeyManager.kt
@@ -139,6 +139,14 @@ constructor(
/** @see KeyManager.getKeyById */
override suspend fun getKeyId(key: PGPKey): PGPIdentifier? = tryGetId(key)
+ public suspend fun isPasswordProtected(key: PGPKey): Boolean {
+ val keyring = tryParseKeyring(key)
+ if (keyring is PGPSecretKeyRing) {
+ keyring.secretKey.keyEncryptionAlgorithm
+ }
+ return false
+ }
+
/** Checks if [keyDir] exists and attempts to create it if not. */
private fun keyDirExists(): Boolean {
return keyDir.exists() || keyDir.mkdirs()
diff --git a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
index a7087acf..72baa81a 100644
--- a/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
+++ b/crypto/pgpainless/src/main/kotlin/app/passwordstore/crypto/PGPainlessCryptoHandler.kt
@@ -22,6 +22,7 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection
import org.bouncycastle.util.io.Streams
import org.pgpainless.PGPainless
import org.pgpainless.decryption_verification.ConsumerOptions
+import org.pgpainless.decryption_verification.MessageInspector
import org.pgpainless.encryption_signing.EncryptionOptions
import org.pgpainless.encryption_signing.ProducerOptions
import org.pgpainless.exception.WrongPassphraseException
@@ -136,4 +137,9 @@ public class PGPainlessCryptoHandler @Inject constructor() :
public override fun canHandle(fileName: String): Boolean {
return fileName.substringAfterLast('.', "") == "gpg"
}
+
+ public override fun isPassphraseProtected(message: InputStream): Boolean {
+ val info = MessageInspector.determineEncryptionInfoForMessage(message)
+ return info.isPassphraseEncrypted
+ }
}