diff options
| author | Aditya Wasan <adityawasan55@gmail.com> | 2021-08-17 04:14:43 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-17 04:14:43 +0530 |
| commit | b7abd561f561af451ec717746e198a8686d10868 (patch) | |
| tree | 16af9397d205d6501624ba4e98389e21764d9dd3 /crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt | |
| parent | 9982562dc4e1ab4dbd058cf9d3c3c46fc598dec8 (diff) | |
| download | HardenedPass-b7abd561f561af451ec717746e198a8686d10868.tar.gz HardenedPass-b7abd561f561af451ec717746e198a8686d10868.zip | |
Add `KeyPair` and `KeyManager` to manage keys in the app (#1487)
Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt')
| -rw-r--r-- | crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt b/crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt new file mode 100644 index 00000000..2340d9a5 --- /dev/null +++ b/crypto-pgp/src/androidTest/kotlin/dev/msfjarvis/aps/crypto/GPGKeyPairTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.crypto + +import androidx.test.platform.app.InstrumentationRegistry +import com.proton.Gopenpgp.crypto.Key +import dev.msfjarvis.aps.crypto.utils.CryptoConstants +import dev.msfjarvis.aps.cryptopgp.test.R +import dev.msfjarvis.aps.data.crypto.GPGKeyPair +import dev.msfjarvis.aps.data.crypto.KeyPairException +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import org.junit.Test + +public class GPGKeyPairTest { + + @Test + public fun testIfKeyIdIsCorrect() { + val gpgKey = Key(getKey()) + val keyPair = GPGKeyPair(gpgKey) + + assertEquals(CryptoConstants.KEY_ID, keyPair.getKeyId()) + } + + @Test + public fun testBuildingKeyPairWithoutPrivateKey() { + assertFailsWith<KeyPairException.PrivateKeyUnavailableException>( + "GPGKeyPair does not have a private sub key" + ) { + // Get public key object from private key + val gpgKey = Key(getKey()).toPublic() + // Try creating a KeyPair from public key + val keyPair = GPGKeyPair(gpgKey) + + keyPair.getPrivateKey() + } + } + + private companion object { + + fun getKey(): String = + InstrumentationRegistry.getInstrumentation() + .context + .resources + .openRawResource(R.raw.private_key) + .readBytes() + .decodeToString() + } +} |
