aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-08-10 22:02:44 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2015-08-10 22:02:44 +0200
commit68cec0197f3679c9dc773719d90013b2bb3f5b63 (patch)
treef25e5ee66c3f1ce158928f48af3fb42af05ce3d9
parent306b94b07e0276f23737db439ba085946a9d4f5d (diff)
downloadopenpgp-api-68cec0197f3679c9dc773719d90013b2bb3f5b63.tar.gz
openpgp-api-68cec0197f3679c9dc773719d90013b2bb3f5b63.tar.bz2
openpgp-api-68cec0197f3679c9dc773719d90013b2bb3f5b63.zip
Update example to API 8
-rw-r--r--example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java133
1 files changed, 49 insertions, 84 deletions
diff --git a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java
index f0b8a46..573e34d 100644
--- a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java
+++ b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java
@@ -31,6 +31,7 @@ import android.widget.EditText;
import android.widget.Toast;
import org.openintents.openpgp.IOpenPgpService;
+import org.openintents.openpgp.OpenPgpDecryptionResult;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi;
@@ -47,16 +48,7 @@ public class OpenPgpApiActivity extends Activity {
private EditText mCiphertext;
private EditText mDetachedSignature;
private EditText mEncryptUserIds;
- private Button mCleartextSign;
- private Button mDetachedSign;
- private Button mEncrypt;
- private Button mSignAndEncrypt;
- private Button mDecryptAndVerify;
- private Button mVerifyDetachedSignature;
private EditText mGetKeyEdit;
- private EditText mGetKeyIdsEdit;
- private Button mGetKey;
- private Button mGetKeyIds;
private OpenPgpServiceConnection mServiceConnection;
@@ -80,60 +72,60 @@ public class OpenPgpApiActivity extends Activity {
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
mDetachedSignature = (EditText) findViewById(R.id.crypto_provider_demo_detached_signature);
mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
- mCleartextSign = (Button) findViewById(R.id.crypto_provider_demo_cleartext_sign);
- mDetachedSign = (Button) findViewById(R.id.crypto_provider_demo_detached_sign);
- mEncrypt = (Button) findViewById(R.id.crypto_provider_demo_encrypt);
- mSignAndEncrypt = (Button) findViewById(R.id.crypto_provider_demo_sign_and_encrypt);
- mDecryptAndVerify = (Button) findViewById(R.id.crypto_provider_demo_decrypt_and_verify);
- mVerifyDetachedSignature = (Button) findViewById(R.id.crypto_provider_demo_verify_detached_signature);
+ Button cleartextSign = (Button) findViewById(R.id.crypto_provider_demo_cleartext_sign);
+ Button detachedSign = (Button) findViewById(R.id.crypto_provider_demo_detached_sign);
+ Button encrypt = (Button) findViewById(R.id.crypto_provider_demo_encrypt);
+ Button signAndEncrypt = (Button) findViewById(R.id.crypto_provider_demo_sign_and_encrypt);
+ Button decryptAndVerify = (Button) findViewById(R.id.crypto_provider_demo_decrypt_and_verify);
+ Button verifyDetachedSignature = (Button) findViewById(R.id.crypto_provider_demo_verify_detached_signature);
mGetKeyEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_edit);
- mGetKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit);
- mGetKey = (Button) findViewById(R.id.crypto_provider_demo_get_key);
- mGetKeyIds = (Button) findViewById(R.id.crypto_provider_demo_get_key_ids);
+ EditText getKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit);
+ Button getKey = (Button) findViewById(R.id.crypto_provider_demo_get_key);
+ Button getKeyIds = (Button) findViewById(R.id.crypto_provider_demo_get_key_ids);
- mCleartextSign.setOnClickListener(new View.OnClickListener() {
+ cleartextSign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cleartextSign(new Intent());
}
});
- mDetachedSign.setOnClickListener(new View.OnClickListener() {
+ detachedSign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
detachedSign(new Intent());
}
});
- mEncrypt.setOnClickListener(new View.OnClickListener() {
+ encrypt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
encrypt(new Intent());
}
});
- mSignAndEncrypt.setOnClickListener(new View.OnClickListener() {
+ signAndEncrypt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signAndEncrypt(new Intent());
}
});
- mDecryptAndVerify.setOnClickListener(new View.OnClickListener() {
+ decryptAndVerify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
decryptAndVerify(new Intent());
}
});
- mVerifyDetachedSignature.setOnClickListener(new View.OnClickListener() {
+ verifyDetachedSignature.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
decryptAndVerifyDetached(new Intent());
}
});
- mGetKey.setOnClickListener(new View.OnClickListener() {
+ getKey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getKey(new Intent());
}
});
- mGetKeyIds.setOnClickListener(new View.OnClickListener() {
+ getKeyIds.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getKeyIds(new Intent());
@@ -198,9 +190,6 @@ public class OpenPgpApiActivity extends Activity {
/**
* Takes input from message or ciphertext EditText and turns it into a ByteArrayInputStream
- *
- * @param ciphertext
- * @return
*/
private InputStream getInputstream(boolean ciphertext) {
InputStream is = null;
@@ -252,58 +241,43 @@ public class OpenPgpApiActivity extends Activity {
}
}
- // detached sign
- if (result.hasExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE)) {
- byte[] detachedSig
- = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
- Log.d(OpenPgpApi.TAG, "RESULT_DETACHED_SIGNATURE: " + detachedSig.length
- + " str=" + new String(detachedSig));
- mDetachedSignature.setText(new String(detachedSig));
- }
+ switch (requestCode) {
+ case REQUEST_CODE_DECRYPT_AND_VERIFY: {
+ // RESULT_SIGNATURE and RESULT_DECRYPTION are never null!
- if (result.hasExtra(OpenPgpApi.RESULT_TYPE)) {
- int resultType = result.getIntExtra(OpenPgpApi.RESULT_TYPE, -1);
- switch (resultType) {
- case OpenPgpApi.RESULT_TYPE_UNENCRYPTED_UNSIGNED: {
- Log.d(Constants.TAG, "unencrypted, unsigned");
- break;
- }
- case OpenPgpApi.RESULT_TYPE_ENCRYPTED: {
- Log.d(Constants.TAG, "encrypted only");
- break;
- }
- case OpenPgpApi.RESULT_TYPE_SIGNED: {
- Log.d(Constants.TAG, "signed only");
- break;
- }
- case (OpenPgpApi.RESULT_TYPE_ENCRYPTED | OpenPgpApi.RESULT_TYPE_SIGNED): {
- Log.d(Constants.TAG, "encrypted + signed");
- break;
- }
- default: {
- Log.d(Constants.TAG, "no type recognized!");
- break;
- }
- }
- }
+ OpenPgpSignatureResult signatureResult
+ = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
+ showToast(signatureResult.toString());
+ OpenPgpDecryptionResult decryptionResult
+ = result.getParcelableExtra(OpenPgpApi.RESULT_DECRYPTION);
+ showToast(decryptionResult.toString());
- // verify
- if (result.hasExtra(OpenPgpApi.RESULT_SIGNATURE)) {
- OpenPgpSignatureResult sigResult
- = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);
- showToast(sigResult.toString());
- }
+ break;
+ }
+ case REQUEST_CODE_DECRYPT_AND_VERIFY_DETACHED: {
+ byte[] detachedSig
+ = result.getByteArrayExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE);
+ Log.d(OpenPgpApi.TAG, "RESULT_DETACHED_SIGNATURE: " + detachedSig.length
+ + " str=" + new String(detachedSig));
+ mDetachedSignature.setText(new String(detachedSig));
+
+ break;
+ }
+ case REQUEST_CODE_GET_KEY_IDS: {
+ long[] keyIds = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS);
+ String out = "keyIds: ";
+ for (long keyId : keyIds) {
+ out += OpenPgpUtils.convertKeyIdToHex(keyId) + ", ";
+ }
+ showToast(out);
- // get key ids
- if (result.hasExtra(OpenPgpApi.RESULT_KEY_IDS)) {
- long[] keyIds = result.getLongArrayExtra(OpenPgpApi.RESULT_KEY_IDS);
- String out = "keyIds: ";
- for (int i = 0; i < keyIds.length; i++) {
- out += OpenPgpUtils.convertKeyIdToHex(keyIds[i]) + ", ";
+ break;
}
+ default: {
- showToast(out);
+ }
}
+
break;
}
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {
@@ -333,7 +307,6 @@ public class OpenPgpApiActivity extends Activity {
public void cleartextSign(Intent data) {
data.setAction(OpenPgpApi.ACTION_CLEARTEXT_SIGN);
data.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mSignKeyId);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
InputStream is = getInputstream(false);
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -345,7 +318,6 @@ public class OpenPgpApiActivity extends Activity {
public void detachedSign(Intent data) {
data.setAction(OpenPgpApi.ACTION_DETACHED_SIGN);
data.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, mSignKeyId);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
InputStream is = getInputstream(false);
// no output stream needed, detached signature is returned as RESULT_DETACHED_SIGNATURE
@@ -360,7 +332,6 @@ public class OpenPgpApiActivity extends Activity {
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, mEncryptUserIds.getText().toString().split(","));
}
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
InputStream is = getInputstream(false);
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -376,7 +347,6 @@ public class OpenPgpApiActivity extends Activity {
data.putExtra(OpenPgpApi.EXTRA_USER_IDS, mEncryptUserIds.getText().toString().split(","));
}
data.putExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR, true);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
InputStream is = getInputstream(false);
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -387,7 +357,6 @@ public class OpenPgpApiActivity extends Activity {
public void decryptAndVerify(Intent data) {
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
InputStream is = getInputstream(true);
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -398,7 +367,6 @@ public class OpenPgpApiActivity extends Activity {
public void decryptAndVerifyDetached(Intent data) {
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
data.putExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE, mDetachedSignature.getText().toString().getBytes());
// use from text from mMessage
@@ -410,7 +378,6 @@ public class OpenPgpApiActivity extends Activity {
public void getKey(Intent data) {
data.setAction(OpenPgpApi.ACTION_GET_KEY);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
data.putExtra(OpenPgpApi.EXTRA_KEY_ID, Long.decode(mGetKeyEdit.getText().toString()));
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
@@ -419,7 +386,6 @@ public class OpenPgpApiActivity extends Activity {
public void getKeyIds(Intent data) {
data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS));
@@ -427,7 +393,6 @@ public class OpenPgpApiActivity extends Activity {
public void getAnyKeyIds(Intent data) {
data.setAction(OpenPgpApi.ACTION_GET_KEY_IDS);
-// data.putExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME, mAccount.getText().toString());
// data.putExtra(OpenPgpApi.EXTRA_USER_IDS, mGetKeyIdsEdit.getText().toString().split(","));
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());