diff --git a/src/Contacts/Threads/TSGroupThread.m b/src/Contacts/Threads/TSGroupThread.m index b655ef169..2dadd57b0 100644 --- a/src/Contacts/Threads/TSGroupThread.m +++ b/src/Contacts/Threads/TSGroupThread.m @@ -86,7 +86,6 @@ NS_ASSUME_NONNULL_BEGIN return [NSData dataFromBase64String:[threadId substringWithRange:NSMakeRange(1, threadId.length - 1)]]; } - // Group and Contact threads share a collection, this is a convenient way to enumerate *just* the group threads + (void)enumerateGroupThreadsUsingBlock:(void (^)(TSGroupThread *groupThread, BOOL *stop))block { diff --git a/src/Security/OWSFingerprint.m b/src/Security/OWSFingerprint.m index 79ecdc705..b8ba10b32 100644 --- a/src/Security/OWSFingerprint.m +++ b/src/Security/OWSFingerprint.m @@ -35,8 +35,8 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200; theirName:(NSString *)theirName hashIterations:(uint32_t)hashIterations { - NSParameterAssert(theirIdentityKeyWithoutKeyType.length == 32); - NSParameterAssert(myIdentityKeyWithoutKeyType.length == 32); + OWSAssert(theirIdentityKeyWithoutKeyType.length == 32); + OWSAssert(myIdentityKeyWithoutKeyType.length == 32); self = [super init]; if (!self) { @@ -205,8 +205,8 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200; */ - (NSData *)dataForStableId:(NSData *)stableIdData publicKey:(NSData *)publicKey { - NSParameterAssert(stableIdData); - NSParameterAssert(publicKey); + OWSAssert(stableIdData); + OWSAssert(publicKey); NSData *versionData = [self dataFromShort:OWSFingerprintHashingVersion]; NSMutableData *hash = [NSMutableData dataWithData:versionData]; @@ -227,7 +227,7 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200; - (NSString *)stringForFingerprintData:(NSData *)data { - NSParameterAssert(data); + OWSAssert(data); return [NSString stringWithFormat:@"%@%@%@%@%@%@", [self encodedChunkFromData:data offset:0], @@ -240,7 +240,7 @@ static uint32_t const OWSFingerprintDefaultHashIterations = 5200; - (NSString *)encodedChunkFromData:(NSData *)data offset:(uint)offset { - NSParameterAssert(data); + OWSAssert(data); uint8_t fiveBytes[5]; [data getBytes:fiveBytes range:NSMakeRange(offset, 5)]; diff --git a/src/Security/OWSRecipientIdentity.h b/src/Security/OWSRecipientIdentity.h index b34f7e879..522257f30 100644 --- a/src/Security/OWSRecipientIdentity.h +++ b/src/Security/OWSRecipientIdentity.h @@ -11,15 +11,13 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSString *recipientId; @property (nonatomic, readonly) NSData *identityKey; @property (nonatomic, readonly) NSDate *createdAt; -@property (nonatomic, readonly) BOOL wasSeen; +@property (atomic, readonly) BOOL wasSeen; @property (nonatomic, readonly) BOOL isFirstKnownKey; -@property (nonatomic) BOOL approvedForBlockingUse; -@property (nonatomic) BOOL approvedForNonBlockingUse; +@property (atomic) BOOL approvedForBlockingUse; +@property (atomic) BOOL approvedForNonBlockingUse; - (instancetype)initWithUniqueId:(NSString *)uniqueId NS_UNAVAILABLE; -- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - - (instancetype)initWithRecipientId:(NSString *)recipientId identityKey:(NSData *)identityKey isFirstKnownKey:(BOOL)isFirstKnownKey diff --git a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h index 07f141dd6..2733aeca7 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h +++ b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.h @@ -14,6 +14,15 @@ extern NSString *const TSStorageManagerTrustedKeysCollection; /** * Explicitly mark an identity as approved for blocking/nonblocking use * e.g. in response to a user confirmation action. + * + * @param identityKey key data used to identify the recipient + * @param recipientId unique stable identifier for the recipient, e.g. e164 phone number + * @param approvedForBlockingUse if the user wants explicit confirmation before sending to changed numbers, whether + * that confirmation has occurred. + * @param approvedForNonBlockingUse YES to override the duration during which we consider an SN "too soon" to send. + * + * @returns YES if we are replacing an existing known identity key for recipientId. + * NO if there was no previously stored identity key for the recipient. */ - (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId diff --git a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m index 7f0dd3dcb..554e701d0 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m +++ b/src/Storage/AxolotlStore/TSStorageManager+IdentityKeyStore.m @@ -66,8 +66,8 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; - (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId { - NSParameterAssert(identityKey != nil); - NSParameterAssert(recipientId != nil); + OWSAssert(identityKey != nil); + OWSAssert(recipientId != nil); @synchronized([[self class] sharedIdentityKeyLock]) { @@ -87,8 +87,8 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; approvedForBlockingUse:(BOOL)approvedForBlockingUse approvedForNonBlockingUse:(BOOL)approvedForNonBlockingUse { - NSParameterAssert(identityKey != nil); - NSParameterAssert(recipientId != nil); + OWSAssert(identityKey != nil); + OWSAssert(recipientId != nil); NSString const *logTag = @"[IdentityKeyStore]"; @synchronized ([[self class] sharedIdentityKeyLock]) { @@ -134,9 +134,9 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; recipientId:(NSString *)recipientId direction:(TSMessageDirection)direction { - NSParameterAssert(identityKey != nil); - NSParameterAssert(recipientId != nil); - NSParameterAssert(direction != TSMessageDirectionUnknown); + OWSAssert(identityKey != nil); + OWSAssert(recipientId != nil); + OWSAssert(direction != TSMessageDirectionUnknown); @synchronized([[self class] sharedIdentityKeyLock]) { @@ -172,7 +172,7 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; - (BOOL)isTrustedKey:(NSData *)identityKey forSendingToIdentity:(nullable OWSRecipientIdentity *)recipientIdentity { - NSParameterAssert(identityKey != nil); + OWSAssert(identityKey != nil); @synchronized([[self class] sharedIdentityKeyLock]) { @@ -207,7 +207,7 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; - (BOOL)isBlockingApprovalRequiredForIdentity:(OWSRecipientIdentity *)recipientIdentity { - NSParameterAssert(recipientIdentity != nil); + OWSAssert(recipientIdentity != nil); OWSAssert([TextSecureKitEnv sharedEnv].preferences != nil); return !recipientIdentity.isFirstKnownKey && @@ -217,7 +217,7 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; - (BOOL)isNonBlockingApprovalRequiredForIdentity:(OWSRecipientIdentity *)recipientIdentity { - NSParameterAssert(recipientIdentity != nil); + OWSAssert(recipientIdentity != nil); return !recipientIdentity.isFirstKnownKey && [[NSDate new] timeIntervalSinceDate:recipientIdentity.createdAt] < kIdentityKeyStoreNonBlockingSecondsThreshold && @@ -226,14 +226,14 @@ const NSTimeInterval kIdentityKeyStoreNonBlockingSecondsThreshold = 5.0; - (void)removeIdentityKeyForRecipient:(NSString *)recipientId { - NSParameterAssert(recipientId != nil); + OWSAssert(recipientId != nil); [[OWSRecipientIdentity fetchObjectWithUniqueID:recipientId] remove]; } - (void)createIdentityChangeInfoMessageForRecipientId:(NSString *)recipientId { - NSParameterAssert(recipientId != nil); + OWSAssert(recipientId != nil); TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:recipientId]; OWSAssert(contactThread != nil);