Browse Source

JNI-167: add Message.encodeASN1XER()

JNI-167
heck 3 years ago
parent
commit
12ff0ec89a
  1. 56
      src/codegen/gen_cpp_Message.ysl2
  2. 6
      src/codegen/gen_java_Message.ysl2

56
src/codegen/gen_cpp_Message.ysl2

@ -17,6 +17,8 @@ tstylesheet {
||
#include <cassert>
#include <pEp/mime.h>
#include <pEp/map_asn1.h>
#include <pEp/message_codec.h>
#include <pEp/pEpLog.hh>
#include "jniutils.hh"
#include "throw_pEp_exception.hh"
@ -113,6 +115,60 @@ tstylesheet {
return result;
}
JNIEXPORT jbyteArray JNICALL Java_foundation_pEp_jniadapter_Message__1encodeASN1XER(JNIEnv *env, jobject obj)
{
pEpLog("called");
message* _obj = nullptr;
try {
_obj = message_ptr(env, obj);
} catch(...) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<jbyteArray>(NULL);
}
// create ASN1Message
ASN1Message_t *pm = ::ASN1Message_from_message(_obj, NULL, true, 0);
if (pm == nullptr) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<jbyteArray>(NULL);
}
// encode PER
char *data_per = nullptr;
size_t data_size_per = 0;
PEP_STATUS status = ::encode_ASN1Message_message(pm, &data_per, &data_size_per);
if (status) {
throw_pEp_Exception(env, status);
}
if (data_per == nullptr) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<jbyteArray>(NULL);
}
// encode PER to XER
char *data_xer = nullptr;
status = ::PER_to_XER_ASN1Message_msg(data_per, data_size_per, &data_xer);
if (status) {
throw_pEp_Exception(env, status);
}
if (data_xer == nullptr) {
jclass ex = env->FindClass("java/lang/IllegalStateException");
assert(ex);
env->ThrowNew(ex, nullptr);
return static_cast<jbyteArray>(NULL);
}
jbyteArray result = from_string(env, data_xer);
return result;
}
||
apply "*[name(.)!='enum']", 0, mode=entry {
with "name", "@name";

6
src/codegen/gen_java_Message.ysl2

@ -64,6 +64,12 @@ tstylesheet {
return Utils.toUTF16(_encodeMIME());
}
private native byte[] _encodeASN1XER() throws pEpException;
public String encodeASN1XER() {
return Utils.toUTF16(_encodeASN1XER());
}
private «$cname»(long h) {
handle = h;
instanceCount.getAndIncrement();

Loading…
Cancel
Save