aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMInboundGroupSession.m
diff options
context:
space:
mode:
authorRichard van der Hoff <github@rvanderhoff.org.uk>2017-01-17 15:16:16 +0000
committerGitHub <noreply@github.com>2017-01-17 15:16:16 +0000
commita45c3cc80957d61065626089eee4ce664ad1615f (patch)
treec467aafb4df13fc31576e49a7909cc2fe2088328 /xcode/OLMKit/OLMInboundGroupSession.m
parentc14f4b28b985a3ca8f8ff4218c7a2a74cf65a580 (diff)
parentded15597c6736d33bac74d34251c8527e5fa360f (diff)
Merge pull request #44 from matrix-org/manuroe/olmkit-backup
OLMKit: Add wrappers for export/import of inbound group sessions
Diffstat (limited to 'xcode/OLMKit/OLMInboundGroupSession.m')
-rw-r--r--xcode/OLMKit/OLMInboundGroupSession.m55
1 files changed, 55 insertions, 0 deletions
diff --git a/xcode/OLMKit/OLMInboundGroupSession.m b/xcode/OLMKit/OLMInboundGroupSession.m
index 6ef51c3..08459ca 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,34 @@
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];
+ [key resetBytesInRange:NSMakeRange(0, key.length)];
+ return keyString;
+}
+
#pragma mark OLMSerializable