// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java
// public class Md5 {
//     public static final String TAG = "Md5";
// 
//     /**
//      * Hashes the input string
//      *
//      * @param text The text to be hashed
//      * @return The hash of the input converted to string
//      */
//     public final static String hash(String text) {
//         try {
//             MessageDigest md5 = MessageDigest.getInstance("MD5");
//             md5.update(text.getBytes("iso-8859-1"), 0, text.length());
//             byte[] md5hash = md5.digest();
//             StringBuilder sb = new StringBuilder();
//             for (int i = 0; i < md5hash.length; ++i) {
//                 sb.append(String.format("%02x", md5hash[i]));
//             }
//             return sb.toString();
//         }
//         catch (Exception e) {
//             Log.w(TAG, "Error when calculating MD5 hash");
//             return "";
//         }
//     }
// }
// 
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java
// public enum Behavior {
//     DEFAULT,
//     NO_REPLY,
//     FAILURE,
//     TRUNCATED_DATA
// }


import edu.berkeley.boinc.Md5;
import edu.berkeley.boinc.testutil.BoincClientStub.Behavior;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

    private void handleRequest(String request) {
        Log.d(TAG, "handleRequest(" + request + ")");
        Behavior behavior;
        synchronized (this) {
            behavior = mBehavior;
        }
        if (behavior == Behavior.NO_REPLY) {
            Log.d(TAG, "handleRequest(): behavior NO_REPLY, not doing anything");
            return;
        }
        else if (behavior == Behavior.TRUNCATED_DATA) {
            mOutput.println("<boinc_gui_rpc_reply>");
            mOutput.print("<");
            mOutput.flush();
            return;
        }
        else if (behavior == Behavior.FAILURE) {
            mOutput.println("<boinc_gui_rpc_reply>");
            mOutput.println("<failure/>");
            mOutput.print("</boinc_gui_rpc_reply>");
            mOutput.print('\003');
            mOutput.flush();
            return;
        }
        String detectedRequest = RpcRequestParser.parse(request);
        if (detectedRequest.equals("auth1")) {
            // Authorization part 1
            if (!mAuthorized) {
                final float nonce = System.currentTimeMillis() / 1000;
// Path: BoincRpc/src/main/java/edu/berkeley/boinc/Md5.java
// public class Md5 {
//     public static final String TAG = "Md5";
// 
//     /**
//      * Hashes the input string
//      *
//      * @param text The text to be hashed
//      * @return The hash of the input converted to string
//      */
//     public final static String hash(String text) {
//         try {
//             MessageDigest md5 = MessageDigest.getInstance("MD5");
//             md5.update(text.getBytes("iso-8859-1"), 0, text.length());
//             byte[] md5hash = md5.digest();
//             StringBuilder sb = new StringBuilder();
//             for (int i = 0; i < md5hash.length; ++i) {
//                 sb.append(String.format("%02x", md5hash[i]));
//             }
//             return sb.toString();
//         }
//         catch (Exception e) {
//             Log.w(TAG, "Error when calculating MD5 hash");
//             return "";
//         }
//     }
// }
// 
// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStub.java
// public enum Behavior {
//     DEFAULT,
//     NO_REPLY,
//     FAILURE,
//     TRUNCATED_DATA
// }


// Path: BoincRpc/src/androidTest/java/edu/berkeley/boinc/testutil/BoincClientStubWorker.java
import edu.berkeley.boinc.Md5;
import edu.berkeley.boinc.testutil.BoincClientStub.Behavior;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;


    private void handleRequest(String request) {
        Log.d(TAG, "handleRequest(" + request + ")");
        Behavior behavior;
        synchronized (this) {
            behavior = mBehavior;
        }
        if (behavior == Behavior.NO_REPLY) {
            Log.d(TAG, "handleRequest(): behavior NO_REPLY, not doing anything");
            return;
        }
        else if (behavior == Behavior.TRUNCATED_DATA) {
            mOutput.println("<boinc_gui_rpc_reply>");
            mOutput.print("<");
            mOutput.flush();
            return;
        }
        else if (behavior == Behavior.FAILURE) {
            mOutput.println("<boinc_gui_rpc_reply>");
            mOutput.println("<failure/>");
            mOutput.print("</boinc_gui_rpc_reply>");
            mOutput.print('\003');
            mOutput.flush();
            return;
        }
        String detectedRequest = RpcRequestParser.parse(request);
        if (detectedRequest.equals("auth1")) {
            // Authorization part 1
            if (!mAuthorized) {
                final float nonce = System.currentTimeMillis() / 1000;
                mNonceHash = Md5.hash(Float.toString(nonce) + mPassword);