OLMKit: Forgot to implement pickle v2 for OLMSession

This commit is contained in:
manuroe 2021-02-19 12:00:03 +01:00
parent b69b56d0bb
commit 4be7cc367b

View file

@ -21,6 +21,7 @@
#import "OLMAccount_Private.h"
#import "OLMSession_Private.h"
#include "olm/olm.h"
#import "OLMKit.h"
@implementation OLMSession
@ -359,6 +360,13 @@
self = [self initWithSerializedData:pickle key:key error:&error];
}
else if ([version isEqualToString:@"2"]) {
NSString *pickle = [decoder decodeObjectOfClass:[NSString class] forKey:@"pickle"];
NSData *key = OLMKit.sharedInstance.pickleKeyDelegate.pickleKey;
NSParameterAssert(key);
self = [self initWithSerializedData:pickle key:key error:&error];
}
NSParameterAssert(error == nil);
NSParameterAssert(self != nil);
@ -370,14 +378,23 @@
}
- (void)encodeWithCoder:(NSCoder *)encoder {
NSData *key = [OLMUtility randomBytesOfLength:32];
NSData *key = OLMKit.sharedInstance.pickleKeyDelegate.pickleKey;
if (key)
{
[encoder encodeObject:@"2" forKey:@"version"];
}
else
{
key = [OLMUtility randomBytesOfLength:32];
[encoder encodeObject:key forKey:@"key"];
[encoder encodeObject:@"1" forKey:@"version"];
}
NSError *error = nil;
NSString *pickle = [self serializeDataWithKey:key error:&error];
NSParameterAssert(pickle.length > 0 && error == nil);
[encoder encodeObject:pickle forKey:@"pickle"];
[encoder encodeObject:key forKey:@"key"];
[encoder encodeObject:@"1" forKey:@"version"];
}
@end