aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMInboundGroupSession.m
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2017-01-17 14:47:41 +0100
committermanuroe <manu@matrix.org>2017-01-17 14:47:41 +0100
commit885b85f5167d2d3ddcbe3de41dc88e8586b01a57 (patch)
treed9d05e75aa7fcf49584cb608ea284899c0eb2cd9 /xcode/OLMKit/OLMInboundGroupSession.m
parent860740a91ee0efcf3c594ece23ef0a38ddda394e (diff)
OLMKit: Add wrappers for export/import of inbound group sessions
Diffstat (limited to 'xcode/OLMKit/OLMInboundGroupSession.m')
-rw-r--r--xcode/OLMKit/OLMInboundGroupSession.m54
1 files changed, 54 insertions, 0 deletions
diff --git a/xcode/OLMKit/OLMInboundGroupSession.m b/xcode/OLMKit/OLMInboundGroupSession.m
index 6ef51c3..3ef02e8 100644
--- a/xcode/OLMKit/OLMInboundGroupSession.m
+++ b/xcode/OLMKit/OLMInboundGroupSession.m
@@ -76,6 +76,33 @@
return self;
}
+- (instancetype)initInboundGroupSessionWithImportedSession:(NSString *)sessionKey error:(NSError *__autoreleasing *)error
+{
+ self = [self init];
+ if (self) {
+ NSData *sessionKeyData = [sessionKey dataUsingEncoding:NSUTF8StringEncoding];
+ size_t result = olm_import_inbound_group_session(session, sessionKeyData.bytes, sessionKeyData.length);
+ if (result == olm_error()) {
+ const char *olm_error = olm_inbound_group_session_last_error(session);
+
+ NSString *errorString = [NSString stringWithUTF8String:olm_error];
+ NSLog(@"olm_import_inbound_group_session error: %@", errorString);
+
+ if (error && olm_error && errorString) {
+ *error = [NSError errorWithDomain:OLMErrorDomain
+ code:0
+ userInfo:@{
+ NSLocalizedDescriptionKey: errorString,
+ NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"olm_import_inbound_group_session error: %@", errorString]
+ }];
+ }
+
+ return nil;
+ }
+ }
+ return self;
+}
+
- (NSString *)sessionIdentifier {
size_t length = olm_inbound_group_session_id_length(session);
NSMutableData *idData = [NSMutableData dataWithLength:length];
@@ -153,6 +180,33 @@
return plaintext;
}
+- (NSUInteger)firstKnownIndex
+{
+ return olm_inbound_group_session_first_known_index(session);
+}
+
+- (BOOL)isVerified
+{
+ return (0 != olm_inbound_group_session_is_verified(session));
+}
+
+- (NSString*)exportSessionAtMessageIndex:(NSUInteger*)messageIndex error:(NSError**)error;
+{
+ size_t length = olm_export_inbound_group_session_length(session);
+ NSMutableData *key = [NSMutableData dataWithLength:length];
+ size_t result = olm_export_inbound_group_session(session, key.mutableBytes, key.length, messageIndex);
+ if (result == olm_error()) {
+ const char *olm_error = olm_inbound_group_session_last_error(session);
+ NSString *errorString = [NSString stringWithUTF8String:olm_error];
+ if (error && errorString) {
+ *error = [NSError errorWithDomain:OLMErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
+ }
+ return nil;
+ }
+ NSString *keyString = [[NSString alloc] initWithData:key encoding:NSUTF8StringEncoding];
+ return keyString;
+}
+
#pragma mark OLMSerializable