New decrypt activity design (WIP), saner UTF8 decoding (replacing non-decodable characters)

This commit is contained in:
Dominik Schürmann
2014-09-15 10:19:55 +02:00
parent 88bbce831c
commit 53bc417f8f
19 changed files with 549 additions and 324 deletions

View File

@@ -42,6 +42,7 @@ import org.sufficientlysecure.keychain.service.results.OperationResultParcel.Log
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Utf8Util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -365,7 +366,7 @@ public class UncachedKeyRing {
ArrayList<byte[]> processedUserIds = new ArrayList<byte[]>();
for (byte[] rawUserId : new IterableIterator<byte[]>(masterKey.getRawUserIDs())) {
String userId = Strings.fromUTF8ByteArray(rawUserId);
String userId = Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId);
// check for duplicate user ids
if (processedUserIds.contains(rawUserId)) {
@@ -439,7 +440,7 @@ public class UncachedKeyRing {
continue;
}
// warn user if the signature was made with bad encoding
if (!cert.verifySignature(masterKey, userId)) {
if (!Utf8Util.isValidUTF8(rawUserId)) {
log.add(LogLevel.WARN, LogType.MSG_KC_UID_WARN_ENCODING, indent);
}
} catch (PgpGeneralException e) {

View File

@@ -32,6 +32,7 @@ import org.spongycastle.util.Strings;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Utf8Util;
import java.util.ArrayList;
import java.util.Arrays;
@@ -185,7 +186,7 @@ public class UncachedPublicKey {
}
}
if (found != null) {
return Strings.fromUTF8ByteArray(found);
return Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(found);
} else {
return null;
}
@@ -204,8 +205,9 @@ public class UncachedPublicKey {
public ArrayList<String> getUnorderedUserIds() {
ArrayList<String> userIds = new ArrayList<String>();
for (String userId : new IterableIterator<String>(mPublicKey.getUserIDs())) {
userIds.add(userId);
for (byte[] rawUserId : new IterableIterator<byte[]>(mPublicKey.getRawUserIDs())) {
// use our decoding method
userIds.add(Utf8Util.fromUTF8ByteArrayReplaceBadEncoding(rawUserId));
}
return userIds;
}