make ascii armor parsing more resiliant
This commit is contained in:
parent
073b6a998a
commit
d889c02a0a
|
@ -164,7 +164,7 @@ public class PgpEngine {
|
|||
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
|
||||
try {
|
||||
params.putExtra(OpenPgpApi.RESULT_DETACHED_SIGNATURE, AsciiArmor.decode(signature));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
} catch (final Exception e) {
|
||||
Log.d(Config.LOGTAG, "unable to parse signature", e);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,14 @@ public class AsciiArmor {
|
|||
final List<String> lines = Splitter.on('\n').splitToList(Strings.nullToEmpty(input).trim());
|
||||
if (lines.size() == 1) {
|
||||
final String line = lines.get(0);
|
||||
final String cleaned = line.substring(0, line.lastIndexOf("="));
|
||||
if (line.length() > 1) {
|
||||
final int end = line.lastIndexOf('=');
|
||||
if (end >= 1) {
|
||||
final String cleaned = line.substring(0, end);
|
||||
return BaseEncoding.base64().decode(cleaned);
|
||||
}
|
||||
}
|
||||
}
|
||||
final String withoutChecksum;
|
||||
if (Iterables.getLast(lines).charAt(0) == '=') {
|
||||
withoutChecksum = Joiner.on("").join(lines.subList(0, lines.size() - 1));
|
||||
|
|
Loading…
Reference in New Issue