aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/keychain-api-library/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/keychain-api-library/src/main/java/org')
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java10
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java127
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpError.java81
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpHelper.java52
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java201
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java93
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java110
7 files changed, 674 insertions, 0 deletions
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
new file mode 100644
index 000000000..b1ca1bfe6
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpConstants.java
@@ -0,0 +1,10 @@
+package org.openintents.openpgp;
+
+public class OpenPgpConstants {
+
+ public static final String TAG = "OpenPgp API";
+
+ public static final int REQUIRED_API_VERSION = 1;
+ public static final String SERVICE_INTENT = "org.openintents.openpgp.IOpenPgpService";
+
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java
new file mode 100644
index 000000000..6615c2146
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpData.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp;
+
+import android.net.Uri;
+import android.os.Parcel;
+import android.os.ParcelFileDescriptor;
+import android.os.Parcelable;
+
+public class OpenPgpData implements Parcelable {
+ public static final int TYPE_STRING = 0;
+ public static final int TYPE_BYTE_ARRAY = 1;
+ public static final int TYPE_FILE_DESCRIPTOR = 2;
+ public static final int TYPE_URI = 3;
+
+ int type;
+
+ String string;
+ byte[] bytes = new byte[0];
+ ParcelFileDescriptor fileDescriptor;
+ Uri uri;
+
+ public int getType() {
+ return type;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+ public byte[] getBytes() {
+ return bytes;
+ }
+
+ public ParcelFileDescriptor getFileDescriptor() {
+ return fileDescriptor;
+ }
+
+ public Uri getUri() {
+ return uri;
+ }
+
+ public OpenPgpData() {
+
+ }
+
+ /**
+ * Not a real constructor. This can be used to define requested output type.
+ *
+ * @param type
+ */
+ public OpenPgpData(int type) {
+ this.type = type;
+ }
+
+ public OpenPgpData(String string) {
+ this.string = string;
+ this.type = TYPE_STRING;
+ }
+
+ public OpenPgpData(byte[] bytes) {
+ this.bytes = bytes;
+ this.type = TYPE_BYTE_ARRAY;
+ }
+
+ public OpenPgpData(ParcelFileDescriptor fileDescriptor) {
+ this.fileDescriptor = fileDescriptor;
+ this.type = TYPE_FILE_DESCRIPTOR;
+ }
+
+ public OpenPgpData(Uri uri) {
+ this.uri = uri;
+ this.type = TYPE_URI;
+ }
+
+ public OpenPgpData(OpenPgpData b) {
+ this.string = b.string;
+ this.bytes = b.bytes;
+ this.fileDescriptor = b.fileDescriptor;
+ this.uri = b.uri;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(type);
+ dest.writeString(string);
+ dest.writeInt(bytes.length);
+ dest.writeByteArray(bytes);
+ dest.writeParcelable(fileDescriptor, 0);
+ dest.writeParcelable(uri, 0);
pre { line-height: 125%; margin: 0; } td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; } td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; } .highlight .hll { background-color: #ffffcc } .highlight { background: #ffffff; } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* ia64.h -- Header file for ia64 opcode table
   Copyright (C) 1998, 1999, 2000, 2002, 2005, 2006
   Free Software Foundation, Inc.
   Contributed by David Mosberger-Tang <davidm@hpl.hp.com> */

#ifndef opcode_ia64_h
#define opcode_ia64_h

#include <sys/types.h>

#include "dis-asm.h"


typedef BFD_HOST_U_64_BIT ia64_insn;

enum ia64_insn_type
  {
    IA64_TYPE_NIL = 0,	/* illegal type */
    IA64_TYPE_A,	/* integer alu (I- or M-unit) */
    IA64_TYPE_I,	/* non-alu integer (I-unit) */
    IA64_TYPE_M,	/* memory (M-unit) */
    IA64_TYPE_B,	/* branch (B-unit) */
    IA64_TYPE_F,	/* floating-point (F-unit) */
    IA64_TYPE_X,	/* long encoding (X-unit) */
    IA64_TYPE_DYN,	/* Dynamic opcode */
    IA64_NUM_TYPES
  };

enum ia64_unit
  {
    IA64_UNIT_NIL = 0,	/* illegal unit */
    IA64_UNIT_I,	/* integer unit */
    IA64_UNIT_M,	/* memory unit */
    IA64_UNIT_B,	/* branching unit */
    IA64_UNIT_F,	/* floating-point unit */
    IA64_UNIT_L,	/* long "unit" */
    IA64_UNIT_X,	/* may be integer or branch unit */
    IA64_NUM_UNITS
  };

/* Changes to this enumeration must be propagated to the operand table in
   bfd/cpu-ia64-opc.c
GP MESSAGE-----).*", Pattern.DOTALL);
+
+ public static Pattern PGP_SIGNED_MESSAGE = Pattern
+ .compile(
+ ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
+ Pattern.DOTALL);
+
+ public OpenPgpHelper(Context context) {
+ super();
+ this.context = context;
+ }
+
+ public boolean isAvailable() {
+ Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT);
+ List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
+ if (!resInfo.isEmpty()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java
new file mode 100644
index 000000000..4ddd97485
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpListPreference.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.AlertDialog.Builder;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.graphics.drawable.Drawable;
+import android.preference.DialogPreference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+
+public class OpenPgpListPreference extends DialogPreference {
+ ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
+ private String mSelectedPackage;
+
+ public OpenPgpListPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(
+ new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA);
+ if (!resInfo.isEmpty()) {
+ for (ResolveInfo resolveInfo : resInfo) {
+ if (resolveInfo.serviceInfo == null)
+ continue;
+
+ String packageName = resolveInfo.serviceInfo.packageName;
+ String simpleName = String.valueOf(resolveInfo.serviceInfo.loadLabel(context
+ .getPackageManager()));
+ Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager());
+
+ // get api version
+ ServiceInfo si = resolveInfo.serviceInfo;
+ int apiVersion = si.metaData.getInt("api_version");
+
+ mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon,
+ apiVersion));
+ }
+ }
+ }
+
+ public OpenPgpListPreference(Context context) {
+ this(context, null);
+ }
+
+ /**
+ * Can be used to add "no selection"
+ *
+ * @param packageName
+ * @param simpleName
+ * @param icon
+ */
+ public void addProvider(int position, String packageName, String simpleName, Drawable icon,
+ int apiVersion) {
+ mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon,
+ apiVersion));
+ }
+
+ @Override
+ protected void onPrepareDialogBuilder(Builder builder) {
+ // Init ArrayAdapter with OpenPGP Providers
+ ListAdapter adapter = new ArrayAdapter<OpenPgpProviderEntry>(getContext(),
+ android.R.layout.select_dialog_singlechoice, android.R.id.text1, mProviderList) {
+ public View getView(int position, View convertView, ViewGroup parent) {
+ // User super class to create the View
+ View v = super.getView(position, convertView, parent);
+ TextView tv = (TextView) v.findViewById(android.R.id.text1);
+
+ // Put the image on the TextView
+ tv.setCompoundDrawablesWithIntrinsicBounds(mProviderList.get(position).icon, null,
+ null, null);
+
+ // Add margin between image and text (support various screen densities)
+ int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
+ tv.setCompoundDrawablePadding(dp10);
+
+ // disable if it has the wrong api_version
+ if (mProviderList.get(position).apiVersion == OpenPgpConstants.REQUIRED_API_VERSION) {
+ tv.setEnabled(true);
+ } else {
+ tv.setEnabled(false);
+ tv.setText(tv.getText() + " (API v" + mProviderList.get(position).apiVersion
+ + ", needs v" + OpenPgpConstants.REQUIRED_API_VERSION + ")");
+ }
+
+ return v;
+ }
+ };
+
+ builder.setSingleChoiceItems(adapter, getIndexOfProviderList(getValue()),
+ new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mSelectedPackage = mProviderList.get(which).packageName;
+
+ /*
+ * Clicking on an item simulates the positive button click, and dismisses
+ * the dialog.
+ */
+ OpenPgpListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
+ dialog.dismiss();
+ }
+ });
+
+ /*
+ * The typical interaction for list-based dialogs is to have click-on-an-item dismiss the
+ * dialog instead of the user having to press 'Ok'.
+ */
+ builder.setPositiveButton(null, null);
+ }
+
+ @Override
+ protected void onDialogClosed(boolean positiveResult) {
+ super.onDialogClosed(positiveResult);
+
+ if (positiveResult && (mSelectedPackage != null)) {
+ if (callChangeListener(mSelectedPackage)) {
+ setValue(mSelectedPackage);
+ }
+ }
+ }
+
+ private int getIndexOfProviderList(String packageName) {
+ for (OpenPgpProviderEntry app : mProviderList) {
+ if (app.packageName.equals(packageName)) {
+ return mProviderList.indexOf(app);
+ }
+ }
+
+ return -1;
+ }
+
+ public void setValue(String packageName) {
+ mSelectedPackage = packageName;
+ persistString(packageName);
+ }
+
+ public String getValue() {
+ return mSelectedPackage;
+ }
+
+ public String getEntry() {
+ return getEntryByValue(mSelectedPackage);
+ }
+
+ public String getEntryByValue(String packageName) {
+ for (OpenPgpProviderEntry app : mProviderList) {
+ if (app.packageName.equals(packageName)) {
+ return app.simpleName;
+ }
+ }
+
+ return null;
+ }
+
+ private static class OpenPgpProviderEntry {
+ private String packageName;
+ private String simpleName;
+ private Drawable icon;
+ private int apiVersion;
+
+ public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon,
+ int apiVersion) {
+ this.packageName = packageName;
+ this.simpleName = simpleName;
+ this.icon = icon;
+ this.apiVersion = apiVersion;
+ }
+
+ @Override
+ public String toString() {
+ return simpleName;
+ }
+ }
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java
new file mode 100644
index 000000000..f7ba06aaf
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpServiceConnection.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp;
+
+import org.openintents.openpgp.IOpenPgpService;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.IBinder;
+import android.util.Log;
+
+public class OpenPgpServiceConnection {
+ private Context mApplicationContext;
+
+ private IOpenPgpService mService;
+ private boolean mBound;
+ private String mCryptoProviderPackageName;
+
+ public OpenPgpServiceConnection(Context context, String cryptoProviderPackageName) {
+ this.mApplicationContext = context.getApplicationContext();
+ this.mCryptoProviderPackageName = cryptoProviderPackageName;
+ }
+
+ public IOpenPgpService getService() {
+ return mService;
+ }
+
+ public boolean isBound() {
+ return mBound;
+ }
+
+ private ServiceConnection mCryptoServiceConnection = new ServiceConnection() {
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mService = IOpenPgpService.Stub.asInterface(service);
+ Log.d(OpenPgpConstants.TAG, "connected to service");
+ mBound = true;
+ }
+
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ Log.d(OpenPgpConstants.TAG, "disconnected from service");
+ mBound = false;
+ }
+ };
+
+ /**
+ * If not already bound, bind!
+ *
+ * @return
+ */
+ public boolean bindToService() {
+ if (mService == null && !mBound) { // if not already connected
+ try {
+ Log.d(OpenPgpConstants.TAG, "not bound yet");
+
+ Intent serviceIntent = new Intent();
+ serviceIntent.setAction(IOpenPgpService.class.getName());
+ serviceIntent.setPackage(mCryptoProviderPackageName);
+ mApplicationContext.bindService(serviceIntent, mCryptoServiceConnection,
+ Context.BIND_AUTO_CREATE);
+
+ return true;
+ } catch (Exception e) {
+ Log.d(OpenPgpConstants.TAG, "Exception on binding", e);
+ return false;
+ }
+ } else {
+ Log.d(OpenPgpConstants.TAG, "already bound");
+ return true;
+ }
+ }
+
+ public void unbindFromService() {
+ mApplicationContext.unbindService(mCryptoServiceConnection);
+ }
+
+}
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
new file mode 100644
index 000000000..829f8f8cf
--- /dev/null
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openintents.openpgp;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class OpenPgpSignatureResult implements Parcelable {
+ // generic error on signature verification
+ public static final int SIGNATURE_ERROR = 0;
+ // successfully verified signature, with trusted public key
+ public static final int SIGNATURE_SUCCESS_TRUSTED = 1;
+ // no public key was found for this signature verification
+ // you can retrieve the key with
+ // getKeys(new String[] {String.valueOf(signatureResult.getKeyId)}, true, callback)
+ public static final int SIGNATURE_UNKNOWN_PUB_KEY = 2;
+ // successfully verified signature, but with untrusted public key
+ public static final int SIGNATURE_SUCCESS_UNTRUSTED = 3;
+
+ int status;
+ boolean signatureOnly;
+ String userId;
+ long keyId;
+
+ public int getStatus() {
+ return status;
+ }
+
+ public boolean isSignatureOnly() {
+ return signatureOnly;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public long getKeyId() {
+ return keyId;
+ }
+
+ public OpenPgpSignatureResult() {
+
+ }
+
+ public OpenPgpSignatureResult(int signatureStatus, String signatureUserId,
+ boolean signatureOnly, long keyId) {
+ this.status = signatureStatus;
+ this.signatureOnly = signatureOnly;
+ this.userId = signatureUserId;
+ this.keyId = keyId;
+ }
+
+ public OpenPgpSignatureResult(OpenPgpSignatureResult b) {
+ this.status = b.status;
+ this.userId = b.userId;
+ this.signatureOnly = b.signatureOnly;
+ this.keyId = b.keyId;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(status);
+ dest.writeByte((byte) (signatureOnly ? 1 : 0));
+ dest.writeString(userId);
+ dest.writeLong(keyId);
+ }
+
+ public static final Creator<OpenPgpSignatureResult> CREATOR = new Creator<OpenPgpSignatureResult>() {
+ public OpenPgpSignatureResult createFromParcel(final Parcel source) {
+ OpenPgpSignatureResult vr = new OpenPgpSignatureResult();
+ vr.status = source.readInt();
+ vr.signatureOnly = source.readByte() == 1;
+ vr.userId = source.readString();
+ vr.keyId = source.readLong();
+ return vr;
+ }
+
+ public OpenPgpSignatureResult[] newArray(final int size) {
+ return new OpenPgpSignatureResult[size];
+ }
+ };
+
+ @Override
+ public String toString() {
+ String out = new String();
+ out += "\nstatus: " + status;
+ out += "\nuserId: " + userId;
+ out += "\nsignatureOnly: " + signatureOnly;
+ out += "\nkeyId: " + keyId;
+ return out;
+ }
+
+}