aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/thialfihar/android/apg/ApgService.java
diff options
context:
space:
mode:
authorMarkus Doits <markus.doits@gmail.com>2011-01-05 14:07:09 +0000
committerMarkus Doits <markus.doits@gmail.com>2011-01-05 14:07:09 +0000
commit1a338de47e7d9faa73a3bc6eda51cb47a18dc91b (patch)
tree3184c203a6bae8922c6cc555edf7356dc7b337cc /src/org/thialfihar/android/apg/ApgService.java
parentdbb46f1633b94aa7be39ebb8f4acc24a3420083f (diff)
downloadopen-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.tar.gz
open-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.tar.bz2
open-keychain-1a338de47e7d9faa73a3bc6eda51cb47a18dc91b.zip
Redesign AIDL-Interface once more
Using Bundles makes passing data easier and does not need to redefine the interface if the internel functions change. The helper class has been updated accordingly. In addition, it wrappes completely around all input and output (if wanted).
Diffstat (limited to 'src/org/thialfihar/android/apg/ApgService.java')
-rw-r--r--src/org/thialfihar/android/apg/ApgService.java103
1 files changed, 87 insertions, 16 deletions
diff --git a/src/org/thialfihar/android/apg/ApgService.java b/src/org/thialfihar/android/apg/ApgService.java
index bb5b6463a..316e9a22c 100644
--- a/src/org/thialfihar/android/apg/ApgService.java
+++ b/src/org/thialfihar/android/apg/ApgService.java
@@ -4,12 +4,11 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.Iterator;
import android.content.Intent;
+import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
@@ -22,11 +21,45 @@ public class ApgService extends Service {
return mBinder;
}
+ private enum error {
+ ARGUMENTS_MISSING,
+ APG_FAILURE
+ }
+
private final IApgService.Stub mBinder = new IApgService.Stub() {
- public String encrypt_with_passphrase(List<String> args) {
- String msg = args.remove(0);
- String passphrase = args.remove(0);
+ public boolean encrypt_with_passphrase(Bundle pArgs, Bundle pReturn) {
+ ArrayList<String> errors = new ArrayList<String>();
+ ArrayList<String> warnings = new ArrayList<String>();
+
+ pReturn.putStringArrayList("ERRORS", errors);
+ pReturn.putStringArrayList("WARNINGS", warnings);
+
+ String msg = pArgs.getString("MSG");
+ pArgs.remove("MSG");
+
+ String passphrase = pArgs.getString("SYM_KEY");
+ pArgs.remove("SYM_KEY");
+
+ if (msg == null) {
+ errors.add("Message to encrypt (MSG) missing");
+ }
+
+ if (passphrase == null) {
+ errors.add("Symmetric key (SYM_KEY) missing");
+ }
+
+ if (!pArgs.isEmpty()) {
+ Iterator<String> iter = pArgs.keySet().iterator();
+ while (iter.hasNext()) {
+ warnings.add("Unknown key: " + iter.next());
+ }
+ }
+
+ if (errors.size() != 0) {
+ pReturn.putInt("ERROR", error.ARGUMENTS_MISSING.ordinal());
+ return false;
+ }
Preferences mPreferences = Preferences.getPreferences(getBaseContext(), true);
InputStream inStream = new ByteArrayInputStream(msg.getBytes());
@@ -52,16 +85,50 @@ public class ApgService extends Service {
);
} catch (Exception e) {
Log.d(TAG, "Exception in encrypt");
- e.printStackTrace();
- return null;
+ errors.add("Internal failure in APG when encrypting: " + e.getMessage());
+
+ pReturn.putInt("ERROR", error.APG_FAILURE.ordinal());
+ return false;
}
+
Log.d(TAG, "Encrypted");
- return out.toString();
+ pReturn.putString("RESULT", out.toString());
+ return true;
}
- public String decrypt_with_passphrase(List<String> args) {
- String encrypted_msg = args.remove(0);
- String passphrase = args.remove(0);
+ public boolean decrypt_with_passphrase(Bundle pArgs, Bundle pReturn) {
+ ArrayList<String> errors = new ArrayList<String>();
+ ArrayList<String> warnings = new ArrayList<String>();
+
+ pReturn.putStringArrayList("ERRORS", errors);
+ pReturn.putStringArrayList("WARNINGS", warnings);
+
+ String encrypted_msg = pArgs.getString("MSG");
+ pArgs.remove("MSG");
+
+ String passphrase = pArgs.getString("SYM_KEY");
+ pArgs.remove("SYM_KEY");
+
+ if (encrypted_msg == null) {
+ errors.add("Message to decrypt (MSG) missing");
+ }
+
+ if (passphrase == null) {
+ errors.add("Symmetric key (SYM_KEY) missing");
+ }
+
+ if (!pArgs.isEmpty()) {
+ Iterator<String> iter = pArgs.keySet().iterator();
+ while (iter.hasNext()) {
+ warnings.add("Unknown key: " + iter.next());
+ }
+ }
+
+ if (errors.size() != 0) {
+ pReturn.putStringArrayList("ERROR", errors);
+ pReturn.putInt("ERROR", error.ARGUMENTS_MISSING.ordinal());
+ return false;
+ }
InputStream inStream = new ByteArrayInputStream(encrypted_msg.getBytes());
InputData in = new InputData(inStream, 9999); // XXX what size in
@@ -73,11 +140,15 @@ public class ApgService extends Service {
);
} catch (Exception e) {
Log.d(TAG, "Exception in decrypt");
- e.printStackTrace();
- return null;
+ errors.add("Internal failure in APG when decrypting: " + e.getMessage());
+
+ pReturn.putInt("ERROR", error.APG_FAILURE.ordinal());
+ pReturn.putStringArrayList("ERROR", errors);
+ return false;
}
- return out.toString();
+ pReturn.putString("RESULT", out.toString());
+ return true;
}
};
}