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)
# 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.
*/
- (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.
@param pubKey The hex encoded public key of the contact.
@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
# 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.
It's used for generating bundles to send to other users.
@ -38,15 +38,15 @@ NS_ASSUME_NONNULL_BEGIN
- (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.
@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;
/**
Set the PreKeyBundle for the given contact.
Set the `PreKeyBundle` for the given contact.
@param bundle The pre key bundle.
@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;
/**
Remove the PreKeyBundle for the given contact.
Remove the `PreKeyBundle` for the given contact.
@param pubKey The hex encoded public key of the contact.
*/

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

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

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

@ -8,7 +8,7 @@
- (SSKProtoContentBuilder *)contentBuilder:(SignalRecipient *)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];
// Build the pre key bundle message

Loading…
Cancel
Save