Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported include/exclude logic from upstream #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/android/com/crypt/cordova/DecryptResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
Expand All @@ -28,12 +29,8 @@ public class DecryptResource extends CordovaPlugin {
private static final String CRYPT_KEY = "";
private static final String CRYPT_IV = "";

private static final String[] CRYPT_FILES = {
".htm",
".html",
".js",
".css",
};
private static final String[] INCLUDE_FILES = new String[] { };
private static final String[] EXCLUDE_FILES = new String[] { };

private String URL_PREFIX;
private String launchUri;
Expand Down Expand Up @@ -102,12 +99,23 @@ private String tofileUri(String uri) {
return uri;
}

private boolean isCryptFiles(String uri) {
for (String ext: CRYPT_FILES) {
if (uri.endsWith(ext)) {
return true;
private boolean isCryptFiles(String uri) {
String checkPath = uri.replace("file:///android_asset/www/", "");
if (!this.hasMatch(checkPath, INCLUDE_FILES)) {
return false;
}
if (this.hasMatch(checkPath, EXCLUDE_FILES)) {
return false;
}
return true;
}

private boolean hasMatch(String text, String[] regexArr) {
for (String regex : regexArr) {
if (Pattern.compile(regex).matcher(text).find()) {
return true;
}
}
return false;
}
return false;
}
}