PGP: retry with trim

pull/215/head
M66B 5 months ago
parent 4f3d58f42c
commit b72486752f

@ -9015,7 +9015,7 @@ public class FragmentMessages extends FragmentBase
Intent data = new Intent(); Intent data = new Intent();
data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY); data.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
data.putExtra(BuildConfig.APPLICATION_ID, id); data.putExtra(BuildConfig.APPLICATION_ID, id);
onPgp(data, auto); onPgp(data, auto, false);
} }
} }
@ -9035,7 +9035,7 @@ public class FragmentMessages extends FragmentBase
break; break;
case REQUEST_OPENPGP: case REQUEST_OPENPGP:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
onPgp(data, false); onPgp(data, false, false);
break; break;
case REQUEST_MESSAGE_DELETE: case REQUEST_MESSAGE_DELETE:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -9250,16 +9250,18 @@ public class FragmentMessages extends FragmentBase
}.execute(this, args, "raw:save"); }.execute(this, args, "raw:save");
} }
private void onPgp(Intent data, boolean auto) { private void onPgp(Intent data, boolean auto, boolean stripped) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable("data", data); args.putParcelable("data", data);
args.putBoolean("auto", auto); args.putBoolean("auto", auto);
args.putBoolean("stripped", stripped);
new SimpleTask<PendingIntent>() { new SimpleTask<PendingIntent>() {
@Override @Override
protected PendingIntent onExecute(Context context, Bundle args) throws Throwable { protected PendingIntent onExecute(Context context, Bundle args) throws Throwable {
// Get arguments // Get arguments
boolean auto = args.getBoolean("auto"); boolean auto = args.getBoolean("auto");
boolean stripped = args.getBoolean("stripped");
Intent data = args.getParcelable("data"); Intent data = args.getParcelable("data");
long id = data.getLongExtra(BuildConfig.APPLICATION_ID, -1); long id = data.getLongExtra(BuildConfig.APPLICATION_ID, -1);
@ -9348,6 +9350,9 @@ public class FragmentMessages extends FragmentBase
else else
throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted)); throw new IllegalArgumentException(context.getString(R.string.title_not_encrypted));
if (stripped)
in = new MessageHelper.StripStream((in));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean autocrypt = prefs.getBoolean("autocrypt", true); boolean autocrypt = prefs.getBoolean("autocrypt", true);
if (autocrypt && if (autocrypt &&
@ -9542,8 +9547,13 @@ public class FragmentMessages extends FragmentBase
} else if (sresult == RESULT_KEY_MISSING) } else if (sresult == RESULT_KEY_MISSING)
args.putString("sigresult", context.getString(R.string.title_signature_key_missing)); args.putString("sigresult", context.getString(R.string.title_signature_key_missing));
else { else {
String text = context.getString(R.string.title_signature_invalid_reason, Integer.toString(sresult)); if (stripped) {
args.putString("sigresult", text); String text = context.getString(R.string.title_signature_invalid_reason, Integer.toString(sresult));
args.putString("sigresult", text);
} else {
onPgp(data, auto, true);
return null;
}
} }
break; break;

@ -88,6 +88,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FilterInputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -6130,6 +6131,47 @@ public class MessageHelper {
} }
} }
static class StripStream extends FilterInputStream {
protected StripStream(InputStream in) {
super(in);
}
@Override
public int read() throws IOException {
int b = super.read();
if (b == ' ') {
super.mark(1000);
while (true) {
b = super.read();
if (b != ' ') {
if (b == '\r' || b == '\n')
return b;
else {
super.reset();
return ' ';
}
}
}
} else
return b;
}
@Override
public int read(byte[] b) throws IOException {
for (int i = 0; i < b.length; i++) {
b[i] = (byte) read();
if (b[i] < 0)
return i;
}
return b.length;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
throw new UnsupportedOperationException();
}
}
static class CanonicalizingStream extends FilterOutputStream { static class CanonicalizingStream extends FilterOutputStream {
private OutputStream os; private OutputStream os;
private int content; private int content;

Loading…
Cancel
Save