diff options
author | Mohamed Zenadi <mohamed@zenadi.com> | 2017-07-29 21:21:46 +0100 |
---|---|---|
committer | Mohamed Zenadi <zeapo@users.noreply.github.com> | 2017-08-10 11:10:29 +0200 |
commit | 200fe9ebe0c4017a3e33293e1be981ec0c7a4dd4 (patch) | |
tree | 96bab59945fc3ffdc9c66d573c023b95f98abb09 /app/src/main/java/com/zeapo | |
parent | 7a3caad76f11ae22f2e15d8aee4ee5a7b5a17611 (diff) |
add getkeyids support
Diffstat (limited to 'app/src/main/java/com/zeapo')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt index dabf9f81..5ab023e9 100644 --- a/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt +++ b/app/src/main/java/com/zeapo/pwdstore/crypto/PgpActivity.kt @@ -339,7 +339,45 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { data.putExtra("fromDecrypt", true) intent = data invalidateOptionsMenu() + } + + /** + * Get the Key ids from OpenKeychain + */ + fun getKeyIds() { + val data = Intent() + data.action = OpenPgpApi.ACTION_GET_KEY_IDS + val api = OpenPgpApi(this, mServiceConnection?.getService()) + api.executeApiAsync(data, null, null, { result: Intent? -> + when (result?.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) { + OpenPgpApi.RESULT_CODE_SUCCESS -> { + try { + val ids = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS) + val keys = ids.map { it.toString() }.toSet() + // use Long + settings.edit().putStringSet("openpgp_key_ids_set", keys).apply() + + showToast("PGP keys selected") + + setResult(RESULT_OK) + finish() + } catch (e: Exception) { + Log.e(TAG, "An Exception occurred", e) + } + } + OpenPgpApi.RESULT_CODE_ERROR -> { + // TODO show what kind of error it is + /* For example: + * No suitable key found -> no key in OpenKeyChain + * + * Check in open-pgp-lib how their definitions and error code + */ + val error: OpenPgpError = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR) + handleError(error) + } + } + }) } override fun onError(e: Exception?) {} @@ -348,7 +386,10 @@ class PgpActivity : AppCompatActivity(), OpenPgpServiceConnection.OnBound { * The action to take when the PGP service is bound */ override fun onBound(service: IOpenPgpService2?) { - if (operation in arrayOf("EDIT", "DECRYPT")) decryptAndVerify() + when (operation) { + "EDIT", "DECRYPT" -> decryptAndVerify() + "GET_KEY_ID" -> getKeyIds() + } } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |