/*

 */
package io.malloc.ccc;

import android.support.v4.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.wolfssl.wolfcrypt.Aes;
import com.wolfssl.wolfcrypt.WolfCryptException;

import io.malloc.ccc.Util;
/*
 * Simple Java UI to trigger jni function. It is exactly same as Java code
 * in hello-jni.
 */
public class MainActivity extends AppCompatActivity {

    private static final byte[] KEY = Util.h2b("00112233445566778899AABBCCDDEEFF");
    private static final byte[] IV = Util.h2b("000102030405060708090A0B0C0D0E0F");

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


        //        Aes aes = new Aes();
        //        TextView tv = new TextView(this);
        //        tv.setText( stringFromJNI() );
        //        setContentView(tv);
    }
//    public native String  stringFromJNI();
    static {

        System.loadLibrary("wolfssl-jni");
    }

    @Override
    protected void onStart() {
        super.onStart();
//        final Button button = (Button) findViewById(R.id.AESbutton);
//        button.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//                checkSetKeyParams();
//            }
//        });
    }

    public void checkSetKeyParams() {
        /* iv is optional, should not raise. */
        Aes aes = new Aes(KEY, null, Aes.ENCRYPT_MODE);

        try {
            aes.setKey(null, IV, Aes.ENCRYPT_MODE);
        } catch (WolfCryptException e) {
            System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage());
        }

        aes.setKey(KEY, IV, Aes.ENCRYPT_MODE);
        aes.releaseNativeStruct();

        try {
            aes.setKey(KEY, IV, Aes.ENCRYPT_MODE);
        } catch (WolfCryptException e) {
            System.out.println("ERROR: WolfCrypt: J3G: "+e.getMessage());
        }
    }
}

