aboutsummaryrefslogtreecommitdiff
path: root/xcode
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2016-09-28 16:06:11 +0200
committermanuroe <manu@matrix.org>2016-09-28 16:06:11 +0200
commit103de505182e569bc811eac1e8ded216e5ae0908 (patch)
treeebce8da8d89da78185300a973be7562ef0ba32a8 /xcode
parent6f113dd7b3b4de918c4efb81d38a1ffe1d391b5b (diff)
OLMKit: Implement missing [OLMAccount signMessage:]
Diffstat (limited to 'xcode')
-rw-r--r--xcode/OLMKit/OLMAccount.m19
1 files changed, 19 insertions, 0 deletions
diff --git a/xcode/OLMKit/OLMAccount.m b/xcode/OLMKit/OLMAccount.m
index 4561a37..77fddac 100644
--- a/xcode/OLMKit/OLMAccount.m
+++ b/xcode/OLMKit/OLMAccount.m
@@ -92,6 +92,25 @@
return keysDictionary;
}
+- (NSString *)signMessage:(NSData *)messageData {
+ size_t signatureLength = olm_account_signature_length(_account);
+ uint8_t *signatureBytes = malloc(signatureLength);
+ if (!signatureBytes) {
+ return nil;
+ }
+
+ size_t result = olm_account_sign(_account, messageData.bytes, messageData.length, signatureBytes, signatureLength);
+ if (result == olm_error()) {
+ const char *error = olm_account_last_error(_account);
+ NSLog(@"error signing message: %s", error);
+ free(signatureBytes);
+ return nil;
+ }
+
+ NSData *signatureData = [NSData dataWithBytesNoCopy:signatureBytes length:signatureLength freeWhenDone:YES];
+ return [[NSString alloc] initWithData:signatureData encoding:NSUTF8StringEncoding];
+}
+
- (NSDictionary*) oneTimeKeys {
size_t otkLength = olm_account_one_time_keys_length(_account);
uint8_t *otkBytes = malloc(otkLength);