1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 09:52:16 -05:00

Update OpenPGP API lib to newest version

This commit is contained in:
Dominik Schürmann 2015-01-29 20:53:25 +01:00
parent 3077e6a2d7
commit a00a119e18
39 changed files with 94 additions and 42 deletions

View File

@ -13,20 +13,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
// NOTE: We are using the old folder structure to also support Eclipse
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
buildToolsVersion '21.1.1'
// Do not abort build if lint finds errors
lintOptions {

View File

@ -1,15 +0,0 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-19
android.library=true

View File

@ -27,6 +27,7 @@ import android.util.Log;
import org.openintents.openpgp.IOpenPgpService;
import org.openintents.openpgp.OpenPgpError;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -290,14 +291,24 @@ public class OpenPgpApi {
}
}
/**
* InputStream and OutputStreams are always closed after operating on them!
*
* @param data
* @param is
* @param os
* @return
*/
public Intent executeApi(Intent data, InputStream is, OutputStream os) {
ParcelFileDescriptor input = null;
ParcelFileDescriptor output = null;
try {
// always send version from client
data.putExtra(EXTRA_API_VERSION, OpenPgpApi.API_VERSION);
Intent result;
// pipe the input and output
ParcelFileDescriptor input = null;
if (is != null) {
input = ParcelFileDescriptorUtil.pipeFrom(is,
new ParcelFileDescriptorUtil.IThreadListener() {
@ -309,7 +320,6 @@ public class OpenPgpApi {
}
);
}
ParcelFileDescriptor output = null;
if (os != null) {
output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@ -324,11 +334,6 @@ public class OpenPgpApi {
// blocks until result is ready
result = mService.execute(data, input, output);
// close() is required to halt the TransferThread
if (output != null) {
output.close();
}
// TODO: close input?
// set class loader to current context to allow unparcelling
// of OpenPgpError and OpenPgpSignatureResult
@ -343,6 +348,22 @@ public class OpenPgpApi {
result.putExtra(RESULT_ERROR,
new OpenPgpError(OpenPgpError.CLIENT_SIDE_ERROR, e.getMessage()));
return result;
} finally {
// close() is required to halt the TransferThread
if (output != null) {
try {
output.close();
} catch (IOException e) {
Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e);
}
}
if (input != null) {
try {
input.close();
} catch (IOException e) {
Log.e(OpenPgpApi.TAG, "IOException when closing ParcelFileDescriptor!", e);
}
}
}
}

View File

@ -46,6 +46,13 @@ public class OpenPgpListPreference extends DialogPreference {
private static final Intent MARKET_INTENT = new Intent(Intent.ACTION_VIEW, Uri.parse(
String.format(MARKET_INTENT_URI_BASE, OPENKEYCHAIN_PACKAGE)));
private static final ArrayList<String> PROVIDER_BLACKLIST = new ArrayList<String>();
static {
// Unfortunately, the current released version of APG includes a broken version of the API
PROVIDER_BLACKLIST.add("org.thialfihar.android.apg");
}
private ArrayList<OpenPgpProviderEntry> mLegacyList = new ArrayList<OpenPgpProviderEntry>();
private ArrayList<OpenPgpProviderEntry> mList = new ArrayList<OpenPgpProviderEntry>();
@ -96,7 +103,9 @@ public class OpenPgpListPreference extends DialogPreference {
.getPackageManager()));
Drawable icon = resolveInfo.serviceInfo.loadIcon(getContext().getPackageManager());
providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
if (!PROVIDER_BLACKLIST.contains(packageName)) {
providerList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
}
}
}

View File

@ -16,16 +16,16 @@
package org.openintents.openpgp.util;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.text.TextUtils;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.text.TextUtils;
public class OpenPgpUtils {
public static final Pattern PGP_MESSAGE = Pattern.compile(

View File

@ -0,0 +1,50 @@
package test.org.openintents.openpgp;
import org.openintents.openpgp.util.OpenPgpUtils;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openintents.openpgp.util.OpenPgpUtils;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
@RunWith(AndroidJUnit4.class)
public class OpenPgpUtilsTest {
@Test
public void splitCompleteUserIdShouldReturnAll3Components() throws Exception {
OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann (this is a comment) <max@example.com>");
assertEquals("Max Mustermann", info.name);
assertEquals("this is a comment", info.comment);
assertEquals("max@example.com", info.email);
}
@Test
public void splitUserIdWithAllButCommentShouldReturnNameAndEmail() throws Exception {
OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann <max@example.com>");
assertEquals("Max Mustermann", info.name);
assertNull(info.comment);
assertEquals("max@example.com", info.email);
}
@Test
public void splitUserIdWithAllButEmailShouldReturnNameAndComment() throws Exception {
OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann (this is a comment)");
assertEquals(info.name, "Max Mustermann");
assertEquals(info.comment, "this is a comment");
assertNull(info.email);
}
@Test
public void splitUserIdWithOnlyNameShouldReturnNameOnly() throws Exception {
OpenPgpUtils.UserInfo info = OpenPgpUtils.splitUserId("Max Mustermann [this is a nothing]");
assertEquals("Max Mustermann", info.name);
assertNull(info.comment);
assertNull(info.email);
}
}