Cleanups in Android implementation.
This commit is contained in:
parent
46c76ed065
commit
8611bfb5e0
|
@ -72,28 +72,22 @@ func Clip(x string) {
|
||||||
|
|
||||||
func (s *Store) nativeDecrypt(name string) (string, error) {
|
func (s *Store) nativeDecrypt(name string) (string, error) {
|
||||||
connect()
|
connect()
|
||||||
log.Printf("Decrypt(): connected")
|
|
||||||
data, err := ioutil.ReadFile(path.Join(s.Dir, strings.Join([]string{name, ".gpg"}, "")))
|
data, err := ioutil.ReadFile(path.Join(s.Dir, strings.Join([]string{name, ".gpg"}, "")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Error reading file: %s", err)
|
return "", fmt.Errorf("Error reading file: %s", err)
|
||||||
}
|
}
|
||||||
ret, err := pgp.Decrypt(string(data))
|
ret, err := pgp.Decrypt(string(data))
|
||||||
log.Printf("Decrypt(): got %s", ret)
|
log.Printf("nativeDecrypt(): got %s", ret)
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) nativeEncrypt(pw string) ([]byte, error) {
|
func (s *Store) nativeEncrypt(pw string) ([]byte, error) {
|
||||||
connect()
|
connect()
|
||||||
ret, err := Encrypt("", pw)
|
ret, err := pgp.Encrypt(s.Id, pw)
|
||||||
|
log.Printf("nativeEncrypt(): got %s", ret)
|
||||||
return []byte(ret), err
|
return []byte(ret), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Encrypt(id, data string) (string, error) {
|
|
||||||
connect()
|
|
||||||
log.Printf("Encrypt(): connected")
|
|
||||||
return pgp.Encrypt(id, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func nativeIdentities() ([]string, error) {
|
func nativeIdentities() ([]string, error) {
|
||||||
log.Printf("nativeIdentities()")
|
log.Printf("nativeIdentities()")
|
||||||
connect()
|
connect()
|
||||||
|
|
|
@ -35,10 +35,6 @@ void
|
||||||
InitPgpConnect(JNIEnv* env) {
|
InitPgpConnect(JNIEnv* env) {
|
||||||
jclass cls = FindClass(env, "st/wow/git/passgo/PgpConnect");
|
jclass cls = FindClass(env, "st/wow/git/passgo/PgpConnect");
|
||||||
printf("class = %p", cls);
|
printf("class = %p", cls);
|
||||||
//jmethodID init = (*env)->GetMethodID(env, cls, "<init>", "(Landroid/app/Activity;)V");
|
|
||||||
//printf("init = %p", init);
|
|
||||||
//jobject ret = (*env)->NewObject(env, cls, init, act);
|
|
||||||
//printf("obj = %p", ret);
|
|
||||||
|
|
||||||
static const JNINativeMethod actMethods[] = {
|
static const JNINativeMethod actMethods[] = {
|
||||||
{
|
{
|
||||||
|
@ -59,7 +55,6 @@ InitPgpConnect(JNIEnv* env) {
|
||||||
};
|
};
|
||||||
|
|
||||||
(*env)->RegisterNatives(env, cls, actMethods, sizeof(actMethods)/sizeof(actMethods[0]));
|
(*env)->RegisterNatives(env, cls, actMethods, sizeof(actMethods)/sizeof(actMethods[0]));
|
||||||
//return (*env)->NewGlobalRef(env, ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -74,10 +69,12 @@ GetId(JNIEnv* env, jobject p, int chint) {
|
||||||
void
|
void
|
||||||
Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, int chint) {
|
Decrypt(JNIEnv* env, jobject p, char* cdata, int datalen, int chint) {
|
||||||
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
||||||
|
if (datalen > 0) {
|
||||||
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
||||||
|
}
|
||||||
jclass cls = (*env)->GetObjectClass(env, p);
|
jclass cls = (*env)->GetObjectClass(env, p);
|
||||||
jmethodID mid = (*env)->GetMethodID(env, cls, "Decrypt", "([BI)V");
|
jmethodID mid = (*env)->GetMethodID(env, cls, "Decrypt", "([BI)V");
|
||||||
(*env)->CallObjectMethod(env, p, mid, data, chint);
|
(*env)->CallVoidMethod(env, p, mid, data, chint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
void stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
||||||
|
@ -92,12 +89,16 @@ void stringResult(JNIEnv* env, jclass cls, jint requestCode, jobject response) {
|
||||||
void
|
void
|
||||||
Encrypt(JNIEnv* env, jobject p, char* cid, int idlen, char* cdata, int datalen, int chint) {
|
Encrypt(JNIEnv* env, jobject p, char* cid, int idlen, char* cdata, int datalen, int chint) {
|
||||||
jbyteArray id = (*env)->NewByteArray(env, idlen);
|
jbyteArray id = (*env)->NewByteArray(env, idlen);
|
||||||
|
if (idlen > 0) {
|
||||||
(*env)->SetByteArrayRegion(env, id, 0, idlen, cid);
|
(*env)->SetByteArrayRegion(env, id, 0, idlen, cid);
|
||||||
|
}
|
||||||
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
jbyteArray data = (*env)->NewByteArray(env, datalen);
|
||||||
|
if (datalen > 0) {
|
||||||
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
(*env)->SetByteArrayRegion(env, data, 0, datalen, cdata);
|
||||||
|
}
|
||||||
jclass cls = (*env)->GetObjectClass(env, p);
|
jclass cls = (*env)->GetObjectClass(env, p);
|
||||||
jmethodID mid = (*env)->GetMethodID(env, cls, "Encrypt", "([B[BI)V");
|
jmethodID mid = (*env)->GetMethodID(env, cls, "Encrypt", "([B[BI)V");
|
||||||
(*env)->CallObjectMethod(env, p, mid, id, data, chint);
|
(*env)->CallVoidMethod(env, p, mid, id, data, chint);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
|
void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package passgo
|
package passgo
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -landroid
|
#cgo LDFLAGS: -landroid -llog
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "jni_android.h"
|
#include "jni_android.h"
|
||||||
|
@ -84,6 +84,7 @@ func (p PGP) GetId() (string, error) {
|
||||||
curint := chint
|
curint := chint
|
||||||
chint++
|
chint++
|
||||||
chmux.Unlock()
|
chmux.Unlock()
|
||||||
|
|
||||||
RunInJVM(func(env *JNIEnv) {
|
RunInJVM(func(env *JNIEnv) {
|
||||||
C.GetId(env, (C.jobject)(p), C.int(curint))
|
C.GetId(env, (C.jobject)(p), C.int(curint))
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user