// Path: src/info/guardianproject/gpg/GnuPG.java
// public class GnuPG {
//     public static GnuPGContext context = null;
// 
//     private static Pattern PGP_MESSAGE = null;
//     private static Pattern PGP_PRIVATE_KEY_BLOCK = null;
//     private static Pattern PGP_PUBLIC_KEY_BLOCK = null;
//     private static Pattern PGP_SIGNATURE = null;
//     private static Pattern PGP_SIGNED_MESSAGE = null;
// 
//     public static void createContext() {
//         context = new GnuPGContext();
//         // set the homeDir option to our custom home location
//         context.setEngineInfo(context.getProtocol(), context.getFilename(),
//                 NativeHelper.app_home.getAbsolutePath());
//     }
// 
//     public static int gpg2(String args) {
//         final String TAG = "gpg2";
//         String command = NativeHelper.gpg2 + " " + args;
//         Log.i(TAG, command);
//         try {
//             Process sh = Runtime.getRuntime().exec("/system/bin/sh",
//                     NativeHelper.envp, NativeHelper.app_home);
//             OutputStream stdin = sh.getOutputStream();
//             InputStream stdout = sh.getInputStream();
//             InputStream stderr = sh.getErrorStream();
// 
//             stdin.write((command + "\nexit\n").getBytes("ASCII"));
//             sh.waitFor();
// 
//             Log.i("stdout", readResult(stdout));
//             Log.w("stderr", readResult(stderr));
//             Log.i(TAG, "finished: " + command + "  exit value: " + sh.exitValue());
//             return sh.exitValue();
//         } catch (Exception e) {
//             Log.e(TAG, "FAILED: " + command, e);
//         }
//         return 1;
//     }
// 
//     private static String readResult(InputStream i) {
//         String ret = "";
//         try {
//             byte[] readBuffer = new byte[512];
//             int readCount = -1;
//             while ((readCount = i.read(readBuffer)) > 0) {
//                 ret += new String(readBuffer, 0, readCount);
//             }
//         } catch (IOException e) {
//             Log.e("GnuPG", "readResult", e);
//         }
//         return ret;
//     }
// 
//     public static Matcher getPgpMessageMatcher(CharSequence input) {
//         if (PGP_MESSAGE == null)
//             PGP_MESSAGE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
//                             Pattern.DOTALL);
//         return PGP_MESSAGE.matcher(input);
//     }
// 
//     public static Matcher getPgpSignatureMatcher(CharSequence input) {
//         if (PGP_SIGNATURE == null)
//             PGP_SIGNATURE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
//                             Pattern.DOTALL);
//         return PGP_SIGNATURE.matcher(input);
//     }
// 
//     public static Matcher getPgpSignedMessageMatcher(CharSequence input) {
//         if (PGP_SIGNED_MESSAGE == null)
//             PGP_SIGNED_MESSAGE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
//                             Pattern.DOTALL);
//         return PGP_SIGNED_MESSAGE.matcher(input);
//     }
// 
//     public static Matcher getPgpPrivateKeyBlockMatcher(CharSequence input) {
//         if (PGP_PRIVATE_KEY_BLOCK == null)
//             PGP_PRIVATE_KEY_BLOCK = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP PRIVATE KEY BLOCK-----.*?-----END PGP PRIVATE KEY BLOCK-----).*",
//                             Pattern.DOTALL);
//         return PGP_PRIVATE_KEY_BLOCK.matcher(input);
//     }
// 
//     public static Matcher getPgpPublicKeyBlockMatcher(CharSequence input) {
//         if (PGP_PUBLIC_KEY_BLOCK == null)
//             PGP_PUBLIC_KEY_BLOCK = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*",
//                             Pattern.DOTALL);
//         return PGP_PUBLIC_KEY_BLOCK.matcher(input);
//     }
// }


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.freiheit.gnupg.GnuPGData;
import info.guardianproject.gpg.GnuPG;
import info.guardianproject.gpg.R;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

package info.guardianproject.gpg.apg_compat;





public class DecryptActivity extends Activity {
    public static final String TAG = "DecryptActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();

        String action = intent.getAction();
        if (action.equals(Apg.Intent.DECRYPT_AND_RETURN)) {
            if (intent.getData() != null)
                Log.w(TAG, Apg.Intent.DECRYPT_AND_RETURN
                        + " " + getString(R.string.error_files_not_supported));
            Bundle extras = intent.getExtras();
            // add empty content so we don't have to check for null again
            if (extras == null)
                extras = new Bundle();

            boolean asciiArmor = extras.getBoolean(Apg.EXTRA_ASCII_ARMOUR, true);
// Path: src/info/guardianproject/gpg/GnuPG.java
// public class GnuPG {
//     public static GnuPGContext context = null;
// 
//     private static Pattern PGP_MESSAGE = null;
//     private static Pattern PGP_PRIVATE_KEY_BLOCK = null;
//     private static Pattern PGP_PUBLIC_KEY_BLOCK = null;
//     private static Pattern PGP_SIGNATURE = null;
//     private static Pattern PGP_SIGNED_MESSAGE = null;
// 
//     public static void createContext() {
//         context = new GnuPGContext();
//         // set the homeDir option to our custom home location
//         context.setEngineInfo(context.getProtocol(), context.getFilename(),
//                 NativeHelper.app_home.getAbsolutePath());
//     }
// 
//     public static int gpg2(String args) {
//         final String TAG = "gpg2";
//         String command = NativeHelper.gpg2 + " " + args;
//         Log.i(TAG, command);
//         try {
//             Process sh = Runtime.getRuntime().exec("/system/bin/sh",
//                     NativeHelper.envp, NativeHelper.app_home);
//             OutputStream stdin = sh.getOutputStream();
//             InputStream stdout = sh.getInputStream();
//             InputStream stderr = sh.getErrorStream();
// 
//             stdin.write((command + "\nexit\n").getBytes("ASCII"));
//             sh.waitFor();
// 
//             Log.i("stdout", readResult(stdout));
//             Log.w("stderr", readResult(stderr));
//             Log.i(TAG, "finished: " + command + "  exit value: " + sh.exitValue());
//             return sh.exitValue();
//         } catch (Exception e) {
//             Log.e(TAG, "FAILED: " + command, e);
//         }
//         return 1;
//     }
// 
//     private static String readResult(InputStream i) {
//         String ret = "";
//         try {
//             byte[] readBuffer = new byte[512];
//             int readCount = -1;
//             while ((readCount = i.read(readBuffer)) > 0) {
//                 ret += new String(readBuffer, 0, readCount);
//             }
//         } catch (IOException e) {
//             Log.e("GnuPG", "readResult", e);
//         }
//         return ret;
//     }
// 
//     public static Matcher getPgpMessageMatcher(CharSequence input) {
//         if (PGP_MESSAGE == null)
//             PGP_MESSAGE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
//                             Pattern.DOTALL);
//         return PGP_MESSAGE.matcher(input);
//     }
// 
//     public static Matcher getPgpSignatureMatcher(CharSequence input) {
//         if (PGP_SIGNATURE == null)
//             PGP_SIGNATURE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
//                             Pattern.DOTALL);
//         return PGP_SIGNATURE.matcher(input);
//     }
// 
//     public static Matcher getPgpSignedMessageMatcher(CharSequence input) {
//         if (PGP_SIGNED_MESSAGE == null)
//             PGP_SIGNED_MESSAGE = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
//                             Pattern.DOTALL);
//         return PGP_SIGNED_MESSAGE.matcher(input);
//     }
// 
//     public static Matcher getPgpPrivateKeyBlockMatcher(CharSequence input) {
//         if (PGP_PRIVATE_KEY_BLOCK == null)
//             PGP_PRIVATE_KEY_BLOCK = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP PRIVATE KEY BLOCK-----.*?-----END PGP PRIVATE KEY BLOCK-----).*",
//                             Pattern.DOTALL);
//         return PGP_PRIVATE_KEY_BLOCK.matcher(input);
//     }
// 
//     public static Matcher getPgpPublicKeyBlockMatcher(CharSequence input) {
//         if (PGP_PUBLIC_KEY_BLOCK == null)
//             PGP_PUBLIC_KEY_BLOCK = Pattern
//                     .compile(
//                             ".*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*",
//                             Pattern.DOTALL);
//         return PGP_PUBLIC_KEY_BLOCK.matcher(input);
//     }
// }


// Path: src/info/guardianproject/gpg/apg_compat/DecryptActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.freiheit.gnupg.GnuPGData;
import info.guardianproject.gpg.GnuPG;
import info.guardianproject.gpg.R;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;


package info.guardianproject.gpg.apg_compat;





public class DecryptActivity extends Activity {
    public static final String TAG = "DecryptActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();

        String action = intent.getAction();
        if (action.equals(Apg.Intent.DECRYPT_AND_RETURN)) {
            if (intent.getData() != null)
                Log.w(TAG, Apg.Intent.DECRYPT_AND_RETURN
                        + " " + getString(R.string.error_files_not_supported));
            Bundle extras = intent.getExtras();
            // add empty content so we don't have to check for null again
            if (extras == null)
                extras = new Bundle();

            boolean asciiArmor = extras.getBoolean(Apg.EXTRA_ASCII_ARMOUR, true);
            GnuPG.context.setArmor(asciiArmor);