From d77c52337ed2c72c720028509e77d07edfe1c09a Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Mon, 13 May 2019 16:56:34 +0200 Subject: [PATCH] bytearray as parameter for importKey --- src/basic_api.cc | 7 ++++--- src/gen_java_Engine.ysl2 | 45 ++++++++++++++++++++++++---------------- src/pEp.yml2 | 2 +- src/types_java.ysl2 | 3 +++ 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/basic_api.cc b/src/basic_api.cc index 1d825d7..84b03cc 100644 --- a/src/basic_api.cc +++ b/src/basic_api.cc @@ -195,20 +195,21 @@ JNIEXPORT void JNICALL Java_org_pEp_jniadapter_Engine_importKey( jbyteArray key ) { - char *_key = to_string(env, key); + size_t _size = (size_t) env->GetArrayLength(key); + char *_key = (char *) env->GetByteArrayElements(key, NULL); if(_key == NULL){ throw_pEp_Exception(env, PEP_OUT_OF_MEMORY); return; } - - PEP_STATUS status = ::import_key(session(), _key, strlen(_key), NULL); + PEP_STATUS status = ::import_key(session(), _key, _size, NULL); if (status != PEP_STATUS_OK && status != PEP_KEY_IMPORTED) { throw_pEp_Exception(env, status); return; } + env->ReleaseByteArrayElements(key, (jbyte *) _key, JNI_ABORT); } JNIEXPORT void JNICALL Java_org_pEp_jniadapter_Engine_config_1passive_1mode( diff --git a/src/gen_java_Engine.ysl2 b/src/gen_java_Engine.ysl2 index 27f927c..d169482 100644 --- a/src/gen_java_Engine.ysl2 +++ b/src/gen_java_Engine.ysl2 @@ -29,26 +29,35 @@ tstylesheet { const "itype" call "toIntermediate" with "type", "@type"; const "jtype" call "toJava" with "type", "@type"; - || - private native «$itype» «@name»(`apply "parm/*", mode=basic_iparm`); - - public «$jtype» «@name»(`apply "parm/*", mode=basic_parm`) { - || - apply "parm/*", mode=basic_parm_set; choose { - when "@type = 'void'" - |> «@name»(`apply "parm/*", mode=basic_parm_name`); - when "@type = 'identity'" - |> return new Identity(«@name»(`apply "parm/*", mode=basic_parm_name`)); - when "@type = 'bool'" - |> return new Boolean(«@name»(`apply "parm/*", mode=basic_parm_name`)); - otherwise - |> return AbstractEngine.toUTF16(«@name»(`apply "parm/*", mode=basic_parm_name`)); - } - || - } + when "name(parm/*[1])='bytearray'" + || + public native «$itype» «@name»(`apply "parm/*", mode=basic_iparm`); - || + || + otherwise { + || + private native «$itype» «@name»(`apply "parm/*", mode=basic_iparm`); + + public «$jtype» «@name»(`apply "parm/*", mode=basic_parm`) { + || + apply "parm/*", mode=basic_parm_set; + choose { + when "@type = 'void'" + |> «@name»(`apply "parm/*", mode=basic_parm_name`); + when "@type = 'identity'" + |> return new Identity(«@name»(`apply "parm/*", mode=basic_parm_name`)); + when "@type = 'bool'" + |> return new Boolean(«@name»(`apply "parm/*", mode=basic_parm_name`)); + otherwise + |> return AbstractEngine.toUTF16(«@name»(`apply "parm/*", mode=basic_parm_name`)); + } + || + } + + || + } + } } template "*", mode=basic_parm_name choose { diff --git a/src/pEp.yml2 b/src/pEp.yml2 index 8c85954..bdf1701 100644 --- a/src/pEp.yml2 +++ b/src/pEp.yml2 @@ -291,7 +291,7 @@ namespace pEp { basic void keyResetTrust(identity ident); basic void trustPersonalKey(identity ident); basic void trustOwnKey(identity ident); - basic void importKey(string key); + basic void importKey(bytearray key); basic void blacklist_add(string fpr); basic void blacklist_delete(string fpr); basic bool blacklist_is_listed(string fpr); diff --git a/src/types_java.ysl2 b/src/types_java.ysl2 index 3922649..7c929f6 100644 --- a/src/types_java.ysl2 +++ b/src/types_java.ysl2 @@ -15,6 +15,7 @@ function "toJava" { when "$type='identitylist'" > Vector when "$type='stringlist'" > Vector when "$type='stringpairlist'" > ArrayList> + when "$type='bytearray'" > byte[] when "$type='Color'" > Color when "$type='DecryptFlags'" > DecryptFlags @@ -31,6 +32,7 @@ function "toSig" { choose { when "$type='string'" error | # cannot declare "string" when "$type='bool'" > Z + when "$type='bytearray'" > [b otherwise { > L choose { @@ -65,6 +67,7 @@ function "toIntermediate" { when "$type='bool'" > boolean when "$type='int'" > int when "$type='string' or $type='sstring'" > byte[] + when "$type='bytearray' or $type='sstring'" > byte[] when "$type='bloblist'" > Vector<_Blob> when "$type='identity'" > _Identity