From cb9aa6304ccf4992bdc5b908ffb025e805db2346 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 30 Oct 2018 09:21:26 -0600 Subject: [PATCH] find -E . -type f -regex ".*\.(m|h)" -exec sed -i "" -e "s/try_/throws_/" {} \; --- .../Models/OWSDeviceProvisioningURLParser.m | 2 +- .../ConversationViewController.m | 2 +- SignalMessaging/utils/ThreadUtil.m | 2 +- .../src/Contacts/ContactDiscoveryService.m | 6 ++-- SignalServiceKit/src/Contacts/TSThread.m | 2 +- .../src/Devices/OWSProvisioningCipher.m | 8 ++--- .../TSInvalidIdentityKeyErrorMessage.h | 4 +-- .../TSInvalidIdentityKeyErrorMessage.m | 4 +-- ...SInvalidIdentityKeyReceivingErrorMessage.m | 10 +++--- .../TSInvalidIdentityKeySendingErrorMessage.m | 8 ++--- .../src/Messages/OWSBatchMessageProcessor.m | 6 ++-- .../src/Messages/OWSIdentityManager.h | 4 +-- .../src/Messages/OWSIdentityManager.m | 6 ++-- .../src/Messages/OWSMessageDecrypter.m | 26 +++++++-------- .../src/Messages/OWSMessageManager.h | 6 ++-- .../src/Messages/OWSMessageManager.m | 26 ++++++++------- .../src/Messages/OWSMessageSender.m | 32 +++++++++---------- .../OWSPrimaryStorage+PreKeyStore.m | 2 +- .../OWSPrimaryStorage+SignedPreKeyStore.m | 6 ++-- .../tests/Storage/TSStoragePreKeyStoreTests.m | 8 ++--- 20 files changed, 86 insertions(+), 84 deletions(-) diff --git a/Signal/src/Models/OWSDeviceProvisioningURLParser.m b/Signal/src/Models/OWSDeviceProvisioningURLParser.m index 3710b5d09..3ae5d8665 100644 --- a/Signal/src/Models/OWSDeviceProvisioningURLParser.m +++ b/Signal/src/Models/OWSDeviceProvisioningURLParser.m @@ -27,7 +27,7 @@ NSString *const OWSQueryItemNameEncodedPublicKeyKey = @"pub_key"; } else if ([queryItem.name isEqualToString:OWSQueryItemNameEncodedPublicKeyKey]) { NSString *encodedPublicKey = queryItem.value; @try { - _publicKey = [[NSData dataFromBase64String:encodedPublicKey] try_removeKeyType]; + _publicKey = [[NSData dataFromBase64String:encodedPublicKey] throws_removeKeyType]; } @catch (NSException *exception) { OWSFailDebug(@"exception: %@", exception); } diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index d7fa7a29f..a5067d467 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1903,7 +1903,7 @@ typedef enum : NSUInteger { if ([errorMessage isKindOfClass:[TSInvalidIdentityKeyReceivingErrorMessage class]]) { // Deliberately crash if the user fails to explicitly accept the new identity // key. In practice we haven't been creating these messags in over a year. - [errorMessage try_acceptNewIdentityKey]; + [errorMessage throws_acceptNewIdentityKey]; } }]; [actionSheetController addAction:acceptSafetyNumberAction]; diff --git a/SignalMessaging/utils/ThreadUtil.m b/SignalMessaging/utils/ThreadUtil.m index a961bae2a..a25363a29 100644 --- a/SignalMessaging/utils/ThreadUtil.m +++ b/SignalMessaging/utils/ThreadUtil.m @@ -632,7 +632,7 @@ NS_ASSUME_NONNULL_BEGIN } @try { - NSData *_Nullable newIdentityKey = [safetyNumberChange try_newIdentityKey]; + NSData *_Nullable newIdentityKey = [safetyNumberChange throws_newIdentityKey]; if (newIdentityKey == nil) { OWSFailDebug(@"Safety number change was missing it's new identity key."); continue; diff --git a/SignalServiceKit/src/Contacts/ContactDiscoveryService.m b/SignalServiceKit/src/Contacts/ContactDiscoveryService.m index b20b678a1..757fb1dd1 100644 --- a/SignalServiceKit/src/Contacts/ContactDiscoveryService.m +++ b/SignalServiceKit/src/Contacts/ContactDiscoveryService.m @@ -83,9 +83,9 @@ NSErrorDomain const ContactDiscoveryServiceErrorDomain = @"SignalServiceKit.Cont NSData *ephemeralToStatic; @try { ephemeralToEphemeral = - [Curve25519 try_generateSharedSecretFromPublicKey:self.serverEphemeralPublic andKeyPair:self.keyPair]; + [Curve25519 throws_generateSharedSecretFromPublicKey:self.serverEphemeralPublic andKeyPair:self.keyPair]; ephemeralToStatic = - [Curve25519 try_generateSharedSecretFromPublicKey:self.serverStaticPublic andKeyPair:self.keyPair]; + [Curve25519 throws_generateSharedSecretFromPublicKey:self.serverStaticPublic andKeyPair:self.keyPair]; } @catch (NSException *exception) { OWSFailDebug(@"could not generate shared secrets: %@", exception); return NO; @@ -101,7 +101,7 @@ NSErrorDomain const ContactDiscoveryServiceErrorDomain = @"SignalServiceKit.Cont NSData *_Nullable derivedMaterial; @try { derivedMaterial = - [HKDFKit try_deriveKey:masterSecret info:nil salt:publicKeys outputSize:(int)kAES256_KeyByteLength * 2]; + [HKDFKit throws_deriveKey:masterSecret info:nil salt:publicKeys outputSize:(int)kAES256_KeyByteLength * 2]; } @catch (NSException *exception) { OWSFailDebug(@"could not derive service key: %@", exception); return NO; diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 975a5bac2..4d046f132 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -249,7 +249,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa if ([interaction isKindOfClass:[TSInvalidIdentityKeyReceivingErrorMessage class]]) { TSInvalidIdentityKeyReceivingErrorMessage *error = (TSInvalidIdentityKeyReceivingErrorMessage *)interaction; @try { - if ([[error try_newIdentityKey] isEqualToData:key]) { + if ([[error throws_newIdentityKey] isEqualToData:key]) { [errorMessages addObject:(TSInvalidIdentityKeyReceivingErrorMessage *)interaction]; } } @catch (NSException *exception) { diff --git a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m index 451f84714..aac5b6499 100644 --- a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m +++ b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSData *)encrypt:(NSData *)dataToEncrypt { @try { - return [self try_encryptWithData:dataToEncrypt]; + return [self throws_encryptWithData:dataToEncrypt]; } @catch (NSException *exception) { OWSFailDebug(@"exception: %@ of type: %@ with reason: %@, user info: %@.", exception.description, @@ -65,14 +65,14 @@ NS_ASSUME_NONNULL_BEGIN } } -- (nullable NSData *)try_encryptWithData:(NSData *)dataToEncrypt +- (nullable NSData *)throws_encryptWithData:(NSData *)dataToEncrypt { NSData *sharedSecret = - [Curve25519 try_generateSharedSecretFromPublicKey:self.theirPublicKey andKeyPair:self.ourKeyPair]; + [Curve25519 throws_generateSharedSecretFromPublicKey:self.theirPublicKey andKeyPair:self.ourKeyPair]; NSData *infoData = [@"TextSecure Provisioning Message" dataUsingEncoding:NSASCIIStringEncoding]; NSData *nullSalt = [[NSMutableData dataWithLength:32] copy]; - NSData *derivedSecret = [HKDFKit try_deriveKey:sharedSecret info:infoData salt:nullSalt outputSize:64]; + NSData *derivedSecret = [HKDFKit throws_deriveKey:sharedSecret info:infoData salt:nullSalt outputSize:64]; NSData *cipherKey = [derivedSecret subdataWithRange:NSMakeRange(0, 32)]; NSData *macKey = [derivedSecret subdataWithRange:NSMakeRange(32, 32)]; if (cipherKey.length != 32) { diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.h b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.h index e81acb66d..2f4f5ff08 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.h +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.h @@ -10,8 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface TSInvalidIdentityKeyErrorMessage : TSErrorMessage -- (void)try_acceptNewIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); -- (nullable NSData *)try_newIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (void)throws_acceptNewIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (nullable NSData *)throws_newIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (NSString *)theirSignalId; @end diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.m b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.m index 301cfe900..239461875 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.m +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyErrorMessage.m @@ -8,12 +8,12 @@ NS_ASSUME_NONNULL_BEGIN @implementation TSInvalidIdentityKeyErrorMessage -- (void)try_acceptNewIdentityKey +- (void)throws_acceptNewIdentityKey { OWSAbstractMethod(); } -- (nullable NSData *)try_newIdentityKey +- (nullable NSData *)throws_newIdentityKey { OWSAbstractMethod(); return nil; diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m index ccc55a8bd..7fa210fa9 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeyReceivingErrorMessage.m @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN return _envelope; } -- (void)try_acceptNewIdentityKey +- (void)throws_acceptNewIdentityKey { OWSAssertIsOnMainThread(); @@ -90,7 +90,7 @@ NS_ASSUME_NONNULL_BEGIN return; } - NSData *_Nullable newKey = [self try_newIdentityKey]; + NSData *_Nullable newKey = [self throws_newIdentityKey]; if (!newKey) { OWSFailDebug(@"Couldn't extract identity key to accept"); return; @@ -112,7 +112,7 @@ NS_ASSUME_NONNULL_BEGIN } } -- (nullable NSData *)try_newIdentityKey +- (nullable NSData *)throws_newIdentityKey { if (!self.envelope) { OWSLogError(@"Error message had no envelope data to extract key from"); @@ -130,8 +130,8 @@ NS_ASSUME_NONNULL_BEGIN return nil; } - PreKeyWhisperMessage *message = [[PreKeyWhisperMessage alloc] init_try_withData:pkwmData]; - return [message.identityKey try_removeKeyType]; + PreKeyWhisperMessage *message = [[PreKeyWhisperMessage alloc] init_throws_withData:pkwmData]; + return [message.identityKey throws_removeKeyType]; } - (NSString *)theirSignalId diff --git a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m index 6e955bb90..3b5a47b2d 100644 --- a/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m +++ b/SignalServiceKit/src/Messages/InvalidKeyMessages/TSInvalidIdentityKeySendingErrorMessage.m @@ -45,13 +45,13 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey"; return self; } -- (void)try_acceptNewIdentityKey +- (void)throws_acceptNewIdentityKey { // Shouldn't really get here, since we're no longer creating blocking SN changes. // But there may still be some old unaccepted SN errors in the wild that need to be accepted. OWSFailDebug(@"accepting new identity key is deprecated."); - NSData *_Nullable newIdentityKey = [self try_newIdentityKey]; + NSData *_Nullable newIdentityKey = [self throws_newIdentityKey]; if (!newIdentityKey) { OWSFailDebug(@"newIdentityKey is unexpectedly nil. Bad Prekey bundle?: %@", self.preKeyBundle); return; @@ -60,9 +60,9 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey"; [[OWSIdentityManager sharedManager] saveRemoteIdentity:newIdentityKey recipientId:self.recipientId]; } -- (nullable NSData *)try_newIdentityKey +- (nullable NSData *)throws_newIdentityKey { - return [self.preKeyBundle.identityKey try_removeKeyType]; + return [self.preKeyBundle.identityKey throws_removeKeyType]; } - (NSString *)theirSignalId diff --git a/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m b/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m index 697040c99..49f05fc88 100644 --- a/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m +++ b/SignalServiceKit/src/Messages/OWSBatchMessageProcessor.m @@ -403,9 +403,9 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo if (!envelope) { reportFailure(transaction); } else { - [self.messageManager try_processEnvelope:envelope - plaintextData:job.plaintextData - transaction:transaction]; + [self.messageManager throws_processEnvelope:envelope + plaintextData:job.plaintextData + transaction:transaction]; } } @catch (NSException *exception) { OWSFailDebug(@"Received an invalid envelope: %@", exception.debugDescription); diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index 7f1c5c060..2d487487d 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -60,8 +60,8 @@ extern const NSUInteger kStoredIdentityKeyLength; - (nullable OWSRecipientIdentity *)untrustedIdentityForSendingToRecipientId:(NSString *)recipientId; // This method can be called from any thread. -- (void)try_processIncomingSyncMessage:(SSKProtoVerified *)verified - transaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)throws_processIncomingSyncMessage:(SSKProtoVerified *)verified + transaction:(YapDatabaseReadWriteTransaction *)transaction; - (BOOL)saveRemoteIdentity:(NSData *)identityKey recipientId:(NSString *)recipientId; diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index 25ab45230..ece948c88 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -678,8 +678,8 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa [transaction removeObjectForKey:recipientId inCollection:OWSIdentityManager_QueuedVerificationStateSyncMessages]; } -- (void)try_processIncomingSyncMessage:(SSKProtoVerified *)verified - transaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)throws_processIncomingSyncMessage:(SSKProtoVerified *)verified + transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssertDebug(verified); OWSAssertDebug(transaction); @@ -696,7 +696,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa rawIdentityKey); return; } - NSData *identityKey = [rawIdentityKey try_removeKeyType]; + NSData *identityKey = [rawIdentityKey throws_removeKeyType]; switch (verified.state) { case SSKProtoVerifiedStateDefault: diff --git a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m index d24721100..04d203a6c 100644 --- a/SignalServiceKit/src/Messages/OWSMessageDecrypter.m +++ b/SignalServiceKit/src/Messages/OWSMessageDecrypter.m @@ -212,7 +212,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes switch (envelope.type) { case SSKProtoEnvelopeTypeCiphertext: { - [self try_decryptSecureMessage:envelope + [self throws_decryptSecureMessage:envelope envelopeData:envelopeData successBlock:^(OWSMessageDecryptResult *result, YapDatabaseReadWriteTransaction *transaction) { OWSLogDebug(@"decrypted secure message."); @@ -229,7 +229,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes return; } case SSKProtoEnvelopeTypePrekeyBundle: { - [self try_decryptPreKeyBundle:envelope + [self throws_decryptPreKeyBundle:envelope envelopeData:envelopeData successBlock:^(OWSMessageDecryptResult *result, YapDatabaseReadWriteTransaction *transaction) { OWSLogDebug(@"decrypted pre-key whisper message"); @@ -298,10 +298,10 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes failureBlock(); } -- (void)try_decryptSecureMessage:(SSKProtoEnvelope *)envelope - envelopeData:(NSData *)envelopeData - successBlock:(DecryptSuccessBlock)successBlock - failureBlock:(void (^)(NSError *_Nullable error))failureBlock +- (void)throws_decryptSecureMessage:(SSKProtoEnvelope *)envelope + envelopeData:(NSData *)envelopeData + successBlock:(DecryptSuccessBlock)successBlock + failureBlock:(void (^)(NSError *_Nullable error))failureBlock { OWSAssertDebug(envelope); OWSAssertDebug(envelopeData); @@ -312,16 +312,16 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes envelopeData:envelopeData cipherTypeName:@"Secure Message" cipherMessageBlock:^(NSData *encryptedData) { - return [[WhisperMessage alloc] init_try_withData:encryptedData]; + return [[WhisperMessage alloc] init_throws_withData:encryptedData]; } successBlock:successBlock failureBlock:failureBlock]; } -- (void)try_decryptPreKeyBundle:(SSKProtoEnvelope *)envelope - envelopeData:(NSData *)envelopeData - successBlock:(DecryptSuccessBlock)successBlock - failureBlock:(void (^)(NSError *_Nullable error))failureBlock +- (void)throws_decryptPreKeyBundle:(SSKProtoEnvelope *)envelope + envelopeData:(NSData *)envelopeData + successBlock:(DecryptSuccessBlock)successBlock + failureBlock:(void (^)(NSError *_Nullable error))failureBlock { OWSAssertDebug(envelope); OWSAssertDebug(envelopeData); @@ -335,7 +335,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes envelopeData:envelopeData cipherTypeName:@"PreKey Bundle" cipherMessageBlock:^(NSData *encryptedData) { - return [[PreKeyWhisperMessage alloc] init_try_withData:encryptedData]; + return [[PreKeyWhisperMessage alloc] init_throws_withData:encryptedData]; } successBlock:successBlock failureBlock:failureBlock]; @@ -379,7 +379,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes // plaintextData may be nil for some envelope types. NSData *_Nullable plaintextData = - [[cipher try_decrypt:cipherMessage protocolContext:transaction] removePadding]; + [[cipher throws_decrypt:cipherMessage protocolContext:transaction] removePadding]; OWSMessageDecryptResult *result = [OWSMessageDecryptResult resultWithEnvelopeData:envelopeData plaintextData:plaintextData source:envelope.source diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.h b/SignalServiceKit/src/Messages/OWSMessageManager.h index fc8e2a43a..fb274d060 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.h +++ b/SignalServiceKit/src/Messages/OWSMessageManager.h @@ -19,9 +19,9 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER; // processEnvelope: can be called from any thread. -- (void)try_processEnvelope:(SSKProtoEnvelope *)envelope - plaintextData:(NSData *_Nullable)plaintextData - transaction:(YapDatabaseReadWriteTransaction *)transaction; +- (void)throws_processEnvelope:(SSKProtoEnvelope *)envelope + plaintextData:(NSData *_Nullable)plaintextData + transaction:(YapDatabaseReadWriteTransaction *)transaction; // This should be invoked by the main app when the app is ready. - (void)startObserving; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index ae3583e74..06a2a5213 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -212,9 +212,9 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - message handling -- (void)try_processEnvelope:(SSKProtoEnvelope *)envelope - plaintextData:(NSData *_Nullable)plaintextData - transaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)throws_processEnvelope:(SSKProtoEnvelope *)envelope + plaintextData:(NSData *_Nullable)plaintextData + transaction:(YapDatabaseReadWriteTransaction *)transaction { if (!envelope) { OWSFailDebug(@"Missing envelope."); @@ -256,7 +256,7 @@ NS_ASSUME_NONNULL_BEGIN OWSFailDebug(@"missing decrypted data for envelope: %@", [self descriptionForEnvelope:envelope]); return; } - [self try_handleEnvelope:envelope plaintextData:plaintextData transaction:transaction]; + [self throws_handleEnvelope:envelope plaintextData:plaintextData transaction:transaction]; break; case SSKProtoEnvelopeTypeReceipt: OWSAssertDebug(!plaintextData); @@ -345,9 +345,9 @@ NS_ASSUME_NONNULL_BEGIN } } -- (void)try_handleEnvelope:(SSKProtoEnvelope *)envelope - plaintextData:(NSData *)plaintextData - transaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)throws_handleEnvelope:(SSKProtoEnvelope *)envelope + plaintextData:(NSData *)plaintextData + transaction:(YapDatabaseReadWriteTransaction *)transaction { if (!envelope) { OWSFailDebug(@"Missing envelope."); @@ -395,7 +395,9 @@ NS_ASSUME_NONNULL_BEGIN OWSLogInfo(@"handling content: ", [self descriptionForContent:contentProto]); if (contentProto.syncMessage) { - [self try_handleIncomingEnvelope:envelope withSyncMessage:contentProto.syncMessage transaction:transaction]; + [self throws_handleIncomingEnvelope:envelope + withSyncMessage:contentProto.syncMessage + transaction:transaction]; [[OWSDeviceManager sharedManager] setHasReceivedSyncMessage]; } else if (contentProto.dataMessage) { @@ -745,9 +747,9 @@ NS_ASSUME_NONNULL_BEGIN }]; } -- (void)try_handleIncomingEnvelope:(SSKProtoEnvelope *)envelope - withSyncMessage:(SSKProtoSyncMessage *)syncMessage - transaction:(YapDatabaseReadWriteTransaction *)transaction +- (void)throws_handleIncomingEnvelope:(SSKProtoEnvelope *)envelope + withSyncMessage:(SSKProtoSyncMessage *)syncMessage + transaction:(YapDatabaseReadWriteTransaction *)transaction { if (!envelope) { OWSFailDebug(@"Missing envelope."); @@ -862,7 +864,7 @@ NS_ASSUME_NONNULL_BEGIN transaction:transaction]; } else if (syncMessage.verified) { OWSLogInfo(@"Received verification state for %@", syncMessage.verified.destination); - [self.identityManager try_processIncomingSyncMessage:syncMessage.verified transaction:transaction]; + [self.identityManager throws_processIncomingSyncMessage:syncMessage.verified transaction:transaction]; } else { OWSLogWarn(@"Ignoring unsupported sync message."); } diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index a56d1361b..31581c74f 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -839,7 +839,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; NSArray *deviceMessages; @try { - deviceMessages = [self try_deviceMessagesForMessageSendUnsafe:messageSend]; + deviceMessages = [self throws_deviceMessagesForMessageSendUnsafe:messageSend]; } @catch (NSException *exception) { if ([exception.name isEqualToString:UntrustedIdentityKeyException]) { // This *can* happen under normal usage, but it should happen relatively rarely. @@ -888,7 +888,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return nil; } - NSData *newIdentityKey = [newIdentityKeyWithVersion try_removeKeyType]; + NSData *newIdentityKey = [newIdentityKeyWithVersion throws_removeKeyType]; [self.identityManager saveRemoteIdentity:newIdentityKey recipientId:recipient.recipientId]; return nil; @@ -1407,7 +1407,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; [self sendMessageToRecipient:messageSend]; } -- (NSArray *)try_deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend +- (NSArray *)throws_deviceMessagesForMessageSendUnsafe:(OWSMessageSend *)messageSend { OWSAssertDebug(messageSend.message); OWSAssertDebug(messageSend.recipient); @@ -1443,17 +1443,17 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; @try { // This may involve blocking network requests, so we do it _before_ // we open a transaction. - [self try_ensureRecipientHasSessionForMessageSend:messageSend deviceId:deviceId]; + [self throws_ensureRecipientHasSessionForMessageSend:messageSend deviceId:deviceId]; __block NSDictionary *messageDict; __block NSException *encryptionException; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { @try { - messageDict = [self try_encryptedMessageForMessageSend:messageSend - deviceId:deviceId - plainText:plainText - transaction:transaction]; + messageDict = [self throws_encryptedMessageForMessageSend:messageSend + deviceId:deviceId + plainText:plainText + transaction:transaction]; } @catch (NSException *exception) { encryptionException = exception; } @@ -1485,7 +1485,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; return [messagesArray copy]; } -- (void)try_ensureRecipientHasSessionForMessageSend:(OWSMessageSend *)messageSend deviceId:(NSNumber *)deviceId +- (void)throws_ensureRecipientHasSessionForMessageSend:(OWSMessageSend *)messageSend deviceId:(NSNumber *)deviceId { OWSAssertDebug(messageSend); OWSAssertDebug(deviceId); @@ -1544,7 +1544,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; deviceId:[deviceId intValue]]; [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { @try { - [builder try_processPrekeyBundle:bundle protocolContext:transaction]; + [builder throws_processPrekeyBundle:bundle protocolContext:transaction]; } @catch (NSException *caughtException) { exception = caughtException; } @@ -1610,10 +1610,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } // NOTE: This method uses exceptions for control flow. -- (NSDictionary *)try_encryptedMessageForMessageSend:(OWSMessageSend *)messageSend - deviceId:(NSNumber *)deviceId - plainText:(NSData *)plainText - transaction:(YapDatabaseReadWriteTransaction *)transaction +- (NSDictionary *)throws_encryptedMessageForMessageSend:(OWSMessageSend *)messageSend + deviceId:(NSNumber *)deviceId + plainText:(NSData *)plainText + transaction:(YapDatabaseReadWriteTransaction *)transaction { OWSAssertDebug(messageSend); OWSAssertDebug(deviceId); @@ -1667,7 +1667,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } else { // This may throw an exception. id encryptedMessage = - [cipher try_encryptMessage:[plainText paddedMessageBody] protocolContext:transaction]; + [cipher throws_encryptMessage:[plainText paddedMessageBody] protocolContext:transaction]; serializedMessage = encryptedMessage.serialized; messageType = [self messageTypeForCipherMessage:encryptedMessage]; } @@ -1679,7 +1679,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; device:[deviceId intValue] content:serializedMessage isSilent:isSilent - registrationId:[cipher try_remoteRegistrationId:transaction]]; + registrationId:[cipher throws_remoteRegistrationId:transaction]]; NSError *error; NSDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:messageParams error:&error]; diff --git a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m index 41e83f7da..5035b4383 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+PreKeyStore.m @@ -49,7 +49,7 @@ } } -- (PreKeyRecord *)try_loadPreKey:(int)preKeyId +- (PreKeyRecord *)throws_loadPreKey:(int)preKeyId { PreKeyRecord *preKeyRecord = [self.dbReadConnection preKeyRecordForKey:[self keyFromInt:preKeyId] inCollection:OWSPrimaryStoragePreKeyStoreCollection]; diff --git a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SignedPreKeyStore.m b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SignedPreKeyStore.m index 2e7394cd1..3c2f9318c 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SignedPreKeyStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/OWSPrimaryStorage+SignedPreKeyStore.m @@ -34,17 +34,17 @@ NSString *const OWSPrimaryStorageKeyPrekeyCurrentSignedPrekeyId = @"currentSigne return [[SignedPreKeyRecord alloc] initWithId:preKeyId keyPair:keyPair - signature:[Ed25519 try_sign:keyPair.publicKey.prependKeyType withKeyPair:identityKeyPair] + signature:[Ed25519 throws_sign:keyPair.publicKey.prependKeyType withKeyPair:identityKeyPair] generatedAt:[NSDate date]]; } @catch (NSException *exception) { - // try_sign only throws when the data to sign is empty or `keyPair`. + // throws_sign only throws when the data to sign is empty or `keyPair`. // Neither of which should happen. OWSFail(@"exception: %@", exception); return nil; } } -- (SignedPreKeyRecord *)try_loadSignedPrekey:(int)signedPreKeyId +- (SignedPreKeyRecord *)throws_loadSignedPrekey:(int)signedPreKeyId { SignedPreKeyRecord *preKeyRecord = [self.dbReadConnection signedPreKeyRecordForKey:[self keyFromInt:signedPreKeyId] diff --git a/SignalServiceKit/tests/Storage/TSStoragePreKeyStoreTests.m b/SignalServiceKit/tests/Storage/TSStoragePreKeyStoreTests.m index 906daaa2a..d87c0f475 100644 --- a/SignalServiceKit/tests/Storage/TSStoragePreKeyStoreTests.m +++ b/SignalServiceKit/tests/Storage/TSStoragePreKeyStoreTests.m @@ -35,10 +35,10 @@ PreKeyRecord *lastPreKeyRecord = [generatedKeys lastObject]; PreKeyRecord *firstPreKeyRecord = [generatedKeys firstObject]; - XCTAssert([[[OWSPrimaryStorage sharedManager] try_loadPreKey:lastPreKeyRecord.Id].keyPair.publicKey + XCTAssert([[[OWSPrimaryStorage sharedManager] throws_loadPreKey:lastPreKeyRecord.Id].keyPair.publicKey isEqualToData:lastPreKeyRecord.keyPair.publicKey]); - XCTAssert([[[OWSPrimaryStorage sharedManager] try_loadPreKey:firstPreKeyRecord.Id].keyPair.publicKey + XCTAssert([[[OWSPrimaryStorage sharedManager] throws_loadPreKey:firstPreKeyRecord.Id].keyPair.publicKey isEqualToData:firstPreKeyRecord.keyPair.publicKey]); } @@ -56,8 +56,8 @@ [[OWSPrimaryStorage sharedManager] removePreKey:lastPreKeyRecord.Id]; - XCTAssertThrows([[OWSPrimaryStorage sharedManager] try_loadPreKey:lastPreKeyRecord.Id]); - XCTAssertNoThrow([[OWSPrimaryStorage sharedManager] try_loadPreKey:firstPreKeyRecord.Id]); + XCTAssertThrows([[OWSPrimaryStorage sharedManager] throws_loadPreKey:lastPreKeyRecord.Id]); + XCTAssertNoThrow([[OWSPrimaryStorage sharedManager] throws_loadPreKey:firstPreKeyRecord.Id]); } @end