diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-15 13:00:47 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2014-02-15 13:00:47 +0100 |
commit | 52f1c930ebe98251fb9d3b34b2725087f2917f64 (patch) | |
tree | ee5543854ced499c282892223674bd9b4c73266f /OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java | |
parent | 3b0f76bf60028603140c3fd8a956241b315a6b18 (diff) | |
download | open-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.tar.gz open-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.tar.bz2 open-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.zip |
parse string util method, better help text for access screen
Diffstat (limited to 'OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java')
-rw-r--r-- | OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java index 6dbf76897..ffecaceba 100644 --- a/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java +++ b/OpenPGP-Keychain-API/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java @@ -17,6 +17,7 @@ package org.openintents.openpgp.util; import java.util.List; +import java.util.regex.Matcher; import java.util.regex.Pattern; import android.content.Context; @@ -24,22 +25,33 @@ import android.content.Intent; import android.content.pm.ResolveInfo; public class OpenPgpUtils { - private Context context; - public static Pattern PGP_MESSAGE = Pattern.compile( - ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL); + public static final Pattern PGP_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", + Pattern.DOTALL); - public static Pattern PGP_SIGNED_MESSAGE = Pattern - .compile( - ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", - Pattern.DOTALL); + public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile( + ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*", + Pattern.DOTALL); - public OpenPgpUtils(Context context) { - super(); - this.context = context; + public static final int PARSE_RESULT_NO_PGP = -1; + public static final int PARSE_RESULT_MESSAGE = 0; + public static final int PARSE_RESULT_SIGNED_MESSAGE = 1; + + public static int parseMessage(String message) { + Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message); + Matcher matcherMessage = PGP_MESSAGE.matcher(message); + + if (matcherMessage.matches()) { + return PARSE_RESULT_MESSAGE; + } else if (matcherSigned.matches()) { + return PARSE_RESULT_SIGNED_MESSAGE; + } else { + return PARSE_RESULT_NO_PGP; + } } - public boolean isAvailable() { + public static boolean isAvailable(Context context) { Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT); List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0); if (!resInfo.isEmpty()) { |