Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
b893b81c
Commit
b893b81c
authored
8 years ago
by
ylecollen
Browse files
Options
Downloads
Patches
Plain Diff
Simplify signMessageJni
parent
60bcf865
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+51
-50
51 additions, 50 deletions
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
with
51 additions
and
50 deletions
java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_account.cpp
+
51
−
50
View file @
b893b81c
...
...
@@ -396,65 +396,66 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
**/
JNIEXPORT
jstring
OLM_ACCOUNT_FUNC_DEF
(
signMessageJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
aMessage
)
{
OlmAccount
*
accountPtr
=
NULL
;
size_t
signatureLength
;
void
*
signedMsgPtr
;
size_t
resultSign
;
jstring
signedMsgRetValue
=
NULL
;
OlmAccount
*
accountPtr
=
NULL
;
size_t
signatureLength
;
void
*
signedMsgPtr
;
size_t
resultSign
;
jstring
signedMsgRetValue
=
NULL
;
if
(
NULL
==
aMessage
)
{
LOGE
(
"## signMessageJni(): failure - invalid aMessage param"
);
}
else
if
(
NULL
==
(
accountPtr
=
(
OlmAccount
*
)
getAccountInstanceId
(
env
,
thiz
)))
if
(
NULL
==
aMessage
)
{
LOGE
(
"## signMessageJni(): failure - invalid aMessage param"
);
}
else
if
(
NULL
==
(
accountPtr
=
(
OlmAccount
*
)
getAccountInstanceId
(
env
,
thiz
)))
{
LOGE
(
"## signMessageJni(): failure - invalid account ptr"
);
}
else
{
int
messageLength
=
env
->
GetArrayLength
(
aMessage
);
jbyte
*
messageToSign
=
env
->
GetByteArrayElements
(
aMessage
,
NULL
);
// signature memory allocation
signatureLength
=
olm_account_signature_length
(
accountPtr
);
if
(
NULL
==
(
signedMsgPtr
=
(
void
*
)
malloc
((
signatureLength
+
1
)
*
sizeof
(
uint8_t
))))
{
LOGE
(
"## signMessageJni(): failure -
invalid account ptr
"
);
LOGE
(
"## signMessageJni(): failure -
signature allocation OOM
"
);
}
else
{
int
messageLength
=
env
->
GetArrayLength
(
aMessage
);
unsigned
char
*
messageToSign
=
new
unsigned
char
[
messageLength
];
env
->
GetByteArrayRegion
(
aMessage
,
0
,
messageLength
,
reinterpret_cast
<
jbyte
*>
(
messageToSign
));
// signature memory allocation
signatureLength
=
olm_account_signature_length
(
accountPtr
);
if
(
NULL
==
(
signedMsgPtr
=
(
void
*
)
malloc
((
signatureLength
+
1
)
*
sizeof
(
uint8_t
))))
{
LOGE
(
"## signMessageJni(): failure - signature allocation OOM"
);
}
else
{
// sign message
resultSign
=
olm_account_sign
(
accountPtr
,
(
void
*
)
messageToSign
,
(
size_t
)
messageLength
,
signedMsgPtr
,
signatureLength
);
if
(
resultSign
==
olm_error
())
{
LOGE
(
"## signMessageJni(): failure - error signing message Msg=%s"
,(
const
char
*
)
olm_account_last_error
(
accountPtr
));
}
else
{
// info: signatureLength is always equal to resultSign
(
static_cast
<
char
*>
(
signedMsgPtr
))[
signatureLength
]
=
static_cast
<
char
>
(
'\0'
);
// convert to jstring
signedMsgRetValue
=
env
->
NewStringUTF
((
const
char
*
)
signedMsgPtr
);
// UTF8
LOGD
(
"## signMessageJni(): success - retCode=%lu signatureLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
resultSign
),
static_cast
<
long
unsigned
int
>
(
signatureLength
));
}
free
(
signedMsgPtr
);
}
// release messageToSign
free
(
messageToSign
);
// sign message
resultSign
=
olm_account_sign
(
accountPtr
,
(
void
*
)
messageToSign
,
(
size_t
)
messageLength
,
signedMsgPtr
,
signatureLength
);
if
(
resultSign
==
olm_error
())
{
LOGE
(
"## signMessageJni(): failure - error signing message Msg=%s"
,(
const
char
*
)
olm_account_last_error
(
accountPtr
));
}
else
{
// info: signatureLength is always equal to resultSign
(
static_cast
<
char
*>
(
signedMsgPtr
))[
signatureLength
]
=
static_cast
<
char
>
(
'\0'
);
// convert to jstring
signedMsgRetValue
=
env
->
NewStringUTF
((
const
char
*
)
signedMsgPtr
);
// UTF8
LOGD
(
"## signMessageJni(): success - retCode=%lu signatureLength=%lu"
,
static_cast
<
long
unsigned
int
>
(
resultSign
),
static_cast
<
long
unsigned
int
>
(
signatureLength
));
}
free
(
signedMsgPtr
);
}
// release messageToSign
if
(
messageToSign
)
{
env
->
ReleaseByteArrayElements
(
aMessage
,
messageToSign
,
JNI_ABORT
);
}
}
return
signedMsgRetValue
;
return
signedMsgRetValue
;
}
/**
* Serialize and encrypt account instance into a base64 string.<br>
* @param aKey key used to encrypt the serialized account data
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment