Apply OCD

pull/14/head
Niels Andriesse 6 years ago
parent e04944d4f3
commit f748fbd4cc

@ -6,18 +6,18 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSPrimaryStorage (Loki) @interface OWSPrimaryStorage (Loki)
# pragma mark - Prekey for contacts # pragma mark - Prekey for Contact
/** /**
Check if we have PreKeyRecord for the given contact. Check if we have a `PreKeyRecord` for the given contact.
@param pubKey The hex encoded public ket of the contact. @param pubKey The hex encoded public key of the contact.
@return Whether we have a prekey or not. @return Whether we have a prekey or not.
*/ */
- (BOOL)hasPreKeyForContact:(NSString *)pubKey; - (BOOL)hasPreKeyForContact:(NSString *)pubKey;
/** /**
Get the PreKeyRecord associated with the given contact. Get the `PreKeyRecord` associated with the given contact.
If the record doesn't exist then this will create a new one. If the record doesn't exist then this will create a new one.
@param pubKey The hex encoded public key of the contact. @param pubKey The hex encoded public key of the contact.
@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
# pragma mark - PreKeyBundle # pragma mark - PreKeyBundle
/** /**
Generate a PreKeyBundle for the given contact. Generate a `PreKeyBundle` for the given contact.
This doesn't store the pre key bundle, and you shouldn't store this bundle. This doesn't store the pre key bundle, and you shouldn't store this bundle.
It's used for generating bundles to send to other users. It's used for generating bundles to send to other users.
@ -38,15 +38,15 @@ NS_ASSUME_NONNULL_BEGIN
- (PreKeyBundle *)generatePreKeyBundleForContact:(NSString *)pubKey; - (PreKeyBundle *)generatePreKeyBundleForContact:(NSString *)pubKey;
/** /**
Get the PreKeyBundle associated with the given contact. Get the `PreKeyBundle` associated with the given contact.
@param pubKey The hex encoded public key of the contact. @param pubKey The hex encoded public key of the contact.
@return The pre key bundle or nil if it doesn't exist. @return The pre key bundle or `nil` if it doesn't exist.
*/ */
- (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey; - (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey;
/** /**
Set the PreKeyBundle for the given contact. Set the `PreKeyBundle` for the given contact.
@param bundle The pre key bundle. @param bundle The pre key bundle.
@param pubKey The hex encoded public key of the contact. @param pubKey The hex encoded public key of the contact.
@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey; - (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey;
/** /**
Remove the PreKeyBundle for the given contact. Remove the `PreKeyBundle` for the given contact.
@param pubKey The hex encoded public key of the contact. @param pubKey The hex encoded public key of the contact.
*/ */

@ -23,7 +23,7 @@
return TSAccountManager.sharedInstance; return TSAccountManager.sharedInstance;
} }
# pragma mark - Prekey for contacts # pragma mark - Prekey for Contact
- (BOOL)hasPreKeyForContact:(NSString *)pubKey { - (BOOL)hasPreKeyForContact:(NSString *)pubKey {
int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection]; int preKeyId = [self.dbReadWriteConnection intForKey:pubKey inCollection:LokiPreKeyContactCollection];
@ -68,8 +68,8 @@
// Check prekeys to make sure we have them for this function // Check prekeys to make sure we have them for this function
[TSPreKeyManager checkPreKeys]; [TSPreKeyManager checkPreKeys];
ECKeyPair *_Nullable myKeyPair = self.identityManager.identityKeyPair; ECKeyPair *_Nullable keyPair = self.identityManager.identityKeyPair;
OWSAssertDebug(myKeyPair); OWSAssertDebug(keyPair);
SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey]; SignedPreKeyRecord *_Nullable signedPreKey = [self currentSignedPreKey];
if (!signedPreKey) { if (!signedPreKey) {
@ -86,13 +86,12 @@
signedPreKeyPublic:signedPreKey.keyPair.publicKey.prependKeyType signedPreKeyPublic:signedPreKey.keyPair.publicKey.prependKeyType
signedPreKeyId:signedPreKey.Id signedPreKeyId:signedPreKey.Id
signedPreKeySignature:signedPreKey.signature signedPreKeySignature:signedPreKey.signature
identityKey:myKeyPair.publicKey.prependKeyType]; identityKey:keyPair.publicKey.prependKeyType];
return bundle; return bundle;
} }
- (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey { - (PreKeyBundle *_Nullable)getPreKeyBundleForContact:(NSString *)pubKey {
PreKeyBundle *bundle = [self.dbReadWriteConnection preKeyBundleForKey:pubKey inCollection:LokiPreKeyBundleCollection]; return [self.dbReadWriteConnection preKeyBundleForKey:pubKey inCollection:LokiPreKeyBundleCollection];
return bundle;
} }
- (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey { - (void)setPreKeyBundle:(PreKeyBundle *)bundle forContact:(NSString *)pubKey {
@ -101,10 +100,8 @@
inCollection:LokiPreKeyBundleCollection]; inCollection:LokiPreKeyBundleCollection];
} }
- (void)removePreKeyBundleForContact:(NSString *)pubKey - (void)removePreKeyBundleForContact:(NSString *)pubKey {
{ [self.dbReadWriteConnection removeObjectForKey:pubKey inCollection:LokiPreKeyBundleCollection];
[self.dbReadWriteConnection removeObjectForKey:pubKey
inCollection:LokiPreKeyBundleCollection];
} }
@end @end

@ -1,15 +1,16 @@
public extension SSKProtoPrekeyBundleMessage {
@objc public extension SSKProtoPrekeyBundleMessage {
@objc public var preKeyBundle: PreKeyBundle? { @objc public var preKeyBundle: PreKeyBundle? {
let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId() let registrationId = TSAccountManager.sharedInstance().getOrGenerateRegistrationId()
return PreKeyBundle(registrationId: Int32(registrationId), return PreKeyBundle(registrationId: Int32(registrationId),
deviceId: Int32(self.deviceID), deviceId: Int32(deviceID),
preKeyId: Int32(self.prekeyID), preKeyId: Int32(prekeyID),
preKeyPublic: self.prekey, preKeyPublic: prekey,
signedPreKeyPublic: self.signedKey, signedPreKeyPublic: signedKey,
signedPreKeyId: Int32(self.signedKeyID), signedPreKeyId: Int32(signedKeyID),
signedPreKeySignature: self.signature, signedPreKeySignature: signature,
identityKey: self.identityKey) identityKey: identityKey)
} }
@objc public class func builder(fromPreKeyBundle preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder { @objc public class func builder(fromPreKeyBundle preKeyBundle: PreKeyBundle) -> SSKProtoPrekeyBundleMessageBuilder {

@ -1,4 +1,4 @@
#import <SignalServiceKit/SignalServiceKit.h> #import "SignalServiceKit.h"
#import "TSOutgoingMessage.h" #import "TSOutgoingMessage.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

@ -8,7 +8,7 @@
- (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)recipient { - (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)recipient {
SSKProtoContentBuilder *contentBuilder = [super contentBuilder:recipient]; SSKProtoContentBuilder *contentBuilder = [super contentBuilder:recipient];
PreKeyBundle *bundle = [[OWSPrimaryStorage sharedManager] generatePreKeyBundleForContact:recipient.recipientId]; PreKeyBundle *bundle = [OWSPrimaryStorage.sharedManager generatePreKeyBundleForContact:recipient.recipientId];
SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle]; SSKProtoPrekeyBundleMessageBuilder *preKeyBuilder = [SSKProtoPrekeyBundleMessage builderFromPreKeyBundle:bundle];
// Build the pre key bundle message // Build the pre key bundle message

Loading…
Cancel
Save