ditch isLikelyText flag, set mimeType to text/plain in that case
This commit is contained in:
@@ -355,8 +355,8 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
|
|||||||
log.add(LogType.MSG_DATA_MIME_CHARSET, 3, charsetVerifier.getCharset());
|
log.add(LogType.MSG_DATA_MIME_CHARSET, 3, charsetVerifier.getCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata = new OpenPgpMetadata(mFilename, mimeType, 0L, totalLength,
|
metadata = new OpenPgpMetadata(mFilename, charsetVerifier.getGuessedMimeType(), 0L, totalLength,
|
||||||
charsetVerifier.getCharset(), charsetVerifier.isProbablyText());
|
charsetVerifier.getCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
out.close();
|
out.close();
|
||||||
|
|||||||
@@ -417,7 +417,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
metadata = new OpenPgpMetadata(
|
metadata = new OpenPgpMetadata(
|
||||||
originalFilename, mimeType,
|
originalFilename, mimeType,
|
||||||
literalData.getModificationTime().getTime(),
|
literalData.getModificationTime().getTime(),
|
||||||
originalSize == null ? 0 : originalSize, charset, false);
|
originalSize == null ? 0 : originalSize, charset);
|
||||||
|
|
||||||
log.add(LogType.MSG_DC_OK_META_ONLY, indent);
|
log.add(LogType.MSG_DC_OK_META_ONLY, indent);
|
||||||
DecryptVerifyResult result =
|
DecryptVerifyResult result =
|
||||||
@@ -483,24 +483,20 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
Log.d(Constants.TAG, "decrypt time taken: " + String.format("%.2f", opTime / 1000.0) + "s");
|
Log.d(Constants.TAG, "decrypt time taken: " + String.format("%.2f", opTime / 1000.0) + "s");
|
||||||
|
|
||||||
// special treatment to detect pgp mime types
|
// special treatment to detect pgp mime types
|
||||||
|
// TODO move into CharsetVerifier? seems like that would be a plausible place for this logic
|
||||||
if (matchesPrefix(firstBytes, "-----BEGIN PGP PUBLIC KEY BLOCK-----")
|
if (matchesPrefix(firstBytes, "-----BEGIN PGP PUBLIC KEY BLOCK-----")
|
||||||
|| matchesPrefix(firstBytes, "-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
|
|| matchesPrefix(firstBytes, "-----BEGIN PGP PRIVATE KEY BLOCK-----")) {
|
||||||
mimeType = Constants.MIME_TYPE_KEYS;
|
mimeType = Constants.MIME_TYPE_KEYS;
|
||||||
} else if (matchesPrefix(firstBytes, "-----BEGIN PGP MESSAGE-----")) {
|
} else if (matchesPrefix(firstBytes, "-----BEGIN PGP MESSAGE-----")) {
|
||||||
// this is NOT application/pgp-encrypted, see RFC 3156!
|
// this is NOT application/pgp-encrypted, see RFC 3156!
|
||||||
mimeType = Constants.MIME_TYPE_ENCRYPTED_ALTERNATE;
|
mimeType = Constants.MIME_TYPE_ENCRYPTED_ALTERNATE;
|
||||||
|
} else {
|
||||||
|
mimeType = charsetVerifier.getGuessedMimeType();
|
||||||
}
|
}
|
||||||
|
metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(),
|
||||||
|
alreadyWritten, charsetVerifier.getCharset());
|
||||||
|
|
||||||
log.add(LogType.MSG_DC_CLEAR_META_MIME, indent + 1, mimeType);
|
log.add(LogType.MSG_DC_CLEAR_META_MIME, indent + 1, mimeType);
|
||||||
|
|
||||||
if (charsetVerifier.isDefinitelyBinary()) {
|
|
||||||
metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(),
|
|
||||||
alreadyWritten);
|
|
||||||
} else {
|
|
||||||
metadata = new OpenPgpMetadata(originalFilename, mimeType, literalData.getModificationTime().getTime(),
|
|
||||||
alreadyWritten, charsetVerifier.getCharset(), charsetVerifier.isProbablyText());
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, metadata.toString());
|
Log.d(Constants.TAG, metadata.toString());
|
||||||
|
|
||||||
indent -= 1;
|
indent -= 1;
|
||||||
@@ -883,7 +879,7 @@ public class PgpDecryptVerifyOperation extends BaseOperation<PgpDecryptVerifyInp
|
|||||||
|
|
||||||
log.add(LogType.MSG_DC_OK, indent);
|
log.add(LogType.MSG_DC_OK, indent);
|
||||||
|
|
||||||
OpenPgpMetadata metadata = new OpenPgpMetadata("", "text/plain", -1, clearText.length, "utf-8", true);
|
OpenPgpMetadata metadata = new OpenPgpMetadata("", "text/plain", -1, clearText.length, "utf-8");
|
||||||
|
|
||||||
DecryptVerifyResult result = new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log);
|
DecryptVerifyResult result = new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log);
|
||||||
result.setSignatureResult(signatureChecker.getSignatureResult());
|
result.setSignatureResult(signatureChecker.getSignatureResult());
|
||||||
|
|||||||
@@ -592,7 +592,7 @@ public class DecryptListFragment
|
|||||||
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
Intent chooserIntent = Intent.createChooser(intent, getString(R.string.intent_show));
|
||||||
chooserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
chooserIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
|
||||||
if (!share && metadata.isLooksLikeText()) {
|
if (!share && ClipDescription.compareMimeTypes(metadata.getMimeType(), "text/*")) {
|
||||||
LabeledIntent internalIntent = new LabeledIntent(
|
LabeledIntent internalIntent = new LabeledIntent(
|
||||||
new Intent(intent)
|
new Intent(intent)
|
||||||
.setClass(activity, DisplayTextActivity.class)
|
.setClass(activity, DisplayTextActivity.class)
|
||||||
|
|||||||
@@ -33,19 +33,21 @@ public class CharsetVerifier {
|
|||||||
private boolean isPossibleTextMimeType;
|
private boolean isPossibleTextMimeType;
|
||||||
private boolean isTextMimeType;
|
private boolean isTextMimeType;
|
||||||
private String charset;
|
private String charset;
|
||||||
|
private String mimeType;
|
||||||
|
|
||||||
public CharsetVerifier(@NonNull byte[] buf, String mimeType, @Nullable String charset) {
|
public CharsetVerifier(@NonNull byte[] buf, @NonNull String mimeType, @Nullable String charset) {
|
||||||
|
|
||||||
isPossibleTextMimeType = ClipDescription.compareMimeTypes(mimeType, "application/octet-stream")
|
this.mimeType = mimeType;
|
||||||
|| ClipDescription.compareMimeTypes(mimeType, "application/x-download")
|
isTextMimeType = ClipDescription.compareMimeTypes(mimeType, "text/*");
|
||||||
|| ClipDescription.compareMimeTypes(mimeType, "text/*");
|
isPossibleTextMimeType = isTextMimeType
|
||||||
|
|| ClipDescription.compareMimeTypes(mimeType, "application/octet-stream")
|
||||||
|
|| ClipDescription.compareMimeTypes(mimeType, "application/x-download");
|
||||||
if (!isPossibleTextMimeType) {
|
if (!isPossibleTextMimeType) {
|
||||||
charsetDecoder = null;
|
charsetDecoder = null;
|
||||||
bufWrap = null;
|
bufWrap = null;
|
||||||
dummyOutput = null;
|
dummyOutput = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isTextMimeType = ClipDescription.compareMimeTypes(mimeType, "text/*");
|
|
||||||
|
|
||||||
bufWrap = ByteBuffer.wrap(buf);
|
bufWrap = ByteBuffer.wrap(buf);
|
||||||
dummyOutput = CharBuffer.allocate(buf.length);
|
dummyOutput = CharBuffer.allocate(buf.length);
|
||||||
@@ -96,6 +98,16 @@ public class CharsetVerifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGuessedMimeType() {
|
||||||
|
if (isTextMimeType) {
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
if (isProbablyText()) {
|
||||||
|
return "text/plain";
|
||||||
|
}
|
||||||
|
return mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCharsetFaulty() {
|
public boolean isCharsetFaulty() {
|
||||||
finishIfNecessary();
|
finishIfNecessary();
|
||||||
return isFaulty;
|
return isFaulty;
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ public class InputDataOperationTest {
|
|||||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
||||||
Assert.assertEquals("text/plain", metadata.getMimeType());
|
Assert.assertEquals("text/plain", metadata.getMimeType());
|
||||||
Assert.assertEquals("utf-8", metadata.getCharset());
|
Assert.assertEquals("utf-8", metadata.getCharset());
|
||||||
Assert.assertTrue("data should be looksLikeText", metadata.isLooksLikeText());
|
|
||||||
|
|
||||||
metadata = result.mMetadata.get(1);
|
metadata = result.mMetadata.get(1);
|
||||||
Assert.assertEquals("text/testvalue", metadata.getMimeType());
|
Assert.assertEquals("text/testvalue", metadata.getMimeType());
|
||||||
@@ -214,7 +213,6 @@ public class InputDataOperationTest {
|
|||||||
|
|
||||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
||||||
Assert.assertEquals("text/plain", metadata.getMimeType());
|
Assert.assertEquals("text/plain", metadata.getMimeType());
|
||||||
Assert.assertTrue("data should be looksLikeText", metadata.isLooksLikeText());
|
|
||||||
|
|
||||||
Assert.assertNull("charset was bad so it should not be set", metadata.getCharset());
|
Assert.assertNull("charset was bad so it should not be set", metadata.getCharset());
|
||||||
Assert.assertTrue("faulty charset should have been detected",
|
Assert.assertTrue("faulty charset should have been detected",
|
||||||
@@ -236,7 +234,6 @@ public class InputDataOperationTest {
|
|||||||
|
|
||||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
||||||
Assert.assertEquals("text/plain", metadata.getMimeType());
|
Assert.assertEquals("text/plain", metadata.getMimeType());
|
||||||
Assert.assertTrue("data should be looksLikeText", metadata.isLooksLikeText());
|
|
||||||
|
|
||||||
Assert.assertEquals("charset should be set since it was guessed and not faulty",
|
Assert.assertEquals("charset should be set since it was guessed and not faulty",
|
||||||
"utf-8", metadata.getCharset());
|
"utf-8", metadata.getCharset());
|
||||||
@@ -258,8 +255,7 @@ public class InputDataOperationTest {
|
|||||||
Assert.assertNull(result.mDecryptVerifyResult);
|
Assert.assertNull(result.mDecryptVerifyResult);
|
||||||
|
|
||||||
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
OpenPgpMetadata metadata = result.mMetadata.get(0);
|
||||||
Assert.assertEquals("application/octet-stream", metadata.getMimeType());
|
Assert.assertEquals("text/plain", metadata.getMimeType());
|
||||||
Assert.assertTrue("data should be looksLikeText", metadata.isLooksLikeText());
|
|
||||||
|
|
||||||
Assert.assertEquals("charset should be set since it was guessed and not faulty",
|
Assert.assertEquals("charset should be set since it was guessed and not faulty",
|
||||||
"utf-8", metadata.getCharset());
|
"utf-8", metadata.getCharset());
|
||||||
|
|||||||
@@ -34,13 +34,14 @@ public class CharsetVerifierTest {
|
|||||||
bytes[4] = (byte) 0xc3;
|
bytes[4] = (byte) 0xc3;
|
||||||
bytes[5] = (byte) 0x28;
|
bytes[5] = (byte) 0x28;
|
||||||
|
|
||||||
CharsetVerifier charsetVerifier = new CharsetVerifier(bytes, "text/plain", "utf-8");
|
CharsetVerifier charsetVerifier = new CharsetVerifier(bytes, "text/something", "utf-8");
|
||||||
charsetVerifier.readBytesFromBuffer(0, bytes.length);
|
charsetVerifier.readBytesFromBuffer(0, bytes.length);
|
||||||
|
|
||||||
assertFalse("text/plain should not be marked as binary, even if it is", charsetVerifier.isDefinitelyBinary());
|
assertFalse("text/plain should not be marked as binary, even if it is", charsetVerifier.isDefinitelyBinary());
|
||||||
assertTrue("text/plain should be marked as text, even if it isn't valid", charsetVerifier.isProbablyText());
|
assertTrue("text/plain should be marked as text, even if it isn't valid", charsetVerifier.isProbablyText());
|
||||||
assertTrue("encoding contained illegal chars, so it should be marked as faulty", charsetVerifier.isCharsetFaulty());
|
assertTrue("encoding contained illegal chars, so it should be marked as faulty", charsetVerifier.isCharsetFaulty());
|
||||||
assertFalse("charset was specified and should not be marked as guessed", charsetVerifier.isCharsetGuessed());
|
assertFalse("charset was specified and should not be marked as guessed", charsetVerifier.isCharsetGuessed());
|
||||||
|
assertEquals("mimetype should be preserved", "text/something", charsetVerifier.getGuessedMimeType());
|
||||||
assertEquals("charset should be utf-8 since it was given explicitly", "utf-8", charsetVerifier.getCharset());
|
assertEquals("charset should be utf-8 since it was given explicitly", "utf-8", charsetVerifier.getCharset());
|
||||||
assertEquals("charset should be utf-8 since it was given explicitly", "utf-8", charsetVerifier.getMaybeFaultyCharset());
|
assertEquals("charset should be utf-8 since it was given explicitly", "utf-8", charsetVerifier.getMaybeFaultyCharset());
|
||||||
}
|
}
|
||||||
@@ -59,6 +60,7 @@ public class CharsetVerifierTest {
|
|||||||
assertTrue("encoding contained illegal chars, so it should be marked as faulty", charsetVerifier.isCharsetFaulty());
|
assertTrue("encoding contained illegal chars, so it should be marked as faulty", charsetVerifier.isCharsetFaulty());
|
||||||
assertTrue("charset was guessed and should be marked as such", charsetVerifier.isCharsetGuessed());
|
assertTrue("charset was guessed and should be marked as such", charsetVerifier.isCharsetGuessed());
|
||||||
assertNull("charset should be null since the guess was faulty", charsetVerifier.getCharset());
|
assertNull("charset should be null since the guess was faulty", charsetVerifier.getCharset());
|
||||||
|
assertEquals("mimetype should be set to text", "text/plain", charsetVerifier.getGuessedMimeType());
|
||||||
assertEquals("maybe-faulty charset should be utf-8", "utf-8", charsetVerifier.getMaybeFaultyCharset());
|
assertEquals("maybe-faulty charset should be utf-8", "utf-8", charsetVerifier.getMaybeFaultyCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ public class CharsetVerifierTest {
|
|||||||
assertTrue("application/octet-stream with text content should be probably text", charsetVerifier.isProbablyText());
|
assertTrue("application/octet-stream with text content should be probably text", charsetVerifier.isProbablyText());
|
||||||
assertFalse("detected charset should not be faulty", charsetVerifier.isCharsetFaulty());
|
assertFalse("detected charset should not be faulty", charsetVerifier.isCharsetFaulty());
|
||||||
assertTrue("charset was guessed and should be marked as such", charsetVerifier.isCharsetGuessed());
|
assertTrue("charset was guessed and should be marked as such", charsetVerifier.isCharsetGuessed());
|
||||||
|
assertEquals("mimetype should be set to text", "text/plain", charsetVerifier.getGuessedMimeType());
|
||||||
assertEquals("guessed charset is utf-8", "utf-8", charsetVerifier.getCharset());
|
assertEquals("guessed charset is utf-8", "utf-8", charsetVerifier.getCharset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
extern/openpgp-api-lib
vendored
2
extern/openpgp-api-lib
vendored
Submodule extern/openpgp-api-lib updated: 51bbe35aa1...075616c461
Reference in New Issue
Block a user