aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-07-30 21:36:28 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2015-07-30 21:36:28 +0200
commitb42636ec3ec63bef61af264a0a9b09998db8186b (patch)
tree0917522a666d3584f87692fc11b527df5d6f6bd6
parentb5c0b1bd7b7822d344d33b91af761d24e681ddd2 (diff)
downloadopenpgp-api-b42636ec3ec63bef61af264a0a9b09998db8186b.tar.gz
openpgp-api-b42636ec3ec63bef61af264a0a9b09998db8186b.tar.bz2
openpgp-api-b42636ec3ec63bef61af264a0a9b09998db8186b.zip
New OpenPgpDecryptionResult, introduce UNSIGNED, UNENCRYPTED results instead of return types, rework constant naming in OpenPgpSignatureResult
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java108
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java6
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpMetadata.java6
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java54
-rw-r--r--openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java23
5 files changed, 151 insertions, 46 deletions
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java
new file mode 100644
index 0000000..2090b55
--- /dev/null
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpDecryptionResult.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2015 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 OpenPgpDecryptionResult implements Parcelable {
+ /**
+ * Since there might be a case where new versions of the client using the library getting
+ * old versions of the protocol (and thus old versions of this class), we need a versioning
+ * system for the parcels sent between the clients and the providers.
+ */
+ public static final int PARCELABLE_VERSION = 1;
+
+ // content not encrypted
+ public static final int RESULT_NOT_ENCRYPTED = -1;
+ // insecure!
+ public static final int RESULT_INSECURE = 0;
+ // encrypted
+ public static final int RESULT_ENCRYPTED = 1;
+
+ int result;
+
+ public int getResult() {
+ return result;
+ }
+
+ public void setResult(int result) {
+ this.result = result;
+ }
+
+ public OpenPgpDecryptionResult() {
+
+ }
+
+ public OpenPgpDecryptionResult(int result) {
+ this.result = result;
+ }
+
+ public OpenPgpDecryptionResult(OpenPgpDecryptionResult b) {
+ this.result = b.result;
+ }
+
+ public int describeContents() {
+ return 0;
+ }
+
+ public void writeToParcel(Parcel dest, int flags) {
+ /**
+ * NOTE: When adding fields in the process of updating this API, make sure to bump
+ * {@link #PARCELABLE_VERSION}.
+ */
+ dest.writeInt(PARCELABLE_VERSION);
+ // Inject a placeholder that will store the parcel size from this point on
+ // (not including the size itself).
+ int sizePosition = dest.dataPosition();
+ dest.writeInt(0);
+ int startPosition = dest.dataPosition();
+ // version 1
+ dest.writeInt(result);
+ // Go back and write the size
+ int parcelableSize = dest.dataPosition() - startPosition;
+ dest.setDataPosition(sizePosition);
+ dest.writeInt(parcelableSize);
+ dest.setDataPosition(startPosition + parcelableSize);
+ }
+
+ public static final Creator<OpenPgpDecryptionResult> CREATOR = new Creator<OpenPgpDecryptionResult>() {
+ public OpenPgpDecryptionResult createFromParcel(final Parcel source) {
+ source.readInt(); // parcelableVersion
+ int parcelableSize = source.readInt();
+ int startPosition = source.dataPosition();
+
+ OpenPgpDecryptionResult vr = new OpenPgpDecryptionResult();
+ vr.result = source.readInt();
+
+ // skip over all fields added in future versions of this parcel
+ source.setDataPosition(startPosition + parcelableSize);
+
+ return vr;
+ }
+
+ public OpenPgpDecryptionResult[] newArray(final int size) {
+ return new OpenPgpDecryptionResult[size];
+ }
+ };
+
+ @Override
+ public String toString() {
+ return "\nresult: " + result;
+ }
+
+}
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java
index ce8f21f..69c39fd 100644
--- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpError.java
@@ -19,10 +19,6 @@ package org.openintents.openpgp;
import android.os.Parcel;
import android.os.Parcelable;
-/**
- * Parcelable versioning has been copied from Dashclock Widget
- * https://code.google.com/p/dashclock/source/browse/api/src/main/java/com/google/android/apps/dashclock/api/ExtensionData.java
- */
public class OpenPgpError implements Parcelable {
/**
* Since there might be a case where new versions of the client using the library getting
@@ -97,7 +93,7 @@ public class OpenPgpError implements Parcelable {
public static final Creator<OpenPgpError> CREATOR = new Creator<OpenPgpError>() {
public OpenPgpError createFromParcel(final Parcel source) {
- int parcelableVersion = source.readInt();
+ source.readInt(); // parcelableVersion
int parcelableSize = source.readInt();
int startPosition = source.dataPosition();
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpMetadata.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpMetadata.java
index d620a57..8b3a3bb 100644
--- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpMetadata.java
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpMetadata.java
@@ -19,10 +19,6 @@ package org.openintents.openpgp;
import android.os.Parcel;
import android.os.Parcelable;
-/**
- * Parcelable versioning has been copied from Dashclock Widget
- * https://code.google.com/p/dashclock/source/browse/api/src/main/java/com/google/android/apps/dashclock/api/ExtensionData.java
- */
public class OpenPgpMetadata implements Parcelable {
/**
* Since there might be a case where new versions of the client using the library getting
@@ -99,7 +95,7 @@ public class OpenPgpMetadata implements Parcelable {
public static final Creator<OpenPgpMetadata> CREATOR = new Creator<OpenPgpMetadata>() {
public OpenPgpMetadata createFromParcel(final Parcel source) {
- int parcelableVersion = source.readInt();
+ source.readInt(); // parcelableVersion
int parcelableSize = source.readInt();
int startPosition = source.dataPosition();
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
index c2461ab..f188968 100644
--- a/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/OpenPgpSignatureResult.java
@@ -23,10 +23,6 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import java.util.ArrayList;
-/**
- * Parcelable versioning has been copied from Dashclock Widget
- * https://code.google.com/p/dashclock/source/browse/api/src/main/java/com/google/android/apps/dashclock/api/ExtensionData.java
- */
public class OpenPgpSignatureResult implements Parcelable {
/**
* Since there might be a case where new versions of the client using the library getting
@@ -35,39 +31,47 @@ public class OpenPgpSignatureResult implements Parcelable {
*/
public static final int PARCELABLE_VERSION = 2;
- // error -> invalid signature!
- public static final int SIGNATURE_ERROR = 0;
- // successfully verified signature, with certified key
- public static final int SIGNATURE_SUCCESS_CERTIFIED = 1;
+ // content not signed
+ public static final int RESULT_NO_SIGNATURE = -1;
+ // invalid signature!
+ public static final int RESULT_INVALID_SIGNATURE = 0;
+ // successfully verified signature, with confirmed key
+ public static final int RESULT_VALID_CONFIRMED = 1;
// no key was found for this signature verification
- public static final int SIGNATURE_KEY_MISSING = 2;
- // successfully verified signature, but with uncertified key
- public static final int SIGNATURE_SUCCESS_UNCERTIFIED = 3;
+ public static final int RESULT_KEY_MISSING = 2;
+ // successfully verified signature, but with unconfirmed key
+ public static final int RESULT_VALID_UNCONFIRMED = 3;
// key has been revoked -> invalid signature!
- public static final int SIGNATURE_KEY_REVOKED = 4;
+ public static final int RESULT_INVALID_KEY_REVOKED = 4;
// key is expired -> invalid signature!
- public static final int SIGNATURE_KEY_EXPIRED = 5;
+ public static final int RESULT_INVALID_KEY_EXPIRED = 5;
// insecure cryptographic algorithms/protocol -> invalid signature!
- public static final int INSECURE_CRYPTOGRAPHY = 6;
+ public static final int RESULT_INVALID_INSECURE = 6;
- int status;
+ int result;
boolean signatureOnly;
String primaryUserId;
ArrayList<String> userIds;
long keyId;
- public int getStatus() {
- return status;
+ public int getResult() {
+ return result;
}
- public void setStatus(int status) {
- this.status = status;
+ public void setResult(int result) {
+ this.result = result;
}
+ /**
+ * @deprecated
+ */
public boolean isSignatureOnly() {
return signatureOnly;
}
+ /**
+ * @deprecated
+ */
public void setSignatureOnly(boolean signatureOnly) {
this.signatureOnly = signatureOnly;
}
@@ -102,7 +106,7 @@ public class OpenPgpSignatureResult implements Parcelable {
public OpenPgpSignatureResult(int signatureStatus, String signatureUserId,
boolean signatureOnly, long keyId, ArrayList<String> userIds) {
- this.status = signatureStatus;
+ this.result = signatureStatus;
this.signatureOnly = signatureOnly;
this.primaryUserId = signatureUserId;
this.keyId = keyId;
@@ -110,7 +114,7 @@ public class OpenPgpSignatureResult implements Parcelable {
}
public OpenPgpSignatureResult(OpenPgpSignatureResult b) {
- this.status = b.status;
+ this.result = b.result;
this.primaryUserId = b.primaryUserId;
this.signatureOnly = b.signatureOnly;
this.keyId = b.keyId;
@@ -133,7 +137,7 @@ public class OpenPgpSignatureResult implements Parcelable {
dest.writeInt(0);
int startPosition = dest.dataPosition();
// version 1
- dest.writeInt(status);
+ dest.writeInt(result);
dest.writeByte((byte) (signatureOnly ? 1 : 0));
dest.writeString(primaryUserId);
dest.writeLong(keyId);
@@ -148,12 +152,12 @@ public class OpenPgpSignatureResult implements Parcelable {
public static final Creator<OpenPgpSignatureResult> CREATOR = new Creator<OpenPgpSignatureResult>() {
public OpenPgpSignatureResult createFromParcel(final Parcel source) {
- int parcelableVersion = source.readInt();
+ source.readInt(); // parcelableVersion
int parcelableSize = source.readInt();
int startPosition = source.dataPosition();
OpenPgpSignatureResult vr = new OpenPgpSignatureResult();
- vr.status = source.readInt();
+ vr.result = source.readInt();
vr.signatureOnly = source.readByte() == 1;
vr.primaryUserId = source.readString();
vr.keyId = source.readLong();
@@ -173,7 +177,7 @@ public class OpenPgpSignatureResult implements Parcelable {
@Override
public String toString() {
- String out = "\nstatus: " + status;
+ String out = "\nresult: " + result;
out += "\nprimaryUserId: " + primaryUserId;
out += "\nuserIds: " + userIds;
out += "\nsignatureOnly: " + signatureOnly;
diff --git a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
index 25bf72b..39e71ce 100644
--- a/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
+++ b/openpgp-api/src/main/java/org/openintents/openpgp/util/OpenPgpApi.java
@@ -49,7 +49,7 @@ public class OpenPgpApi {
* - Introduction of ACTION_DECRYPT_METADATA, RESULT_METADATA, EXTRA_ORIGINAL_FILENAME, and OpenPgpMetadata parcel
* - Introduction of internal NFC extras: EXTRA_NFC_SIGNED_HASH, EXTRA_NFC_SIG_CREATION_TIMESTAMP
* 5:
- * - OpenPgpSignatureResult: new consts SIGNATURE_KEY_REVOKED and SIGNATURE_KEY_EXPIRED
+ * - OpenPgpSignatureResult: new consts RESULT_INVALID_KEY_REVOKED and RESULT_INVALID_KEY_EXPIRED
* - OpenPgpSignatureResult: ArrayList<String> userIds
* 6:
* - Deprecate ACTION_SIGN
@@ -66,8 +66,14 @@ public class OpenPgpApi {
* - New ACTION_GET_SIGN_KEY_ID
* - EXTRA_PASSPHRASE changed from String to char[]
* 8:
- * - OpenPgpSignatureResult: new const INSECURE_CRYPTOGRAPHY
- * - RESULT_TYPES important change: Introduce RESULT_TYPE_SIGNED_AND_ENCRYPTED, remove RESULT_TYPE_UNENCRYPTED_UNSIGNED
+ * - OpenPgpSignatureResult:
+ * method getStatus() renamed to getResult()
+ * constants have been renamed for clarity
+ * new constants: RESULT_NO_SIGNATURE, RESULT_INVALID_INSECURE
+ * isSignatureOnly() has been deprecated
+ * - RESULT_TYPES have been removed
+ * - new OpenPgpDecryptionResult returned via RESULT_DECRYPTION
+ * - OpenPgpSignatureResult and OpenPgpDecryptionResult are never null, they are always returned.
*/
public static final int API_VERSION = 8;
@@ -164,7 +170,7 @@ public class OpenPgpApi {
* and also signed-only input.
* OutputStream is optional, e.g., for verifying detached signatures!
* <p/>
- * If OpenPgpSignatureResult.getStatus() == OpenPgpSignatureResult.SIGNATURE_KEY_MISSING
+ * If OpenPgpSignatureResult.getResult() == OpenPgpSignatureResult.RESULT_KEY_MISSING
* in addition a PendingIntent is returned via RESULT_INTENT to download missing keys.
* On all other status, in addition a PendingIntent is returned via RESULT_INTENT to open
* the key view in OpenKeychain.
@@ -174,9 +180,9 @@ public class OpenPgpApi {
* <p/>
* returned extras:
* OpenPgpSignatureResult RESULT_SIGNATURE
+ * OpenPgpDecryptionResult RESULT_DECRYPTION
* OpenPgpDecryptMetadata RESULT_METADATA
* String RESULT_CHARSET (charset which was specified in the headers of ascii armored input, if any)
- * int RESULT_TYPE
*/
public static final String ACTION_DECRYPT_VERIFY = "org.openintents.openpgp.action.DECRYPT_VERIFY";
@@ -273,16 +279,11 @@ public class OpenPgpApi {
// DECRYPT_VERIFY
public static final String EXTRA_DETACHED_SIGNATURE = "detached_signature";
public static final String RESULT_SIGNATURE = "signature";
+ public static final String RESULT_DECRYPTION = "decryption";
public static final String RESULT_METADATA = "metadata";
// This will be the charset which was specified in the headers of ascii armored input, if any
public static final String RESULT_CHARSET = "charset";
- // unencrypted _and_ unsigned content will return an ERROR as there is no OpenPGP data available
- public static final String RESULT_TYPE = "type";
- public static final int RESULT_TYPE_ENCRYPTED = 1;
- public static final int RESULT_TYPE_SIGNED = 2;
- public static final int RESULT_TYPE_SIGNED_AND_ENCRYPTED = 3;
-
// INTERNAL, should not be used
public static final String EXTRA_CALL_UUID1 = "call_uuid1";
public static final String EXTRA_CALL_UUID2 = "call_uuid2";