diff options
| author | Harsh Shandilya <me@msfjarvis.dev> | 2023-08-10 03:21:47 +0530 |
|---|---|---|
| committer | Harsh Shandilya <me@msfjarvis.dev> | 2023-08-10 03:31:08 +0530 |
| commit | 959a56d7ffbc20db60721d7a09f399c8bdefe07e (patch) | |
| tree | 0d9b14e0bb770fd6da2e04295f2c22c087142439 /crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt | |
| parent | efef72b6327c8e683c8844146e23d12104f12dd1 (diff) | |
| download | HardenedPass-959a56d7ffbc20db60721d7a09f399c8bdefe07e.tar.gz HardenedPass-959a56d7ffbc20db60721d7a09f399c8bdefe07e.zip | |
refactor: un-flatten module structure
Diffstat (limited to 'crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt')
| -rw-r--r-- | crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt b/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt deleted file mode 100644 index 5b23dc18..00000000 --- a/crypto-pgpainless/src/main/kotlin/app/passwordstore/crypto/KeyUtils.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved. - * SPDX-License-Identifier: GPL-3.0-only - */ - -package app.passwordstore.crypto - -import app.passwordstore.crypto.PGPIdentifier.KeyId -import app.passwordstore.crypto.PGPIdentifier.UserId -import com.github.michaelbull.result.get -import com.github.michaelbull.result.runCatching -import org.bouncycastle.openpgp.PGPKeyRing -import org.pgpainless.PGPainless -import org.pgpainless.key.parsing.KeyRingReader - -/** Utility methods to deal with [PGPKey]s. */ -public object KeyUtils { - /** - * Attempts to parse a [PGPKeyRing] from a given [key]. The key is first tried as a secret key and - * then as a public one before the method gives up and returns null. - */ - public fun tryParseKeyring(key: PGPKey): PGPKeyRing? { - return runCatching { KeyRingReader.readKeyRing(key.contents.inputStream()) }.get() - } - - /** Parses a [PGPKeyRing] from the given [key] and calculates its long key ID */ - public fun tryGetId(key: PGPKey): KeyId? { - val keyRing = tryParseKeyring(key) ?: return null - return KeyId(keyRing.publicKey.keyID) - } - - /** - * Attempts to parse the given [PGPKey] into a [PGPKeyRing] and obtains the [UserId] of the - * corresponding public key. - */ - public fun tryGetEmail(key: PGPKey): UserId? { - val keyRing = tryParseKeyring(key) ?: return null - return UserId(keyRing.publicKey.userIDs.next()) - } - - /** - * Tests if the given [key] can be used for encryption, which is a bare minimum necessity for the - * app. - */ - public fun isKeyUsable(key: PGPKey): Boolean { - return runCatching { - val keyRing = tryParseKeyring(key) ?: return false - PGPainless.inspectKeyRing(keyRing).isUsableForEncryption - } - .get() != null - } -} |
