diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 7d8f43be8..a506352c6 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -77,11 +77,11 @@ attrs = @{NSFileProtectionKey: NSFileProtectionComplete}; [[NSFileManager defaultManager] setAttributes:attrs ofItemAtPath:logPath error:&error]; - for (NSUInteger i = 0; i < [logsFiles count]; i++) { + for (NSUInteger i = 0; i < logsFiles.count; i++) { [pathsToExclude addObject:[logPath stringByAppendingString:logsFiles[i]]]; } - for (NSUInteger i = 0; i < [pathsToExclude count]; i++) { + for (NSUInteger i = 0; i < pathsToExclude.count; i++) { [[NSURL fileURLWithPath:pathsToExclude[i]] setResourceValue: @YES forKey: NSURLIsExcludedFromBackupKey error: &error]; } diff --git a/Signal/src/NotificationTracker.m b/Signal/src/NotificationTracker.m index 65de83dd7..e1a52402a 100644 --- a/Signal/src/NotificationTracker.m +++ b/Signal/src/NotificationTracker.m @@ -27,7 +27,7 @@ NSData* data = [self getIdForNotification:notification]; [_witnessedNotifications insertObject:data atIndex:0]; - while(MAX_NOTIFICATIONS_TO_TRACK < [_witnessedNotifications count]){ + while(MAX_NOTIFICATIONS_TO_TRACK < _witnessedNotifications.count){ [_witnessedNotifications removeLastObject]; } } diff --git a/Signal/src/async/AsyncUtil.m b/Signal/src/async/AsyncUtil.m index 2efe406b7..c9973f891 100644 --- a/Signal/src/async/AsyncUtil.m +++ b/Signal/src/async/AsyncUtil.m @@ -15,7 +15,7 @@ untilCancelled:(id)untilCancelledToken { require(cancellableOperationStarters != nil); - if ([cancellableOperationStarters count] == 0) return [Future failed:@[]]; + if (cancellableOperationStarters.count == 0) return [Future failed:@[]]; NSArray* racingOperations = [AsyncUtilHelperRacingOperation racingOperationsFromCancellableOperationStarters:cancellableOperationStarters untilCancelled:untilCancelledToken]; diff --git a/Signal/src/async/AsyncUtilHelperRacingOperation.m b/Signal/src/async/AsyncUtilHelperRacingOperation.m index daecc541d..8670daf95 100644 --- a/Signal/src/async/AsyncUtilHelperRacingOperation.m +++ b/Signal/src/async/AsyncUtilHelperRacingOperation.m @@ -39,12 +39,12 @@ FutureSource* futureWinner = [FutureSource new]; - NSUInteger totalCount = [racingOperations count]; + NSUInteger totalCount = racingOperations.count; NSMutableArray* failures = [NSMutableArray array]; void(^failIfAllFailed)(id) = ^(id failure) { @synchronized(failures) { [failures addObject:failure]; - if ([failures count] < totalCount) return; + if (failures.count < totalCount) return; } [futureWinner trySetFailure:failures]; diff --git a/Signal/src/audio/incall_audio/AudioPacker.m b/Signal/src/audio/incall_audio/AudioPacker.m index cd45d0734..e1439e5ac 100644 --- a/Signal/src/audio/incall_audio/AudioPacker.m +++ b/Signal/src/audio/incall_audio/AudioPacker.m @@ -26,7 +26,7 @@ } -(EncodedAudioPacket*) tryGetFinishedAudioPacket{ - if ([framesToSend count] < AUDIO_FRAMES_PER_PACKET) return nil; + if (framesToSend.count < AUDIO_FRAMES_PER_PACKET) return nil; uint16_t sequenceNumber = nextSequenceNumber++; NSData* payload = [framesToSend concatDatas]; @@ -55,9 +55,9 @@ require(packet != nil); NSData* audioData = [packet audioData]; - requireState([audioData length] % AUDIO_FRAMES_PER_PACKET == 0); + requireState(audioData.length % AUDIO_FRAMES_PER_PACKET == 0); - NSUInteger frameSize = [audioData length] / AUDIO_FRAMES_PER_PACKET; + NSUInteger frameSize = audioData.length / AUDIO_FRAMES_PER_PACKET; for (NSUInteger i = 0; i < AUDIO_FRAMES_PER_PACKET; i++) { NSData* frameData = [audioData subdataWithRange:NSMakeRange(frameSize*i, frameSize)]; [audioFrameToReceiveQueue enqueue:[EncodedAudioFrame encodedAudioFrameWithData:frameData]]; diff --git a/Signal/src/audio/incall_audio/CallAudioManager.m b/Signal/src/audio/incall_audio/CallAudioManager.m index 12bf0e70e..e0b0b4208 100644 --- a/Signal/src/audio/incall_audio/CallAudioManager.m +++ b/Signal/src/audio/incall_audio/CallAudioManager.m @@ -52,7 +52,7 @@ NSData* decodedAudioData = [audioProcessor tryDecodeOrInferFrame]; if (decodedAudioData == nil) break; [audioInterface populatePlaybackQueueWithData:decodedAudioData]; - bytesInPlaybackBuffer += [decodedAudioData length]; + bytesInPlaybackBuffer += decodedAudioData.length; } } diff --git a/Signal/src/audio/incall_audio/RemoteIOAudio.m b/Signal/src/audio/incall_audio/RemoteIOAudio.m index ee2a9b2be..6b745dad0 100644 --- a/Signal/src/audio/incall_audio/RemoteIOAudio.m +++ b/Signal/src/audio/incall_audio/RemoteIOAudio.m @@ -36,7 +36,7 @@ static bool doesActiveInstanceExist; newRemoteIoInterface->playbackBufferSizeLogger = [[Environment logging] getValueLoggerForValue:@"|playback queue|" from:newRemoteIoInterface]; newRemoteIoInterface->recordingQueueSizeLogger = [[Environment logging] getValueLoggerForValue:@"|recording queue|" from:newRemoteIoInterface]; - while ([newRemoteIoInterface->unusedBuffers count] < INITIAL_NUMBER_OF_BUFFERS) { + while (newRemoteIoInterface->unusedBuffers.count < INITIAL_NUMBER_OF_BUFFERS) { [newRemoteIoInterface addUnusedBuffer]; } [newRemoteIoInterface setupAudio]; @@ -236,7 +236,7 @@ static OSStatus recordingCallback(void *inRefCon, -(void)populatePlaybackQueueWithData:(NSData*)data { require(data != nil); - if ([data length] == 0) return; + if (data.length == 0) return; @synchronized(self){ [playbackQueue enqueueData:data]; } @@ -258,7 +258,7 @@ static OSStatus playbackCallback(void *inRefCon, [instance->starveLogger markOccurrence:@(starveAmount)]; } else { NSData* audioToCopyVolatile = [[instance playbackQueue] dequeuePotentialyVolatileDataWithLength:requestedByteCount]; - memcpy(ioData->mBuffers[0].mData, [audioToCopyVolatile bytes], [audioToCopyVolatile length]); + memcpy(ioData->mBuffers[0].mData, [audioToCopyVolatile bytes], audioToCopyVolatile.length); } } diff --git a/Signal/src/audio/incall_audio/SpeexCodec.m b/Signal/src/audio/incall_audio/SpeexCodec.m index 6dddd80b4..9d7ee83e3 100644 --- a/Signal/src/audio/incall_audio/SpeexCodec.m +++ b/Signal/src/audio/incall_audio/SpeexCodec.m @@ -37,12 +37,12 @@ -(void) determineDecodedLength { NSData* encoded = [self encode:[NSMutableData dataWithLength:[self decodedFrameSizeInBytes]]]; - cachedEncodedLength = [encoded length]; + cachedEncodedLength = encoded.length; } -(NSData*)encode:(NSData*)rawData { require(rawData != nil); - require([rawData length] == FRAME_SIZE_IN_SAMPLES*DECODED_SAMPLE_SIZE_IN_BYTES); + require(rawData.length == FRAME_SIZE_IN_SAMPLES*DECODED_SAMPLE_SIZE_IN_BYTES); speex_bits_reset(&encodingBits); speex_encode_int(encodingState, (spx_int16_t*)[rawData bytes], &encodingBits); @@ -55,7 +55,7 @@ } -(NSData*)decode:(NSData*)potentiallyMissingEncodedData { - NSUInteger encodedDataLength = [potentiallyMissingEncodedData length]; + NSUInteger encodedDataLength = potentiallyMissingEncodedData.length; if (potentiallyMissingEncodedData == nil) { encodedDataLength = [self decodedFrameSizeInBytes]; // size for infering audio data } @@ -70,7 +70,7 @@ -(NSUInteger) encodedDataLengthFromData:(NSData*)potentiallyMissingEncodedData{ if (potentiallyMissingEncodedData != nil) { - return [potentiallyMissingEncodedData length]; + return potentiallyMissingEncodedData.length; } return [self decodedFrameSizeInBytes]; } diff --git a/Signal/src/audio/incall_audio/processing/AudioStretcher.m b/Signal/src/audio/incall_audio/processing/AudioStretcher.m index 75b21d0a0..f2a78d7ea 100644 --- a/Signal/src/audio/incall_audio/processing/AudioStretcher.m +++ b/Signal/src/audio/incall_audio/processing/AudioStretcher.m @@ -22,7 +22,7 @@ checkOperationDescribe(time_scale_rate(&timeScaleState, (float)stretchFactor) == 0, @"Changing time scaling"); - int inputSampleCount = (unsigned int)[audioData length]/sizeof(int16_t); + int inputSampleCount = (unsigned int)audioData.length/sizeof(int16_t); int maxOutputSampleCount = [self getSafeMaxOutputSampleCountFromInputSampleCount:inputSampleCount]; int16_t* input = (int16_t*)[audioData bytes]; diff --git a/Signal/src/audio/incall_audio/processing/JitterQueue.m b/Signal/src/audio/incall_audio/processing/JitterQueue.m index 581a4fa91..535e62572 100644 --- a/Signal/src/audio/incall_audio/processing/JitterQueue.m +++ b/Signal/src/audio/incall_audio/processing/JitterQueue.m @@ -23,7 +23,7 @@ } -(NSUInteger) count { - return [resultPriorityQueue count]; + return resultPriorityQueue.count; } -(bool) tryEnqueue:(EncodedAudioPacket*)audioPacket { @@ -96,7 +96,7 @@ }]; } -(void) discardExcess { - if ([resultPriorityQueue count] <= MAXIMUM_JITTER_QUEUE_SIZE_BEFORE_DISCARDING) return; + if (resultPriorityQueue.count <= MAXIMUM_JITTER_QUEUE_SIZE_BEFORE_DISCARDING) return; EncodedAudioPacket* discarded = [resultPriorityQueue dequeue]; uint16_t discardedSequenceNumber = [discarded sequenceNumber]; @@ -127,7 +127,7 @@ [idsInJitterQueue removeObject:@([result sequenceNumber])]; for (id e in watchers) { - [e notifyDequeue:[result sequenceNumber] withRemainingEnqueuedItemCount:[idsInJitterQueue count]]; + [e notifyDequeue:[result sequenceNumber] withRemainingEnqueuedItemCount:idsInJitterQueue.count]; } return result; } @@ -141,7 +141,7 @@ return isOutOfSync; } -(bool) checkReactIfEmptyForDequeue { - bool isEmpty = [resultPriorityQueue count] == 0; + bool isEmpty = resultPriorityQueue.count == 0; if (isEmpty) { readHeadSpan += 1; for (id watcher in watchers) { diff --git a/Signal/src/contact/ContactsManager.m b/Signal/src/contact/ContactsManager.m index b6ea9a2ee..14289944f 100644 --- a/Signal/src/contact/ContactsManager.m +++ b/Signal/src/contact/ContactsManager.m @@ -190,7 +190,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) { NSString* phoneNumber = (__bridge_transfer NSString*) ABMultiValueCopyValueAtIndex(phoneNumbers, i); - if ([phoneNumber length]>0) { + if (phoneNumber.length>0) { result = YES; break; } @@ -208,7 +208,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in -(NSArray*)latestContactsWithSearchString:(NSString *)searchString { return [[latestContactsById allValues] filter:^int(Contact *contact) { - return [searchString length] == 0 || [ContactsManager name:[contact fullName] matchesQuery:searchString]; + return searchString.length == 0 || [ContactsManager name:[contact fullName] matchesQuery:searchString]; }]; } @@ -225,7 +225,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in NSString *companyName = (__bridge_transfer NSString*)ABRecordCopyValue(record, kABPersonOrganizationProperty); if (companyName) { firstName = companyName; - } else if ([phoneNumbers count]) { + } else if (phoneNumbers.count) { firstName = [phoneNumbers firstObject]; } } @@ -288,7 +288,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in NSMutableArray *numbers = [NSMutableArray array]; - for (NSUInteger i = 0; i < [phoneNumbers count]; i++) { + for (NSUInteger i = 0; i < phoneNumbers.count; i++) { NSString *phoneNumber = phoneNumbers[i]; [numbers addObject:phoneNumber]; } @@ -323,7 +323,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in require(contacts != nil); NSArray *matchingContacts = [contacts filter:^int(Contact *contact) { - return [optionalSearchString length] == 0 || [self name:[contact fullName] matchesQuery:optionalSearchString]; + return optionalSearchString.length == 0 || [self name:[contact fullName] matchesQuery:optionalSearchString]; }]; return [matchingContacts groupBy:^id(Contact *contact) { @@ -373,7 +373,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in NSArray *nameStrings = [nameString componentsSeparatedByCharactersInSet:whitespaceSet]; return [queryStrings all:^int(NSString* query) { - if ([query length] == 0) return YES; + if (query.length == 0) return YES; return [nameStrings any:^int(NSString* nameWord) { NSStringCompareOptions searchOpts = NSCaseInsensitiveSearch | NSAnchoredSearch; return [nameWord rangeOfString:query options:searchOpts].location != NSNotFound; @@ -387,7 +387,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in [[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""]; - if ([queryString length] == 0) return YES; + if (queryString.length == 0) return YES; NSStringCompareOptions searchOpts = NSCaseInsensitiveSearch | NSAnchoredSearch; return [searchString rangeOfString:queryString options:searchOpts].location != NSNotFound; } @@ -451,12 +451,12 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in NSArray *currentUsers = [self getWhisperUsersFromContactsArray:[latestContactsById allValues]]; NSArray *newUsers = [self getNewItemsFrom:currentUsers comparedTo:[latestWhisperUsersById allValues]]; - if([newUsers count] > 0){ + if(newUsers.count > 0){ [observableWhisperUsersController updateValue:currentUsers]; } NSArray *unacknowledgedUserIds = [self getUnacknowledgedUsersFrom:currentUsers]; - if([unacknowledgedUserIds count] > 0){ + if(unacknowledgedUserIds.count > 0){ NSArray *unacknowledgedUsers = [self contactsForContactIds: unacknowledgedUserIds]; if(!newUserNotificationsEnabled){ [self addContactsToKnownWhisperUsers:unacknowledgedUsers]; @@ -465,7 +465,7 @@ void onAddressBookChanged(ABAddressBookRef notifyAddressBook, CFDictionaryRef in [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_NEW_USERS_AVAILABLE object:self userInfo:payload]; } } - return [newUsers count]; + return newUsers.count; } -(NSArray*) getUnacknowledgedUsersFrom:(NSArray*) users { diff --git a/Signal/src/crypto/CryptoTools.m b/Signal/src/crypto/CryptoTools.m index 1a719f12f..9fa29c7cb 100644 --- a/Signal/src/crypto/CryptoTools.m +++ b/Signal/src/crypto/CryptoTools.m @@ -65,8 +65,8 @@ } -(bool)isEqualToData_TimingSafe:(NSData*)other { if (other == nil) return false; - NSUInteger n = [self length]; - if ([other length] != n) return false; + NSUInteger n = self.length; + if (other.length != n) return false; bool equal = true; for (NSUInteger i = 0; i < n; i++) equal &= [self uint8At:i] == [other uint8At:i]; diff --git a/Signal/src/crypto/EvpMessageDigest.m b/Signal/src/crypto/EvpMessageDigest.m index c24b483b0..1475e89ab 100644 --- a/Signal/src/crypto/EvpMessageDigest.m +++ b/Signal/src/crypto/EvpMessageDigest.m @@ -33,8 +33,8 @@ NSUInteger digestLength = [NumberUtil assertConvertIntToNSUInteger:EVP_MD_size(md)]; unsigned char* digest = HMAC(md, - [key bytes], [NumberUtil assertConvertNSUIntegerToInt:[key length]], - [data bytes], [data length], + [key bytes], [NumberUtil assertConvertNSUIntegerToInt:key.length], + [data bytes], data.length, NULL, NULL); return [NSData dataWithBytes:digest length:digestLength]; diff --git a/Signal/src/crypto/EvpSymetricUtil.m b/Signal/src/crypto/EvpSymetricUtil.m index c8b2dd459..006b2174b 100644 --- a/Signal/src/crypto/EvpSymetricUtil.m +++ b/Signal/src/crypto/EvpSymetricUtil.m @@ -9,7 +9,7 @@ +(NSData*) encryptMessage:(NSData *)message usingCipher:(const EVP_CIPHER*) cipher andKey:(NSData *)key andIv:(NSData *)iv { [self assertKey:key andIv:iv lengthsAgainstCipher:cipher]; - int messageLength = [NumberUtil assertConvertNSUIntegerToInt:[message length]]; + int messageLength = [NumberUtil assertConvertNSUIntegerToInt:message.length]; int cipherBlockSize = EVP_CIPHER_block_size(cipher); int cipherTextLength = 0; int paddingLength = 0; @@ -40,15 +40,15 @@ int cipherKeyLength = EVP_CIPHER_key_length(cipher); int cipherIvLength = EVP_CIPHER_iv_length(cipher); - require([key length] == [NumberUtil assertConvertIntToNSUInteger:cipherKeyLength]); - require([iv length] == [NumberUtil assertConvertIntToNSUInteger:cipherIvLength]); + require(key.length == [NumberUtil assertConvertIntToNSUInteger:cipherKeyLength]); + require(iv.length == [NumberUtil assertConvertIntToNSUInteger:cipherIvLength]); } +(NSData*) decryptMessage:(NSData *)cipherText usingCipher:(const EVP_CIPHER*) cipher andKey:(NSData *)key andIv:(NSData *)iv { [self assertKey:key andIv:iv lengthsAgainstCipher:cipher]; - int cipherTextLength = [NumberUtil assertConvertNSUIntegerToInt:[cipherText length]]; + int cipherTextLength = [NumberUtil assertConvertNSUIntegerToInt:cipherText.length]; int cipherBlockSize = EVP_CIPHER_block_size(cipher); int plainTextLength = 0; int paddingLength = 0; diff --git a/Signal/src/environment/DebugLogger.m b/Signal/src/environment/DebugLogger.m index 0fb34acf7..1547a0bee 100644 --- a/Signal/src/environment/DebugLogger.m +++ b/Signal/src/environment/DebugLogger.m @@ -50,7 +50,7 @@ MacrosSingletonImplemention NSString *logPath = [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/Logs/"]; NSArray *logsFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:logPath error:&error]; - for (NSUInteger i = 0; i < [logsFiles count]; i++) { + for (NSUInteger i = 0; i < logsFiles.count; i++) { [[NSFileManager defaultManager] removeItemAtPath:[logPath stringByAppendingString:logsFiles[i]] error:&error]; } diff --git a/Signal/src/environment/PreferencesUtil.m b/Signal/src/environment/PreferencesUtil.m index 0b8e82ccd..0653f6f27 100644 --- a/Signal/src/environment/PreferencesUtil.m +++ b/Signal/src/environment/PreferencesUtil.m @@ -32,7 +32,7 @@ NSUInteger hashCount = [[self tryGetValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_HASH_COUNT_KEY] unsignedIntegerValue]; NSData* data = [self tryGetValueForKey:PHONE_DIRECTORY_BLOOM_FILTER_DATA_KEY]; NSDate* expiration = [self tryGetValueForKey:PHONE_DIRECTORY_EXPIRATION]; - if (hashCount == 0 || [data length] == 0 || expiration == nil) return nil; + if (hashCount == 0 || data.length == 0 || expiration == nil) return nil; BloomFilter* bloomFilter = [BloomFilter bloomFilterWithHashCount:hashCount andData:data]; return [PhoneNumberDirectoryFilter phoneNumberDirectoryFilterWithBloomFilter:bloomFilter andExpirationDate:expiration]; diff --git a/Signal/src/environment/SGNKeychainUtil.m b/Signal/src/environment/SGNKeychainUtil.m index ab4d987eb..9faf6309e 100644 --- a/Signal/src/environment/SGNKeychainUtil.m +++ b/Signal/src/environment/SGNKeychainUtil.m @@ -67,8 +67,8 @@ +(Zid *)zid{ NSData *data = [self dataForKey:ZID_KEY]; - if ([data length] != ZID_LENGTH) { - DDLogError(@"ZID length is incorrect. Is %lu, should be %d", (unsigned long)[data length], ZID_LENGTH); + if (data.length != ZID_LENGTH) { + DDLogError(@"ZID length is incorrect. Is %lu, should be %d", (unsigned long)data.length, ZID_LENGTH); } Zid *zid = [Zid zidWithData:data]; return zid; @@ -90,8 +90,8 @@ +(NSString *)serverAuthPassword{ NSString *password = [self stringForKey:SAVED_PASSWORD_KEY]; NSData *data = [password decodedAsBase64Data]; - if ([data length] != SAVED_PASSWORD_LENGTH) { - DDLogError(@"The server password has incorrect length. Is %lu but should be %d", (unsigned long)[data length], SAVED_PASSWORD_LENGTH); + if (data.length != SAVED_PASSWORD_LENGTH) { + DDLogError(@"The server password has incorrect length. Is %lu but should be %d", (unsigned long)data.length, SAVED_PASSWORD_LENGTH); } return password; } @@ -109,8 +109,8 @@ +(NSData*)dataForKey:(NSString*)key andVerifyLength:(uint)length{ NSData *data = [self dataForKey:key]; - if ([data length] != length) { - DDLogError(@"Length of data not matching. Got %lu, expected %u", (unsigned long)[data length], length); + if (data.length != length) { + DDLogError(@"Length of data not matching. Got %lu, expected %u", (unsigned long)data.length, length); } return data; diff --git a/Signal/src/environment/VersionMigrations.m b/Signal/src/environment/VersionMigrations.m index db3bcfd25..66a3b1514 100644 --- a/Signal/src/environment/VersionMigrations.m +++ b/Signal/src/environment/VersionMigrations.m @@ -28,7 +28,7 @@ NSArray *entries = [dict allKeys]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - for (NSUInteger i = 0; i < [entries count]; i++) { + for (NSUInteger i = 0; i < entries.count; i++) { NSString *key = entries[i]; [defaults setObject:dict[key] forKey:key]; } diff --git a/Signal/src/network/IpEndPoint.m b/Signal/src/network/IpEndPoint.m index 571ab8863..b7d85f190 100644 --- a/Signal/src/network/IpEndPoint.m +++ b/Signal/src/network/IpEndPoint.m @@ -31,7 +31,7 @@ +(IpEndPoint*) ipEndPointFromSockaddrData:(NSData*)sockaddrData { require(sockaddrData != nil); - require([sockaddrData length] >= sizeof(struct sockaddr)); + require(sockaddrData.length >= sizeof(struct sockaddr)); struct sockaddr s; memcpy(&s, [sockaddrData bytes], sizeof(struct sockaddr)); @@ -44,7 +44,7 @@ } +(IpEndPoint*) ipv4EndPointFromSockaddrData:(NSData*)sockaddrData { require(sockaddrData != nil); - require([sockaddrData length] >= sizeof(struct sockaddr_in)); + require(sockaddrData.length >= sizeof(struct sockaddr_in)); struct sockaddr_in s; memcpy(&s, [sockaddrData bytes], sizeof(struct sockaddr_in)); @@ -53,7 +53,7 @@ } +(IpEndPoint*) ipv6EndPointFromSockaddrData:(NSData*)sockaddrData { require(sockaddrData != nil); - require([sockaddrData length] >= sizeof(struct sockaddr_in6)); + require(sockaddrData.length >= sizeof(struct sockaddr_in6)); struct sockaddr_in6 s; memcpy(&s, [sockaddrData bytes], sizeof(struct sockaddr_in6)); diff --git a/Signal/src/network/http/HttpManager.m b/Signal/src/network/http/HttpManager.m index ab94122f9..07e738485 100644 --- a/Signal/src/network/http/HttpManager.m +++ b/Signal/src/network/http/HttpManager.m @@ -120,7 +120,7 @@ HttpResponse* response = requestHandler([requestOrResponse request]); requireState(response != nil); [httpChannel send:[HttpRequestOrResponse httpRequestOrResponse:response]]; - } else if ([eventualResponseQueue count] == 0) { + } else if (eventualResponseQueue.count == 0) { errorHandler(@"Response when no requests queued", [requestOrResponse response], false); } else { FutureSource* ev = [eventualResponseQueue dequeue]; @@ -137,17 +137,17 @@ } -(void) clearQueue:(id)error { @synchronized (self) { - while ([eventualResponseQueue count] > 0) { + while (eventualResponseQueue.count > 0) { [[eventualResponseQueue dequeue] trySetFailure:error]; } } } -(void) terminateWhenDoneCurrentWork { @synchronized (self) { - if ([eventualResponseQueue count] == 0) { + if (eventualResponseQueue.count == 0) { [self terminate]; } else { - FutureSource* v = [eventualResponseQueue peekAt:[eventualResponseQueue count]-1]; + FutureSource* v = [eventualResponseQueue peekAt:eventualResponseQueue.count-1]; [v finallyDo:^(id _) { [self terminate]; }]; diff --git a/Signal/src/network/http/HttpRequest.m b/Signal/src/network/http/HttpRequest.m index f02342ee4..8efdd8321 100644 --- a/Signal/src/network/http/HttpRequest.m +++ b/Signal/src/network/http/HttpRequest.m @@ -19,7 +19,7 @@ require(location != nil); require(headers != nil); require((optionalBody == nil) == (headers[@"Content-Length"] == nil)); - require(optionalBody == nil || [[@([optionalBody length]) description] isEqualToString:headers[@"Content-Length"]]); + require(optionalBody == nil || [[@(optionalBody.length) description] isEqualToString:headers[@"Content-Length"]]); HttpRequest* s = [HttpRequest new]; s->_method = method; @@ -36,7 +36,7 @@ NSMutableDictionary* headers = [NSMutableDictionary dictionary]; if (optionalBody != nil) { - headers[@"Content-Length"] = [@([optionalBody length]) stringValue]; + headers[@"Content-Length"] = [@(optionalBody.length) stringValue]; } HttpRequest* s = [HttpRequest new]; @@ -58,7 +58,7 @@ NSMutableDictionary* headers = [NSMutableDictionary dictionary]; if (optionalBody != nil) { - headers[@"Content-Length"] = [@([optionalBody length]) stringValue]; + headers[@"Content-Length"] = [@(optionalBody.length) stringValue]; } headers[@"Authorization"] = [HttpRequest computeBasicAuthorizationTokenForLocalNumber:localNumber andPassword:password]; @@ -81,7 +81,7 @@ NSMutableDictionary* headers = [NSMutableDictionary dictionary]; if (optionalBody != nil) { - headers[@"Content-Length"] = [@([optionalBody length]) stringValue]; + headers[@"Content-Length"] = [@(optionalBody.length) stringValue]; } headers[@"Authorization"] = [HttpRequest computeOtpAuthorizationTokenForLocalNumber:localNumber andCounterValue:counter andPassword:password]; @@ -97,7 +97,7 @@ require(data != nil); NSUInteger requestSize; HttpRequestOrResponse* http = [HttpRequestOrResponse tryExtractFromPartialData:data usedLengthOut:&requestSize]; - checkOperation([http isRequest] && requestSize == [data length]); + checkOperation([http isRequest] && requestSize == data.length); return [http request]; } @@ -156,7 +156,7 @@ self.method, self.location, self.optionalBody == nil ? @"" - : [self.optionalBody length] == 0 ? @" [empty body]" + : self.optionalBody.length == 0 ? @" [empty body]" : @" [...body...]"]; } diff --git a/Signal/src/network/http/HttpRequestOrResponse.m b/Signal/src/network/http/HttpRequestOrResponse.m index bebefa274..9eb4d6e82 100644 --- a/Signal/src/network/http/HttpRequestOrResponse.m +++ b/Signal/src/network/http/HttpRequestOrResponse.m @@ -45,23 +45,23 @@ headerLength += 4; // account for \r\n\r\n NSArray* headerLines = [fullHeader componentsSeparatedByString:@"\r\n"]; - checkOperation([headerLines count] >= 1); + checkOperation(headerLines.count >= 1); // GET /index.html HTTP/1.1 // HTTP/1.1 200 OK NSString* requestOrResponseLine = headerLines[0]; NSArray* requestOrResponseLineParts = [requestOrResponseLine componentsSeparatedByString:@" "]; - checkOperation([requestOrResponseLineParts count] >= 3); + checkOperation(requestOrResponseLineParts.count >= 3); bool isResponse = [requestOrResponseLineParts[0] hasPrefix:@"HTTP/"]; // Host: www.example.com // Content-Length: 5 NSMutableDictionary* headers = [NSMutableDictionary dictionary]; - for (NSUInteger i = 1; i < [headerLines count]; i++) { + for (NSUInteger i = 1; i < headerLines.count; i++) { NSString* headerLine = headerLines[i]; NSArray* headerLineParts = [headerLine componentsSeparatedByString:@":"]; - checkOperation([headerLineParts count] >= 2); + checkOperation(headerLineParts.count >= 2); NSString* headerKey = [headerLineParts[0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; NSString* headerValue = [[headerLine substringFromIndex:[(NSString *)headerLineParts[0] length]+1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; headers[headerKey] = headerValue; @@ -73,7 +73,7 @@ bool hasContent = contentLengthParsed != nil; NSUInteger contentLength = [contentLengthParsed unsignedIntegerValue]; - if (headerLength + contentLength > [data length]) return nil; // need more data + if (headerLength + contentLength > data.length) return nil; // need more data NSData* optionalBodyData = hasContent ? [data subdataWithRange:NSMakeRange(headerLength, contentLength)] : nil; *usedLengthPtr = headerLength + contentLength; @@ -82,14 +82,14 @@ checkOperation(statusCodeParsed != nil); NSUInteger statusCode = [statusCodeParsed unsignedIntegerValue]; - NSString* statusText = [[requestOrResponseLineParts subarrayWithRange:NSMakeRange(2, [requestOrResponseLineParts count] - 2)] componentsJoinedByString:@" "]; + NSString* statusText = [[requestOrResponseLineParts subarrayWithRange:NSMakeRange(2, requestOrResponseLineParts.count - 2)] componentsJoinedByString:@" "]; HttpResponse* response = [HttpResponse httpResponseFromStatusCode:statusCode andStatusText:statusText andHeaders:headers andOptionalBodyData:optionalBodyData]; return [HttpRequestOrResponse httpRequestOrResponse:response]; } else { - checkOperation([requestOrResponseLineParts count] == 3); + checkOperation(requestOrResponseLineParts.count == 3); NSString* method = requestOrResponseLineParts[0]; NSString* location = requestOrResponseLineParts[1]; HttpRequest* request = [HttpRequest httpRequestWithMethod:method diff --git a/Signal/src/network/http/HttpResponse.m b/Signal/src/network/http/HttpResponse.m index 977e6783c..85ab9e67c 100644 --- a/Signal/src/network/http/HttpResponse.m +++ b/Signal/src/network/http/HttpResponse.m @@ -41,7 +41,7 @@ require(data != nil); NSUInteger responseSize; HttpRequestOrResponse* http = [HttpRequestOrResponse tryExtractFromPartialData:data usedLengthOut:&responseSize]; - checkOperation([http isResponse] && responseSize == [data length]); + checkOperation([http isResponse] && responseSize == data.length); return [http response]; } +(HttpResponse*) httpResponse200Ok { @@ -81,7 +81,7 @@ } -(bool) hasEmptyBody { - return [optionalBodyData length] == 0 && [optionalBodyText length] == 0; + return optionalBodyData.length == 0 && optionalBodyText.length == 0; } -(NSString*) getOptionalBodyText { if (optionalBodyText != nil) return optionalBodyText; @@ -106,7 +106,7 @@ NSString* body = [self getOptionalBodyText]; if (body != nil) { [r addObject:@"Content-Length: "]; - [r addObject:[@([body length]) stringValue]]; + [r addObject:[@(body.length) stringValue]]; [r addObject:@"\r\n"]; [r addObject:body]; } else { diff --git a/Signal/src/network/http/HttpSocket.m b/Signal/src/network/http/HttpSocket.m index 556f6272c..9f11388c3 100644 --- a/Signal/src/network/http/HttpSocket.m +++ b/Signal/src/network/http/HttpSocket.m @@ -68,7 +68,7 @@ require([packet isKindOfClass:[NSData class]]); NSData* data = packet; - [partialDataBuffer replaceBytesInRange:NSMakeRange([partialDataBuffer length], [data length]) withBytes:[data bytes]]; + [partialDataBuffer replaceBytesInRange:NSMakeRange(partialDataBuffer.length, data.length) withBytes:[data bytes]]; while (true) { NSUInteger usedDataLength; diff --git a/Signal/src/network/rtp/RtpPacket.m b/Signal/src/network/rtp/RtpPacket.m index c109730ed..355c5eb07 100644 --- a/Signal/src/network/rtp/RtpPacket.m +++ b/Signal/src/network/rtp/RtpPacket.m @@ -69,9 +69,9 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier require((version & ~0x3) == 0); require((payloadType & ~0x7F) == 0); require(extensionData != nil); - require([extensionData length] < 0x10000); + require(extensionData.length < 0x10000); require(contributingSourceIdentifiers != nil); - require([contributingSourceIdentifiers count] < 0x10); + require(contributingSourceIdentifiers.count < 0x10); require(payload != nil); RtpPacket* p = [RtpPacket new]; @@ -102,7 +102,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier require((version & ~0x3) == 0); require((payloadType & ~0x7F) == 0); require(contributingSourceIdentifiers != nil); - require([contributingSourceIdentifiers count] < 0x10); + require(contributingSourceIdentifiers.count < 0x10); require(payload != nil); RtpPacket* p = [RtpPacket new]; @@ -156,7 +156,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier uint8_t contributingSourceCount = [NumberUtil lowUInt4OfUint8:[packetData uint8At:VERSION_AND_PADDING_AND_EXTENSION_AND_CCSRC_FLAG_BYTE_OFFSET]]; *minSize += contributingSourceCount * CONTRIBUTING_SOURCE_ID_LENGTH; - checkOperationDescribe([packetData length] >= *minSize, @"Rtp packet ends before header finished."); + checkOperationDescribe(packetData.length >= *minSize, @"Rtp packet ends before header finished."); NSMutableArray* contributingSources = [NSMutableArray array]; for (NSUInteger i = 0; i < contributingSourceCount; i++) { @@ -183,7 +183,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier if (!hasExtensionHeader) return; *minSize += EXTENSION_HEADER_IDENTIFIER_LENGTH + EXTENSION_HEADER_LENGTH_LENGTH; - checkOperationDescribe([packetData length] >= *minSize, @"Rtp packet ends before header of extension header finished."); + checkOperationDescribe(packetData.length >= *minSize, @"Rtp packet ends before header of extension header finished."); extensionHeaderIdentifier = [packetData bigEndianUInt16At:*offset]; *offset += EXTENSION_HEADER_IDENTIFIER_LENGTH; @@ -192,7 +192,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier *offset += EXTENSION_HEADER_LENGTH_LENGTH; *minSize += extensionLength; - checkOperationDescribe([packetData length] >= *minSize, @"Rtp packet ends before payload of extension header finished."); + checkOperationDescribe(packetData.length >= *minSize, @"Rtp packet ends before payload of extension header finished."); extensionHeaderData = [packetData subdataWithRange:NSMakeRange(*offset, extensionLength)]; *offset += extensionLength; @@ -210,17 +210,17 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier if (!hasPadding) return; - padding = [packetData uint8At:[packetData length] - 1]; + padding = [packetData uint8At:packetData.length - 1]; checkOperationDescribe(padding > 0, @"Padding length must be at least 1 because it includes the suffix byte specifying the length."); *minSize += padding; - checkOperationDescribe([packetData length] >= *minSize, @"Rtp packet overlaps header and padding."); + checkOperationDescribe(packetData.length >= *minSize, @"Rtp packet overlaps header and padding."); } +(RtpPacket*) rtpPacketParsedFromPacketData:(NSData*)packetData { require(packetData != nil); NSUInteger minSize = MINIMUM_RTP_HEADER_LENGTH; - checkOperationDescribe([packetData length] >= minSize, @"Rtp packet ends before header finished."); + checkOperationDescribe(packetData.length >= minSize, @"Rtp packet ends before header finished."); RtpPacket* p = [RtpPacket new]; @@ -235,7 +235,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier [p readContributingSourcesFromPacketData:packetData trackingOffset:&offset andMinSize:&minSize]; [p readExtensionHeaderFromPacketData:packetData trackingOffset:&offset andMinSize:&minSize]; [p readPaddingFromPacketData:packetData andMinSize:&minSize]; - p->payload = [packetData subdataWithRange:NSMakeRange(offset, [packetData length] - p->padding - offset)]; + p->payload = [packetData subdataWithRange:NSMakeRange(offset, packetData.length - p->padding - offset)]; p->sequenceNumber = [self getSequenceNumberFromPacketData:packetData]; p->timeStamp = [self getTimeStampFromPacketData:packetData]; @@ -247,14 +247,14 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier -(NSData*) generateFlags { requireState((version & ~0x3) == 0); requireState((payloadType & ~0x7F) == 0); - requireState([contributingSourceIdentifiers count] < 0x10); + requireState(contributingSourceIdentifiers.count < 0x10); NSMutableData* flags = [NSMutableData dataWithLength:2]; uint8_t versionMask = (uint8_t)(version << VERSION_INDEX); uint8_t paddingBit = padding > 0 ? (uint8_t)(1< 0) { - [paddingData setUint8At:[paddingData length] - 1 to:padding]; + [paddingData setUint8At:paddingData.length - 1 to:padding]; } return paddingData; } -(NSData*) generateSerializedPacketDataUsingInteropOptions:(NSArray*)interopOptions { requireState(hasExtensionHeader == (extensionHeaderData != nil)); - requireState(extensionHeaderData == nil || [extensionHeaderData length] <= MAX_EXTENSION_HEADER_LENGTH); + requireState(extensionHeaderData == nil || extensionHeaderData.length <= MAX_EXTENSION_HEADER_LENGTH); NSData* shouldBeEmpty = [NSData data]; diff --git a/Signal/src/network/rtp/srtp/SrtpStream.m b/Signal/src/network/rtp/srtp/SrtpStream.m index 54b5aafdb..462bd57a2 100644 --- a/Signal/src/network/rtp/srtp/SrtpStream.m +++ b/Signal/src/network/rtp/srtp/SrtpStream.m @@ -11,7 +11,7 @@ require(cipherKey != nil); require(macKey != nil); require(cipherIvSalt != nil); - require([cipherIvSalt length] == IV_SALT_LENGTH); + require(cipherIvSalt.length == IV_SALT_LENGTH); SrtpStream* s = [SrtpStream new]; s->cipherIvSalt = cipherIvSalt; @@ -42,7 +42,7 @@ NSData* authenticatedData = [securedRtpPacket rawPacketDataUsingInteropOptions:nil]; NSData* includedHmac = [authenticatedData takeLastVolatile:HMAC_LENGTH]; NSData* expectedHmac = [[authenticatedData skipLastVolatile:HMAC_LENGTH] hmacWithSha1WithKey:macKey]; - checkOperationDescribe([expectedHmac length] == HMAC_LENGTH, @"Hmac length constant is wrong"); + checkOperationDescribe(expectedHmac.length == HMAC_LENGTH, @"Hmac length constant is wrong"); checkOperationDescribe([includedHmac isEqualToData_TimingSafe:expectedHmac], @"Authentication failed."); NSData* iv = [self getIvForSequenceNumber:[securedRtpPacket sequenceNumber] andSynchronizationSourceIdentifier:[securedRtpPacket synchronizationSourceIdentifier]]; diff --git a/Signal/src/network/rtp/zrtp/HashChain.m b/Signal/src/network/rtp/zrtp/HashChain.m index f2f592839..d6ea67711 100644 --- a/Signal/src/network/rtp/zrtp/HashChain.m +++ b/Signal/src/network/rtp/zrtp/HashChain.m @@ -8,7 +8,7 @@ +(HashChain*) hashChainWithSeed:(NSData*)seed { require(seed != nil); - require([seed length] == HASH_CHAIN_ITEM_LENGTH); + require(seed.length == HASH_CHAIN_ITEM_LENGTH); HashChain* s = [HashChain new]; s->h0 = seed; s->h1 = [s->h0 hashWithSha256]; diff --git a/Signal/src/network/rtp/zrtp/ShortAuthenticationStringGenerator.m b/Signal/src/network/rtp/zrtp/ShortAuthenticationStringGenerator.m index 8804e62e6..7e73b070f 100644 --- a/Signal/src/network/rtp/zrtp/ShortAuthenticationStringGenerator.m +++ b/Signal/src/network/rtp/zrtp/ShortAuthenticationStringGenerator.m @@ -79,7 +79,7 @@ const char* PGP_LIST_ODD[] = { +(NSString*) generateFromData:(NSData*)sasBytes { require(sasBytes != nil); - require([sasBytes length] >= MIN_SAS_BYTES); + require(sasBytes.length >= MIN_SAS_BYTES); uint8_t wordIndexOne = [sasBytes uint8At:0]; uint8_t wordIndexTwo = [sasBytes uint8At:1]; diff --git a/Signal/src/network/rtp/zrtp/agreement/EvpKeyAgreement.m b/Signal/src/network/rtp/zrtp/agreement/EvpKeyAgreement.m index 43e822738..dce18944e 100644 --- a/Signal/src/network/rtp/zrtp/agreement/EvpKeyAgreement.m +++ b/Signal/src/network/rtp/zrtp/agreement/EvpKeyAgreement.m @@ -134,7 +134,7 @@ enum KeyAgreementType { size_t secret_len; unsigned char* secret; - EVP_PKEY* peerkey = [self deserializePublicKey:[publicKey bytes] withLength:[publicKey length]]; + EVP_PKEY* peerkey = [self deserializePublicKey:[publicKey bytes] withLength:publicKey.length]; EVP_PKEY_CTX* ctx; @@ -314,7 +314,7 @@ enum KeyAgreementType { } -(BIGNUM*) generateBignumberFor:(NSData*) data{ - assert([data length] <= INT_MAX ); + assert(data.length <= INT_MAX ); return BN_bin2bn([data bytes], (int)data.length, NULL); } diff --git a/Signal/src/network/rtp/zrtp/packets/CommitPacket.m b/Signal/src/network/rtp/zrtp/packets/CommitPacket.m index 369196d67..07e692ef9 100644 --- a/Signal/src/network/rtp/zrtp/packets/CommitPacket.m +++ b/Signal/src/network/rtp/zrtp/packets/CommitPacket.m @@ -68,12 +68,12 @@ require(dhPart2HelloCommitment != nil); require(hmacKey != nil); - require([h2 length] == HASH_CHAIN_ITEM_LENGTH); - require([hashSpecId length] == HASH_SPEC_LENGTH); - require([cipherSpecId length] == CIPHER_SPEC_LENGTH); - require([authSpecId length] == AUTH_SPEC_LENGTH); - require([agreeSpecId length] == AGREE_SPEC_LENGTH); - require([sasSpecId length] == SAS_SPEC_LENGTH); + require(h2.length == HASH_CHAIN_ITEM_LENGTH); + require(hashSpecId.length == HASH_SPEC_LENGTH); + require(cipherSpecId.length == CIPHER_SPEC_LENGTH); + require(authSpecId.length == AUTH_SPEC_LENGTH); + require(agreeSpecId.length == AGREE_SPEC_LENGTH); + require(sasSpecId.length == SAS_SPEC_LENGTH); CommitPacket* p = [CommitPacket new]; @@ -93,12 +93,12 @@ -(HandshakePacket*) embedInHandshakePacketAuthenticatedWith:(NSData*)hmacKey { require(hmacKey != nil); - requireState([h2 length] == HASH_CHAIN_ITEM_LENGTH); - requireState([hashSpecId length] == HASH_SPEC_LENGTH); - requireState([cipherSpecId length] == CIPHER_SPEC_LENGTH); - requireState([authSpecId length] == AUTH_SPEC_LENGTH); - requireState([agreementSpecId length] == AGREE_SPEC_LENGTH); - requireState([sasSpecId length] == SAS_SPEC_LENGTH); + requireState(h2.length == HASH_CHAIN_ITEM_LENGTH); + requireState(hashSpecId.length == HASH_SPEC_LENGTH); + requireState(cipherSpecId.length == CIPHER_SPEC_LENGTH); + requireState(authSpecId.length == AUTH_SPEC_LENGTH); + requireState(agreementSpecId.length == AGREE_SPEC_LENGTH); + requireState(sasSpecId.length == SAS_SPEC_LENGTH); NSData* payload = [@[ h2, @@ -156,7 +156,7 @@ require(handshakePacket != nil); checkOperation([[handshakePacket typeId] isEqualToData:HANDSHAKE_TYPE_COMMIT]); NSData* payload = [handshakePacket payload]; - checkOperation([payload length] == COMMIT_OFFSET + COMMIT_LENGTH + HANDSHAKE_TRUNCATED_HMAC_LENGTH); + checkOperation(payload.length == COMMIT_OFFSET + COMMIT_LENGTH + HANDSHAKE_TRUNCATED_HMAC_LENGTH); CommitPacket* p = [CommitPacket new]; diff --git a/Signal/src/network/rtp/zrtp/packets/ConfirmPacket.m b/Signal/src/network/rtp/zrtp/packets/ConfirmPacket.m index 45995a104..0b9d8f0ba 100644 --- a/Signal/src/network/rtp/zrtp/packets/ConfirmPacket.m +++ b/Signal/src/network/rtp/zrtp/packets/ConfirmPacket.m @@ -68,8 +68,8 @@ require(cipherKey != nil); require(hashChainH0 != nil); require(iv != nil); - require([iv length] == CONFIRM_IV_LENGTH); - require([hashChainH0 length] == HASH_CHAIN_ITEM_LENGTH); + require(iv.length == CONFIRM_IV_LENGTH); + require(hashChainH0.length == HASH_CHAIN_ITEM_LENGTH); ConfirmPacket* p = [ConfirmPacket new]; p->hashChainH0 = hashChainH0; diff --git a/Signal/src/network/rtp/zrtp/packets/DhPacket.m b/Signal/src/network/rtp/zrtp/packets/DhPacket.m index 397cbe33c..8f232b3c0 100644 --- a/Signal/src/network/rtp/zrtp/packets/DhPacket.m +++ b/Signal/src/network/rtp/zrtp/packets/DhPacket.m @@ -52,7 +52,7 @@ require(sharedSecretHashes != nil); require(publicKeyData != nil); - require([hashChainH0 length] == HASH_CHAIN_ITEM_LENGTH); + require(hashChainH0.length == HASH_CHAIN_ITEM_LENGTH); DhPacket* p = [DhPacket new]; p->isPart1 = isPart1; @@ -93,7 +93,7 @@ NSData* payload = [handshakePacket payload]; checkOperation([[handshakePacket typeId] isEqualToData:expectedTypeIdDhPacket]); - checkOperation([payload length] >= MIN_DH_PKT_LENGTH); + checkOperation(payload.length >= MIN_DH_PKT_LENGTH); DhPacket* p = [DhPacket new]; p->hashChainH1 = [self getHashChainH1FromPayload:payload]; @@ -105,7 +105,7 @@ -(HandshakePacket*) embedIntoHandshakePacketAuthenticatedWithMacKey:(NSData*)macKey { require(macKey != nil); - requireState([hashChainH1 length] == HASH_CHAIN_ITEM_LENGTH); + requireState(hashChainH1.length == HASH_CHAIN_ITEM_LENGTH); NSData* typeId = isPart1 ? HANDSHAKE_TYPE_DH_1 : HANDSHAKE_TYPE_DH_2; diff --git a/Signal/src/network/rtp/zrtp/packets/DhPacketSharedSecretHashes.m b/Signal/src/network/rtp/zrtp/packets/DhPacketSharedSecretHashes.m index b1e1066e5..852ba5068 100644 --- a/Signal/src/network/rtp/zrtp/packets/DhPacketSharedSecretHashes.m +++ b/Signal/src/network/rtp/zrtp/packets/DhPacketSharedSecretHashes.m @@ -22,10 +22,10 @@ require(aux != nil); require(pbx != nil); - require([rs1 length] == DH_RS1_LENGTH); - require([rs2 length] == DH_RS2_LENGTH); - require([aux length] == DH_AUX_LENGTH); - require([pbx length] == DH_PBX_LENGTH); + require(rs1.length == DH_RS1_LENGTH); + require(rs2.length == DH_RS2_LENGTH); + require(aux.length == DH_AUX_LENGTH); + require(pbx.length == DH_PBX_LENGTH); DhPacketSharedSecretHashes* h = [DhPacketSharedSecretHashes new]; h->rs1 = rs1; diff --git a/Signal/src/network/rtp/zrtp/packets/HandshakePacket.m b/Signal/src/network/rtp/zrtp/packets/HandshakePacket.m index 03c2055d9..332cd70eb 100644 --- a/Signal/src/network/rtp/zrtp/packets/HandshakePacket.m +++ b/Signal/src/network/rtp/zrtp/packets/HandshakePacket.m @@ -27,7 +27,7 @@ +(HandshakePacket*) handshakePacketWithTypeId:(NSData*)typeId andPayload:(NSData*)payload { require(typeId != nil); require(payload != nil); - require([typeId length] == HANDSHAKE_TYPE_ID_LENGTH); + require(typeId.length == HANDSHAKE_TYPE_ID_LENGTH); HandshakePacket* p = [HandshakePacket new]; p->typeId = typeId; @@ -93,7 +93,7 @@ // The data corresponding to the rtp extension header is used when hmac-ing return [@[ [NSData dataWithBigEndianBytesOfUInt16:HANDSHAKE_PACKET_EXTENSION_IDENTIFIER], - [NSData dataWithBigEndianBytesOfUInt16:(uint16_t)([payload length] + HEADER_FOOTER_LENGTH_WITHOUT_HMAC)], + [NSData dataWithBigEndianBytesOfUInt16:(uint16_t)(payload.length + HEADER_FOOTER_LENGTH_WITHOUT_HMAC)], typeId, payload ] concatDatas]; @@ -110,14 +110,14 @@ // When we hmac the rtp extension header, the hmac length must be counted even though it's not appended yet return [@[ [NSData dataWithBigEndianBytesOfUInt16:HANDSHAKE_PACKET_EXTENSION_IDENTIFIER], - [NSData dataWithBigEndianBytesOfUInt16:(uint16_t)([payload length] + HEADER_FOOTER_LENGTH_WITH_HMAC)], + [NSData dataWithBigEndianBytesOfUInt16:(uint16_t)(payload.length + HEADER_FOOTER_LENGTH_WITH_HMAC)], typeId, payload ] concatDatas]; } -(RtpPacket*) embeddedIntoRtpPacketWithSequenceNumber:(uint16_t)sequenceNumber usingInteropOptions:(NSArray*)interopOptions { - requireState([typeId length] == HANDSHAKE_TYPE_ID_LENGTH); + requireState(typeId.length == HANDSHAKE_TYPE_ID_LENGTH); NSData* payloadExceptCrc = [self rtpExtensionPayloadExceptCrc]; NSData* extensionDataWithZeroCrc = [(@[payloadExceptCrc, [NSData dataWithBigEndianBytesOfUInt32:0]]) concatDatas]; diff --git a/Signal/src/network/rtp/zrtp/packets/HelloPacket.m b/Signal/src/network/rtp/zrtp/packets/HelloPacket.m index 6861c41c6..f5c0620ad 100644 --- a/Signal/src/network/rtp/zrtp/packets/HelloPacket.m +++ b/Signal/src/network/rtp/zrtp/packets/HelloPacket.m @@ -101,14 +101,14 @@ require((flagsUnusedLow4 & ~FLAGS_UNUSED_LOW_MASK) == 0); require((flagsUnusedHigh4 & ~FLAGS_UNUSED_HIGH_MASK) == 0); - require([versionId length] == VERSION_ID_LENGTH); - require([clientId length] == CLIENT_ID_LENGTH); - require([hashChainH3 length] == HASH_CHAIN_ITEM_LENGTH); - require([hashIds count] <= MAX_SPEC_IDS); - require([cipherIds count] <= MAX_SPEC_IDS); - require([authIds count] <= MAX_SPEC_IDS); - require([agreeIds count] <= MAX_SPEC_IDS); - require([sasIds count] <= MAX_SPEC_IDS); + require(versionId.length == VERSION_ID_LENGTH); + require(clientId.length == CLIENT_ID_LENGTH); + require(hashChainH3.length == HASH_CHAIN_ITEM_LENGTH); + require(hashIds.count <= MAX_SPEC_IDS); + require(cipherIds.count <= MAX_SPEC_IDS); + require(authIds.count <= MAX_SPEC_IDS); + require(agreeIds.count <= MAX_SPEC_IDS); + require(sasIds.count <= MAX_SPEC_IDS); HelloPacket* p = [HelloPacket new]; p->flagsUnusedLow4 = flagsUnusedLow4; @@ -136,16 +136,16 @@ andHighUInt4:flags0SMP]]; [flags setUint8At:UNUSED_HIGH_AND_0SMP_FLAG_INDEX - to:[NumberUtil uint8FromLowUInt4:(uint8_t)[hashIds count] + to:[NumberUtil uint8FromLowUInt4:(uint8_t)hashIds.count andHighUInt4:flagsUnusedLow4]]; [flags setUint8At:AUTH_ID_AND_CIPHER_ID_FLAG_INDEX - to:[NumberUtil uint8FromLowUInt4:(uint8_t)[authIds count] - andHighUInt4:(uint8_t)[cipherIds count]]]; + to:[NumberUtil uint8FromLowUInt4:(uint8_t)authIds.count + andHighUInt4:(uint8_t)cipherIds.count]]; [flags setUint8At:SAS_ID_AND_AGREE_ID_FLAG_INDEX - to:[NumberUtil uint8FromLowUInt4:(uint8_t)[sasIds count] - andHighUInt4:(uint8_t)[agreeIds count]]]; + to:[NumberUtil uint8FromLowUInt4:(uint8_t)sasIds.count + andHighUInt4:(uint8_t)agreeIds.count]]; return flags; } @@ -179,7 +179,7 @@ return [Zid zidWithData:[payload subdataWithRange:NSMakeRange(ZID_OFFSET, ZID_LENGTH)]]; } +(NSArray*) getSpecIdsFromPayload:(NSData*)payload counts:(NSArray*)counts { - checkOperation([payload length] >= SPEC_IDS_OFFSET + SPEC_ID_LENGTH*[counts sumNSUInteger]); + checkOperation(payload.length >= SPEC_IDS_OFFSET + SPEC_ID_LENGTH*[counts sumNSUInteger]); NSMutableArray* result = [NSMutableArray array]; NSUInteger offset = SPEC_IDS_OFFSET; @@ -223,7 +223,7 @@ checkOperationDescribe([[handshakePacket typeId] isEqualToData:HANDSHAKE_TYPE_HELLO], @"Not a hello packet"); NSData* payload = [handshakePacket payload]; - checkOperation([payload length] >= SPEC_IDS_OFFSET); + checkOperation(payload.length >= SPEC_IDS_OFFSET); HelloPacket* p = [HelloPacket new]; diff --git a/Signal/src/network/tcp/tls/NetworkStream.m b/Signal/src/network/tcp/tls/NetworkStream.m index 1f15d47d9..f79e8d9ad 100644 --- a/Signal/src/network/tcp/tls/NetworkStream.m +++ b/Signal/src/network/tcp/tls/NetworkStream.m @@ -82,7 +82,7 @@ while ([writeBuffer enqueuedLength] > 0 && [outputStream hasSpaceAvailable]) { NSData* data = [writeBuffer peekVolatileHeadOfData]; - NSInteger d = [outputStream write:[data bytes] maxLength:[data length]]; + NSInteger d = [outputStream write:[data bytes] maxLength:data.length]; // reached destination buffer capacity? if (d == 0) break; @@ -184,7 +184,7 @@ if (![[futureConnectedAndWritableSource forceGetResult] isEqual:@YES]) return; while ([inputStream hasBytesAvailable]) { - NSInteger numRead = [inputStream read:[readBuffer mutableBytes] maxLength:[readBuffer length]]; + NSInteger numRead = [inputStream read:[readBuffer mutableBytes] maxLength:readBuffer.length]; if (numRead < 0) [self onErrorOccurred:@"Read Error"]; if (numRead <= 0) break; diff --git a/Signal/src/network/udp/UdpSocket.m b/Signal/src/network/udp/UdpSocket.m index b54312e76..ee53566fe 100644 --- a/Signal/src/network/udp/UdpSocket.m +++ b/Signal/src/network/udp/UdpSocket.m @@ -102,7 +102,7 @@ void onReceivedData(CFSocketRef socket, CFSocketCallBackType type, CFDataRef add checkOperation(type == kCFSocketDataCallBack); bool waitingForClient = ![self isRemoteEndPointKnown]; - bool packetHasContent = [data length] > 0; + bool packetHasContent = data.length > 0; bool haveNotSentPacketToBeBounced = !hasSentData; checkOperationDescribe(packetHasContent || waitingForClient || haveNotSentPacketToBeBounced, @"Received empty UDP packet. Probably indicates destination is unreachable."); diff --git a/Signal/src/phone/PhoneNumber.m b/Signal/src/phone/PhoneNumber.m index 956d34e2d..bcf99ae22 100644 --- a/Signal/src/phone/PhoneNumber.m +++ b/Signal/src/phone/PhoneNumber.m @@ -65,7 +65,7 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN NBAsYouTypeFormatter* formatter = [[NBAsYouTypeFormatter alloc] initWithRegionCode:regionCode]; NSString* result = input; - for (NSUInteger i = 0; i < [input length]; i++) { + for (NSUInteger i = 0; i < input.length; i++) { result = [formatter inputDigit:[input substringWithRange:NSMakeRange(i, 1)]]; } return result; @@ -94,9 +94,9 @@ static NSString *const RPDefaultsKeyPhoneNumberCanonical = @"RPDefaultsKeyPhoneN +(PhoneNumber*) tryParsePhoneNumberFromUserSpecifiedText:(NSString*)text { require(text != nil); - char s[[text length]+1]; + char s[text.length+1]; int xx = 0; - for (NSUInteger i = 0; i < [text length]; i++) { + for (NSUInteger i = 0; i < text.length; i++) { unichar x = [text characterAtIndex:i]; if (x == '+' || (x >= '0' && x <= '9')) { s[xx++] = (char)x; diff --git a/Signal/src/phone/signaling/CallConnectUtil_Server.m b/Signal/src/phone/signaling/CallConnectUtil_Server.m index 557d3a7c5..be5f0f487 100644 --- a/Signal/src/phone/signaling/CallConnectUtil_Server.m +++ b/Signal/src/phone/signaling/CallConnectUtil_Server.m @@ -124,9 +124,9 @@ unlessCancelled:untilCancelledToken]; Future* futureEndPoint = [futureDnsResult then:^(NSArray* ipAddresses) { - require([ipAddresses count] > 0); + require(ipAddresses.count > 0); - IpAddress* address = ipAddresses[arc4random_uniform((unsigned int)[ipAddresses count])]; + IpAddress* address = ipAddresses[arc4random_uniform((unsigned int)ipAddresses.count)]; return [IpEndPoint ipEndPointAtAddress:address onPort:sessionDescriptor.relayUdpPort]; }]; diff --git a/Signal/src/phone/signaling/ResponderSessionDescriptor.m b/Signal/src/phone/signaling/ResponderSessionDescriptor.m index c2d859094..d11d06bb9 100644 --- a/Signal/src/phone/signaling/ResponderSessionDescriptor.m +++ b/Signal/src/phone/signaling/ResponderSessionDescriptor.m @@ -54,7 +54,7 @@ checkOperation(message != nil); NSData* authenticatedPayload = [message decodedAsBase64Data]; - checkOperation([authenticatedPayload length] > 0); + checkOperation(authenticatedPayload.length > 0); uint8_t includedRemoteNotificationFormatVersion = [authenticatedPayload uint8At:0]; checkOperation(includedRemoteNotificationFormatVersion == EXPECTED_REMOTE_NOTIF_FORMAT_VERSION); @@ -86,7 +86,7 @@ } +(NSData*) verifyAndRemoveMacFromRemoteNotifcationData:(NSData*)data { require(data != nil); - checkOperation([data length] >= HMAC_TRUNCATED_SIZE); + checkOperation(data.length >= HMAC_TRUNCATED_SIZE); NSData* includedMac = [data takeLast:HMAC_TRUNCATED_SIZE]; NSData* payload = [data skipLast:HMAC_TRUNCATED_SIZE]; NSData* signalingMacKey = [SGNKeychainUtil signalingMacKey]; @@ -97,7 +97,7 @@ } +(NSData*) decryptRemoteNotificationData:(NSData*)data { require(data != nil); - checkOperation([data length] >= VERSION_SIZE + IV_SIZE); + checkOperation(data.length >= VERSION_SIZE + IV_SIZE); NSData* cipherKey = [SGNKeychainUtil signalingCipherKey]; NSData* iv = [data subdataWithRange:NSMakeRange(VERSION_SIZE, IV_SIZE)]; NSData* cipherText = [data skip:VERSION_SIZE+IV_SIZE]; diff --git a/Signal/src/phone/signaling/SignalUtil.m b/Signal/src/phone/signaling/SignalUtil.m index 472a2eab7..0cdc7b7fa 100644 --- a/Signal/src/phone/signaling/SignalUtil.m +++ b/Signal/src/phone/signaling/SignalUtil.m @@ -18,7 +18,7 @@ -(NSNumber*) tryGetSessionId { if (![self.location hasPrefix:@"/session/"]) return nil; - NSString* sessionIdText = [self.location substringFromIndex:[@"/session/" length]]; + NSString* sessionIdText = [self.location substringFromIndex:@"/session/".length]; sessionIdText = [sessionIdText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; NSNumber* sessionIdNumber = [sessionIdText tryParseAsDecimalNumber]; diff --git a/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilter.m b/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilter.m index ab764d403..fcd79c372 100644 --- a/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilter.m +++ b/Signal/src/phone/signaling/number directory/PhoneNumberDirectoryFilter.m @@ -44,7 +44,7 @@ checkOperation(hashCountValue > 0); NSData* responseBody = [response getOptionalBodyData]; - checkOperation([responseBody length] > 0); + checkOperation(responseBody.length > 0); BloomFilter* bloomFilter = [BloomFilter bloomFilterWithHashCount:(NSUInteger)hashCountValue andData:responseBody]; diff --git a/Signal/src/profiling/CategorizingLogger.m b/Signal/src/profiling/CategorizingLogger.m index 46b9bc411..badfd9491 100644 --- a/Signal/src/profiling/CategorizingLogger.m +++ b/Signal/src/profiling/CategorizingLogger.m @@ -19,7 +19,7 @@ -(void) log:(NSString*)category details:(id)details { NSNumber* index = indexDic[category]; if (index == nil) { - index = @([indexDic count]); + index = @(indexDic.count); indexDic[category] = index; } NSUInteger x = [index unsignedIntegerValue]; diff --git a/Signal/src/profiling/EventWindow.m b/Signal/src/profiling/EventWindow.m index c0c490a6a..cb2fe3d3c 100644 --- a/Signal/src/profiling/EventWindow.m +++ b/Signal/src/profiling/EventWindow.m @@ -27,10 +27,10 @@ lastWindowEnding = endOfWindowTime; NSTimeInterval startOfWindowTime = endOfWindowTime - windowDuration; - while([events count] > 0 && [[events peek] doubleValue] < startOfWindowTime) { + while(events.count > 0 && [[events peek] doubleValue] < startOfWindowTime) { [events dequeue]; } - return [events count]; + return events.count; } @end diff --git a/Signal/src/util/ArrayUtil.m b/Signal/src/util/ArrayUtil.m index 81b520fb7..0cd1d16aa 100644 --- a/Signal/src/util/ArrayUtil.m +++ b/Signal/src/util/ArrayUtil.m @@ -4,7 +4,7 @@ @implementation NSArray (Util) -(NSData*) toUint8Data { - NSUInteger n = [self count]; + NSUInteger n = self.count; uint8_t x[n]; for (NSUInteger i = 0; i < n; i++) { x[i] = [(NSNumber*)self[i] unsignedCharValue]; @@ -21,8 +21,8 @@ NSMutableData* result = [NSMutableData dataWithLength:t]; uint8_t* dst = [result mutableBytes]; for (NSData* d in self) { - memcpy(dst, [d bytes], [d length]); - dst += [d length]; + memcpy(dst, [d bytes], d.length); + dst += d.length; } return result; } diff --git a/Signal/src/util/BloomFilter.m b/Signal/src/util/BloomFilter.m index 63ae09cc3..c7ec72dd7 100644 --- a/Signal/src/util/BloomFilter.m +++ b/Signal/src/util/BloomFilter.m @@ -32,7 +32,7 @@ -(uint32_t) hash:(NSData*)value index:(NSUInteger)index { NSData* key = [[@(index) stringValue] encodedAsAscii]; NSData* hash = [value hmacWithSha1WithKey:key]; - return [hash bigEndianUInt32At:0] % ([data length] * 8); + return [hash bigEndianUInt32At:0] % (data.length * 8); } -(bool) isBitSetAt:(uint32_t)bitIndex { diff --git a/Signal/src/util/Conversions.m b/Signal/src/util/Conversions.m index 0097bb0ad..3c92b7ec6 100644 --- a/Signal/src/util/Conversions.m +++ b/Signal/src/util/Conversions.m @@ -5,12 +5,12 @@ @implementation NSData (Conversions) -(uint16_t) bigEndianUInt16At:(NSUInteger)offset { - require(offset <= [self length]-sizeof(uint16_t)); + require(offset <= self.length-sizeof(uint16_t)); return (uint16_t)[self uint8At:1+offset] | (uint16_t)((uint16_t)[self uint8At:0+offset] << 8); } -(uint32_t) bigEndianUInt32At:(NSUInteger)offset { - require(offset <= [self length]-sizeof(uint32_t)); + require(offset <= self.length-sizeof(uint32_t)); return ((uint32_t)[self uint8At:3+offset] << 0) | ((uint32_t)[self uint8At:2+offset] << 8) | ((uint32_t)[self uint8At:1+offset] << 16) @@ -34,7 +34,7 @@ +(NSData*) switchEndiannessOfData:(NSData*)data{ const void* bytes = [data bytes]; NSMutableData* switchedEndianData = [NSMutableData new]; - for (NSUInteger i = [data length]; i > 0; --i){ + for (NSUInteger i = data.length; i > 0; --i){ uint8_t byte = *(((uint8_t*)(bytes))+((i-1)*sizeof(uint8_t))); [switchedEndianData appendData:[NSData dataWithBytes:&byte length:sizeof(byte)]]; } diff --git a/Signal/src/util/Crc32.m b/Signal/src/util/Crc32.m index eb17a68fb..76b66d15c 100644 --- a/Signal/src/util/Crc32.m +++ b/Signal/src/util/Crc32.m @@ -31,7 +31,7 @@ void generateCRC32Table(uint32_t *pTable, uint32_t poly) { uint32_t crc = seed; uint8_t *pBytes = (uint8_t *)[self bytes]; - NSUInteger length = [self length]; + NSUInteger length = self.length; while (length--) { crc = (crc>>8) ^ pTable[(crc & 0xFF) ^ *pBytes++]; diff --git a/Signal/src/util/DataUtil.m b/Signal/src/util/DataUtil.m index 28edaa62a..f1d8741f7 100644 --- a/Signal/src/util/DataUtil.m +++ b/Signal/src/util/DataUtil.m @@ -7,7 +7,7 @@ // (also, by virtue of being const, there are no threading/entrancy issues) static const int SafeNonNullPointerToStaticStorageLocation[1]; - if ([self length] == 0) { + if (self.length == 0) { return SafeNonNullPointerToStaticStorageLocation; } else { require([self bytes] != nil); @@ -23,10 +23,10 @@ } -(NSNumber*) tryFindIndexOf:(NSData*)subData { require(subData != nil); - if ([subData length] > [self length]) return nil; + if (subData.length > self.length) return nil; - NSUInteger subDataLength = [subData length]; - NSUInteger excessLength = [self length] - subDataLength; + NSUInteger subDataLength = subData.length; + NSUInteger excessLength = self.length - subDataLength; const uint8_t* selfBytes = [self bytes]; const uint8_t* subDataBytes = [subData bytes]; @@ -41,14 +41,14 @@ if (![self bytes]) return @""; NSMutableString* result = [NSMutableString string]; - for (NSUInteger i = 0; i < [self length]; ++i) + for (NSUInteger i = 0; i < self.length; ++i) [result appendString:[NSString stringWithFormat:@"%02x", [self uint8At:i]]]; return result; } -(NSString*) decodedAsUtf8 { // workaround for empty data having nil bytes - if ([self length] == 0) return @""; + if (self.length == 0) return @""; [NSString stringWithUTF8String:[self bytes]]; NSString* result = [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding]; @@ -57,9 +57,9 @@ } -(NSString*) decodedAsAscii { // workaround for empty data having nil bytes - if ([self length] == 0) return @""; + if (self.length == 0) return @""; // workaround for initWithData not enforcing the fact that NSASCIIStringEncoding means strict 7-bit - for (NSUInteger i = 0; i < [self length]; i++) { + for (NSUInteger i = 0; i < self.length; i++) { checkOperationDescribe(([self uint8At:i] & 0x80) == 0, @"Invalid ascii data."); } @@ -71,8 +71,8 @@ const int MinPrintableChar = ' '; const int MaxPrintableChar = '~'; - NSMutableData* d = [NSMutableData dataWithLength:[self length]]; - for (NSUInteger i = 0; i < [self length]; i++) { + NSMutableData* d = [NSMutableData dataWithLength:self.length]; + for (NSUInteger i = 0; i < self.length; i++) { uint8_t v = [self uint8At:i]; if (v < MinPrintableChar || v > MaxPrintableChar) v = '.'; [d setUint8At:i to:v]; @@ -81,24 +81,24 @@ } -(NSData*) skip:(NSUInteger)offset { - require(offset <= [self length]); - return [self subdataWithRange:NSMakeRange(offset, [self length] - offset)]; + require(offset <= self.length); + return [self subdataWithRange:NSMakeRange(offset, self.length - offset)]; } -(NSData*) take:(NSUInteger)takeCount { - require(takeCount <= [self length]); + require(takeCount <= self.length); return [self subdataWithRange:NSMakeRange(0, takeCount)]; } -(NSData*) skipLast:(NSUInteger)skipLastCount { - require(skipLastCount <= [self length]); - return [self subdataWithRange:NSMakeRange(0, [self length] - skipLastCount)]; + require(skipLastCount <= self.length); + return [self subdataWithRange:NSMakeRange(0, self.length - skipLastCount)]; } -(NSData*) takeLast:(NSUInteger)takeLastCount { - require(takeLastCount <= [self length]); - return [self subdataWithRange:NSMakeRange([self length] - takeLastCount, takeLastCount)]; + require(takeLastCount <= self.length); + return [self subdataWithRange:NSMakeRange(self.length - takeLastCount, takeLastCount)]; } -(NSData*) subdataVolatileWithRange:(NSRange)range { - NSUInteger length = [self length]; + NSUInteger length = self.length; require(range.location <= length); require(range.length <= length); require(range.location + range.length <= length); @@ -106,20 +106,20 @@ return [NSData dataWithBytesNoCopy:(uint8_t*)[self bytes] + range.location length:range.length freeWhenDone:NO]; } -(NSData*) skipVolatile:(NSUInteger)offset { - require(offset <= [self length]); - return [self subdataVolatileWithRange:NSMakeRange(offset, [self length] - offset)]; + require(offset <= self.length); + return [self subdataVolatileWithRange:NSMakeRange(offset, self.length - offset)]; } -(NSData*) takeVolatile:(NSUInteger)takeCount { - require(takeCount <= [self length]); + require(takeCount <= self.length); return [self subdataVolatileWithRange:NSMakeRange(0, takeCount)]; } -(NSData*) skipLastVolatile:(NSUInteger)skipLastCount { - require(skipLastCount <= [self length]); - return [self subdataVolatileWithRange:NSMakeRange(0, [self length] - skipLastCount)]; + require(skipLastCount <= self.length); + return [self subdataVolatileWithRange:NSMakeRange(0, self.length - skipLastCount)]; } -(NSData*) takeLastVolatile:(NSUInteger)takeLastCount { - require(takeLastCount <= [self length]); - return [self subdataVolatileWithRange:NSMakeRange([self length] - takeLastCount, takeLastCount)]; + require(takeLastCount <= self.length); + return [self subdataVolatileWithRange:NSMakeRange(self.length - takeLastCount, takeLastCount)]; } -(uint8_t) highUint4AtByteOffset:(NSUInteger)offset { @@ -129,7 +129,7 @@ return [self uint8At:offset] & 0xF; } -(uint8_t) uint8At:(NSUInteger)offset { - require(offset < [self length]); + require(offset < self.length); return ((const uint8_t*)[self bytes])[offset]; } -(const uint8_t*) constPtrToUint8At:(NSUInteger)offset { @@ -140,7 +140,7 @@ const NSUInteger BitsPerByte = 8; const uint8_t Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - NSUInteger byteCount = [self length]; + NSUInteger byteCount = self.length; NSUInteger bitCount = byteCount*BitsPerByte; NSUInteger base64WordCount = bitCount / BitsPerBase64Word; if (base64WordCount * BitsPerBase64Word < bitCount) base64WordCount += 1; @@ -180,12 +180,12 @@ @implementation NSMutableData (Util) -(void) setUint8At:(NSUInteger)offset to:(uint8_t)newValue { - require(offset < [self length]); + require(offset < self.length); ((uint8_t*)[self mutableBytes])[offset] = newValue; } -(void) replaceBytesStartingAt:(NSUInteger)offset withData:(NSData*)data { require(data != nil); - require(offset + [data length] <= [self length]); - [self replaceBytesInRange:NSMakeRange(offset, [data length]) withBytes:[data bytes]]; + require(offset + data.length <= self.length); + [self replaceBytesInRange:NSMakeRange(offset, data.length) withBytes:[data bytes]]; } @end diff --git a/Signal/src/util/FunctionalUtil.m b/Signal/src/util/FunctionalUtil.m index 1eabd7c7e..ad29c2d44 100644 --- a/Signal/src/util/FunctionalUtil.m +++ b/Signal/src/util/FunctionalUtil.m @@ -32,7 +32,7 @@ -(NSArray*) map:(id (^)(id item))projection { require(projection != nil); - NSMutableArray* r = [NSMutableArray arrayWithCapacity:[self count]]; + NSMutableArray* r = [NSMutableArray arrayWithCapacity:self.count]; for (id e in self) { [r addObject:projection(e)]; } @@ -78,7 +78,7 @@ for (id value in self) { result[keySelector(value)] = value; } - checkOperation([result count] == [self count]); + checkOperation(result.count == self.count); return result; } diff --git a/Signal/src/util/StringUtil.m b/Signal/src/util/StringUtil.m index b5972b8c8..c50108aa3 100644 --- a/Signal/src/util/StringUtil.m +++ b/Signal/src/util/StringUtil.m @@ -5,9 +5,9 @@ @implementation NSString (Util) -(NSData*) decodedAsHexString { - require([self length] % 2 == 0); + require(self.length % 2 == 0); - NSUInteger n = [self length] / 2; + NSUInteger n = self.length / 2; uint8_t result[n]; for (NSUInteger i = 0; i < n; i++) { unsigned int r; @@ -52,17 +52,17 @@ require(regex != nil); require(replacement != nil); NSMutableString* m = [self mutableCopy]; - [regex replaceMatchesInString:m options:0 range:NSMakeRange(0, [m length]) withTemplate:replacement]; + [regex replaceMatchesInString:m options:0 range:NSMakeRange(0, m.length) withTemplate:replacement]; return m; } -(bool) containsAnyMatches:(NSRegularExpression*)regex { require(regex != nil); - return [regex numberOfMatchesInString:self options:0 range:NSMakeRange(0, [self length])] > 0; + return [regex numberOfMatchesInString:self options:0 range:NSMakeRange(0, self.length)] > 0; } -(NSString*) withPrefixRemovedElseNull:(NSString*)prefix { require(prefix != nil); - if ([prefix length] > 0 && ![self hasPrefix:prefix]) return nil; - return [self substringFromIndex:[prefix length]]; + if (prefix.length > 0 && ![self hasPrefix:prefix]) return nil; + return [self substringFromIndex:prefix.length]; } -(NSData*) decodedAsJsonIntoData { NSError* jsonParseError = nil; @@ -93,11 +93,11 @@ // Determine amount of information (based on length and padding) NSUInteger paddingCount = 0; - while (paddingCount < 2 && paddingCount < [self length] - 1 && [self characterAtIndex:[self length] - paddingCount - 1] == '=') { + while (paddingCount < 2 && paddingCount < self.length - 1 && [self characterAtIndex:self.length - paddingCount - 1] == '=') { paddingCount += 1; } - NSUInteger base64WordCount = [self length] - paddingCount; - NSUInteger bitCount = [self length]*BitsPerBase64Word - paddingCount*BitsPerByte; + NSUInteger base64WordCount = self.length - paddingCount; + NSUInteger bitCount = self.length*BitsPerBase64Word - paddingCount*BitsPerByte; NSUInteger byteCount = bitCount / BitsPerByte; checkOperation(bitCount % BitsPerByte == 0); diff --git a/Signal/src/util/Zid.m b/Signal/src/util/Zid.m index 9455ff5b9..8fb7c9747 100644 --- a/Signal/src/util/Zid.m +++ b/Signal/src/util/Zid.m @@ -4,7 +4,7 @@ @implementation Zid +(Zid*) zidWithData:(NSData*)zidData { require(zidData != nil); - require([zidData length] == 12); + require(zidData.length == 12); Zid* s = [Zid new]; s->data = zidData; return s; diff --git a/Signal/src/util/collections/CyclicalBuffer.m b/Signal/src/util/collections/CyclicalBuffer.m index 818d9a3b0..a71fc8ff0 100644 --- a/Signal/src/util/collections/CyclicalBuffer.m +++ b/Signal/src/util/collections/CyclicalBuffer.m @@ -15,10 +15,10 @@ -(void) enqueueData:(NSData*)data { require(data != nil); - if([data length] == 0) return; + if(data.length == 0) return; - NSUInteger incomingDataLength = [data length]; - NSUInteger bufferCapacity = [buffer length]; + NSUInteger incomingDataLength = data.length; + NSUInteger bufferCapacity = buffer.length; NSUInteger writeOffset = (readOffset + count) % bufferCapacity; NSUInteger bufferSpaceAvailable = bufferCapacity - count; NSUInteger writeSlack = bufferCapacity - writeOffset; @@ -45,7 +45,7 @@ if (incomingDataLength > writeSlack) { [buffer replaceBytesInRange:NSMakeRange(0, incomingDataLength - writeSlack) withBytes:(uint8_t*)[data bytes] + writeSlack]; } - count += [data length]; + count += data.length; } -(NSUInteger) enqueuedLength { @@ -55,14 +55,14 @@ -(void) discard:(NSUInteger)length { require(length <= count); count -= length; - readOffset = (readOffset + length)%(unsigned int)[buffer length]; + readOffset = (readOffset + length)%(unsigned int)buffer.length; } -(NSData*) peekDataWithLength:(NSUInteger)length{ require(length <= count); if (length == 0) return [NSData data]; - NSUInteger readSlack = [buffer length] - readOffset; + NSUInteger readSlack = buffer.length - readOffset; NSMutableData* result = [NSMutableData dataWithLength:length]; [result replaceBytesInRange:NSMakeRange(0, MIN(readSlack, length)) withBytes:(uint8_t*)[buffer bytes] + readOffset]; @@ -80,7 +80,7 @@ } -(NSData*) dequeuePotentialyVolatileDataWithLength:(NSUInteger)length { - NSUInteger readSlack = [buffer length] - readOffset; + NSUInteger readSlack = buffer.length - readOffset; if (readSlack < length) return [self dequeueDataWithLength:length]; @@ -91,7 +91,7 @@ } -(NSData*) peekVolatileHeadOfData { - NSUInteger capacity = [buffer length]; + NSUInteger capacity = buffer.length; NSUInteger slack = capacity - readOffset; return [buffer subdataVolatileWithRange:NSMakeRange(readOffset, MIN(count, slack))]; } diff --git a/Signal/src/util/collections/PriorityQueue.m b/Signal/src/util/collections/PriorityQueue.m index fb4464bb7..533a7cd48 100644 --- a/Signal/src/util/collections/PriorityQueue.m +++ b/Signal/src/util/collections/PriorityQueue.m @@ -12,7 +12,7 @@ } -(void)enqueue:(id)item { - NSUInteger curIndex = [items count]; + NSUInteger curIndex = items.count; [items addObject:item]; while (curIndex > 0) { NSUInteger parentIndex = (curIndex - 1) >> 1; @@ -26,16 +26,16 @@ } -(id)peek { - requireState([items count] > 0); + requireState(items.count > 0); return items[0]; } -(id) dequeue { - requireState([items count] > 0); + requireState(items.count > 0); id result = items[0]; // iteratively pull up smaller child until we hit the bottom of the heap - NSUInteger endangeredIndex = [items count] - 1; + NSUInteger endangeredIndex = items.count - 1; id endangeredItem = items[endangeredIndex]; NSUInteger i = 0; while (true) { @@ -60,7 +60,7 @@ } -(NSUInteger) count { - return [items count]; + return items.count; } @end diff --git a/Signal/src/util/collections/Queue.m b/Signal/src/util/collections/Queue.m index 029988c8b..5bbb43853 100644 --- a/Signal/src/util/collections/Queue.m +++ b/Signal/src/util/collections/Queue.m @@ -14,24 +14,24 @@ [items addObject:item]; } -(id) tryDequeue { - if ([self count] == 0) return nil; + if (self.count == 0) return nil; return [self dequeue]; } -(id) dequeue { - requireState([self count] > 0); + requireState(self.count > 0); id result = items[0]; [items removeObjectAtIndex:0]; return result; } -(id) peek { - requireState([self count] > 0); + requireState(self.count > 0); return items[0]; } -(id) peekAt:(NSUInteger)offset { - require(offset < [self count]); + require(offset < self.count); return items[offset]; } -(NSUInteger) count { - return [items count]; + return items.count; } @end diff --git a/Signal/src/view controllers/CallLogViewController.m b/Signal/src/view controllers/CallLogViewController.m index f5fd4285e..23339e06a 100644 --- a/Signal/src/view controllers/CallLogViewController.m +++ b/Signal/src/view controllers/CallLogViewController.m @@ -87,7 +87,7 @@ typedef NSComparisonResult (^CallComparator)(RecentCall*, RecentCall*); #pragma mark - UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return (NSInteger)[_recents count]; + return (NSInteger)_recents.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Signal/src/view controllers/ContactDetailViewController.m b/Signal/src/view controllers/ContactDetailViewController.m index bf3f10a41..3f9fdd930 100644 --- a/Signal/src/view controllers/ContactDetailViewController.m +++ b/Signal/src/view controllers/ContactDetailViewController.m @@ -53,7 +53,7 @@ static NSString *const FAVOURITE_FALSE_ICON_NAME = @"favourite_false_icon"; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - NSInteger secureNumberCount = (NSInteger)[_contact.userTextPhoneNumbers count] + (NSInteger)[_contact.emails count]; + NSInteger secureNumberCount = (NSInteger)_contact.userTextPhoneNumbers.count + (NSInteger)_contact.emails.count; return _contact.notes != nil ? secureNumberCount + 1 : secureNumberCount; } @@ -65,15 +65,15 @@ static NSString *const FAVOURITE_FALSE_ICON_NAME = @"favourite_false_icon"; reuseIdentifier:DETAIL_TABLE_CELL_IDENTIFIER]; } - if ((NSUInteger)indexPath.row < [_contact.userTextPhoneNumbers count]) { + if ((NSUInteger)indexPath.row < _contact.userTextPhoneNumbers.count) { PhoneNumber *phoneNumber = [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:_contact.userTextPhoneNumbers[(NSUInteger)indexPath.row]]; BOOL isSecure = [[[[Environment getCurrent] phoneDirectoryManager] getCurrentFilter] containsPhoneNumber:phoneNumber]; [cell configureWithPhoneNumber:phoneNumber isSecure:isSecure]; - } else if ((NSUInteger)indexPath.row < [_contact.userTextPhoneNumbers count] + [_contact.emails count]) { + } else if ((NSUInteger)indexPath.row < _contact.userTextPhoneNumbers.count + _contact.emails.count) { - NSUInteger emailIndex = (NSUInteger)indexPath.row - [_contact.userTextPhoneNumbers count]; + NSUInteger emailIndex = (NSUInteger)indexPath.row - _contact.userTextPhoneNumbers.count; [cell configureWithEmailString:_contact.emails[emailIndex]]; } else { @@ -99,8 +99,8 @@ static NSString *const FAVOURITE_FALSE_ICON_NAME = @"favourite_false_icon"; [self openPhoneAppWithPhoneNumber:number]; } - } else if ((NSUInteger)indexPath.row < [_contact.userTextPhoneNumbers count] + [_contact.emails count]) { - NSUInteger emailIndex = (NSUInteger)indexPath.row - [_contact.userTextPhoneNumbers count]; + } else if ((NSUInteger)indexPath.row < _contact.userTextPhoneNumbers.count + _contact.emails.count) { + NSUInteger emailIndex = (NSUInteger)indexPath.row - _contact.userTextPhoneNumbers.count; [self openEmailAppWithEmail:_contact.emails[emailIndex]]; } } diff --git a/Signal/src/view controllers/CountryCodeViewController.m b/Signal/src/view controllers/CountryCodeViewController.m index 32b918aae..1ab763551 100644 --- a/Signal/src/view controllers/CountryCodeViewController.m +++ b/Signal/src/view controllers/CountryCodeViewController.m @@ -34,7 +34,7 @@ static NSString *const CONTRY_CODE_TABLE_CELL_IDENTIFIER = @"CountryCodeTableVie #pragma mark - UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return (NSInteger)[_countryCodes count]; + return (NSInteger)_countryCodes.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/Signal/src/view controllers/DialerViewController.m b/Signal/src/view controllers/DialerViewController.m index a21989b29..8b341a235 100644 --- a/Signal/src/view controllers/DialerViewController.m +++ b/Signal/src/view controllers/DialerViewController.m @@ -95,7 +95,7 @@ } - (void)removeLastDigit { - NSUInteger n = [_currentNumberMutable length]; + NSUInteger n = _currentNumberMutable.length; if (n > 0) { [_currentNumberMutable deleteCharactersInRange:NSMakeRange(n - 1, 1)]; } @@ -134,7 +134,7 @@ - (PhoneNumber *)phoneNumberForCurrentInput { NSString *numberText = [_currentNumberMutable copy]; - if ([numberText length]> 0 && [[numberText substringToIndex:1] isEqualToString:COUNTRY_CODE_PREFIX]) { + if (numberText.length> 0 && [[numberText substringToIndex:1] isEqualToString:COUNTRY_CODE_PREFIX]) { return [PhoneNumber tryParsePhoneNumberFromE164:numberText]; } else { return [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:numberText]; diff --git a/Signal/src/view controllers/FavouritesViewController.m b/Signal/src/view controllers/FavouritesViewController.m index 714021a19..0c5b3fb98 100644 --- a/Signal/src/view controllers/FavouritesViewController.m +++ b/Signal/src/view controllers/FavouritesViewController.m @@ -53,7 +53,7 @@ static NSString *const CONTACT_TABLE_VIEW_CELL_IDENTIFIER = @"ContactTableViewCe } - (void)hideTableViewIfNoFavourites { - BOOL hideFavourites = [_favourites count] == 0; + BOOL hideFavourites = _favourites.count == 0; _favouriteTableView.hidden = hideFavourites; } @@ -95,7 +95,7 @@ static NSString *const CONTACT_TABLE_VIEW_CELL_IDENTIFIER = @"ContactTableViewCe #pragma mark - UITableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return _isSearching ? (NSInteger)[_searchFavourites count] : (NSInteger)[_favourites count]; + return _isSearching ? (NSInteger)_searchFavourites.count : (NSInteger)_favourites.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -142,7 +142,7 @@ static NSString *const CONTACT_TABLE_VIEW_CELL_IDENTIFIER = @"ContactTableViewCe - (NSArray *)favouritesForSearchTerm:(NSString *)searchTerm { return [_favourites filter:^int(Contact *contact) { - return [searchTerm length] == 0 || [ContactsManager name:[contact fullName] matchesQuery:searchTerm]; + return searchTerm.length == 0 || [ContactsManager name:[contact fullName] matchesQuery:searchTerm]; }]; } diff --git a/Signal/src/view controllers/InboxFeedViewController.m b/Signal/src/view controllers/InboxFeedViewController.m index d1c383030..4700659aa 100644 --- a/Signal/src/view controllers/InboxFeedViewController.m +++ b/Signal/src/view controllers/InboxFeedViewController.m @@ -210,14 +210,14 @@ static NSString *const FOOTER_TABLE_CELL_IDENTIFIER = @"InboxFeedFooterCell"; if (_isSearching) { if (section == SEARCH_TABLE_SECTION_FEED) { - return (NSInteger)[_searchInboxFeed count]; + return (NSInteger)_searchInboxFeed.count; } else if (section == SEARCH_TABLE_SECTION_REGISTERED) { - return (NSInteger)[_searchRegisteredContacts count]; + return (NSInteger)_searchRegisteredContacts.count; } else { - return (NSInteger)[_searchUnregisteredContacts count]; + return (NSInteger)_searchUnregisteredContacts.count; } } else { - NSInteger inboxFeedAndInfoCellCount = (NSInteger)[_inboxFeed count] + 1; + NSInteger inboxFeedAndInfoCellCount = (NSInteger)_inboxFeed.count + 1; return inboxFeedAndInfoCellCount; } } @@ -243,7 +243,7 @@ static NSString *const FOOTER_TABLE_CELL_IDENTIFIER = @"InboxFeedFooterCell"; [self showContactViewControllerWithContact:_searchUnregisteredContacts[(NSUInteger)indexPath.row]]; } } else { - if (indexPath.row < (NSInteger)[_inboxFeed count]) { + if (indexPath.row < (NSInteger)_inboxFeed.count) { [self showRecentCallViewControllerWithRecentCall:_inboxFeed[(NSUInteger)indexPath.row]]; } } @@ -251,7 +251,7 @@ static NSString *const FOOTER_TABLE_CELL_IDENTIFIER = @"InboxFeedFooterCell"; - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == SEARCH_TABLE_SECTION_FEED) { - if ((NSUInteger)indexPath.row == [_inboxFeed count]) { + if ((NSUInteger)indexPath.row == _inboxFeed.count) { return FOOTER_CELL_HEIGHT; } else { return INBOX_TABLE_VIEW_CELL_HEIGHT; @@ -272,7 +272,7 @@ static NSString *const FOOTER_TABLE_CELL_IDENTIFIER = @"InboxFeedFooterCell"; } - (UITableViewCell *)inboxFeedCellForIndexPath:(NSIndexPath *)indexPath { - if (!_isSearching && (NSUInteger)[indexPath row] == [_inboxFeed count]) { + if (!_isSearching && (NSUInteger)[indexPath row] == _inboxFeed.count) { return [self inboxFeedFooterCell]; } else { return [self inboxCellForIndexPath:indexPath andIsSearching:NO]; @@ -339,7 +339,7 @@ static NSString *const FOOTER_TABLE_CELL_IDENTIFIER = @"InboxFeedFooterCell"; #pragma mark - SearchBarTitleViewDelegate - (void)searchBarTitleView:(SearchBarTitleView *)view didSearchForTerm:(NSString *)term { - BOOL searching = [term length] > 0; + BOOL searching = term.length > 0; _isSearching = searching; if (searching) { diff --git a/Signal/src/view controllers/InviteContactsViewController.m b/Signal/src/view controllers/InviteContactsViewController.m index abe96be29..349d168d0 100644 --- a/Signal/src/view controllers/InviteContactsViewController.m +++ b/Signal/src/view controllers/InviteContactsViewController.m @@ -118,7 +118,7 @@ static NSString *const INVITE_CONTACTS_TABLE_CELL_IDENTIFIER = @"ContactTableVie NSMutableArray *indexPaths = [NSMutableArray array]; - for (int i = 0; i < (NSInteger)[_newWhisperUsers count]; i++) { + for (int i = 0; i < (NSInteger)_newWhisperUsers.count; i++) { [indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:FIRST_TABLE_SECTION]]; } [_contactTableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic]; @@ -139,9 +139,9 @@ static NSString *const INVITE_CONTACTS_TABLE_CELL_IDENTIFIER = @"ContactTableVie - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == FIRST_TABLE_SECTION) { - return _isSearching ? 0 : (NSInteger)[_newWhisperUsers count]; + return _isSearching ? 0 : (NSInteger)_newWhisperUsers.count; } else { - return (NSInteger)[_displayedContacts count]; + return (NSInteger)_displayedContacts.count; } } @@ -187,7 +187,7 @@ static NSString *const INVITE_CONTACTS_TABLE_CELL_IDENTIFIER = @"ContactTableVie } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { - if (section == FIRST_TABLE_SECTION && !_isSearching && [_newWhisperUsers count] > 0) { + if (section == FIRST_TABLE_SECTION && !_isSearching && _newWhisperUsers.count > 0) { return _unseenWhisperUsersHeaderView; } else if (section == SECOND_TABLE_SECTION) { return _regularContactsHeaderView; @@ -197,7 +197,7 @@ static NSString *const INVITE_CONTACTS_TABLE_CELL_IDENTIFIER = @"ContactTableVie } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { - if (_isSearching || ([_newWhisperUsers count] == 0 && section == FIRST_TABLE_SECTION)) { + if (_isSearching || (_newWhisperUsers.count == 0 && section == FIRST_TABLE_SECTION)) { return 0.0f; } else { diff --git a/Signal/src/view controllers/LeftSideMenuViewController.m b/Signal/src/view controllers/LeftSideMenuViewController.m index 1ade071f6..f024c357e 100644 --- a/Signal/src/view controllers/LeftSideMenuViewController.m +++ b/Signal/src/view controllers/LeftSideMenuViewController.m @@ -159,9 +159,9 @@ static NSString *WHISPER_SYSTEMS_BUGREPORT_URL = @"http://support.whispersystems - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == FIRST_SECTION_INDEX) { - return (NSInteger)[_firstSectionOptions count]; + return (NSInteger)_firstSectionOptions.count; } else { - return (NSInteger)[_secondSectionOptions count]; + return (NSInteger)_secondSectionOptions.count; } } diff --git a/Signal/src/view controllers/RegisterViewController.m b/Signal/src/view controllers/RegisterViewController.m index a975c3520..79ad8ca7f 100644 --- a/Signal/src/view controllers/RegisterViewController.m +++ b/Signal/src/view controllers/RegisterViewController.m @@ -69,7 +69,7 @@ - (void)setPlaceholderTextColor:(UIColor *)color { NSAttributedString *placeholder = _phoneNumberTextField.attributedPlaceholder; - if ([placeholder length]) { + if (placeholder.length) { NSDictionary * attributes = [placeholder attributesAtIndex:0 effectiveRange:NULL]; diff --git a/Signal/src/view controllers/SettingsViewController.m b/Signal/src/view controllers/SettingsViewController.m index bbb538308..d2fbe9241 100644 --- a/Signal/src/view controllers/SettingsViewController.m +++ b/Signal/src/view controllers/SettingsViewController.m @@ -51,7 +51,7 @@ static NSString *const CHECKBOX_EMPTY_IMAGE_NAME = @"checkbox_empty"; - (void)viewWillDisappear:(BOOL)animated { [self saveExpandedSectionPreferences]; - if ([self.navigationController.viewControllers count] > 1) { + if (self.navigationController.viewControllers.count > 1) { [self.navigationController setNavigationBarHidden:NO animated:YES]; } @@ -85,11 +85,11 @@ static NSString *const CHECKBOX_EMPTY_IMAGE_NAME = @"checkbox_empty"; [attributedString addAttribute:NSFontAttributeName value:prefixFont - range:NSMakeRange(0, [numberPrefixString length])]; + range:NSMakeRange(0, numberPrefixString.length)]; [attributedString addAttribute:NSFontAttributeName value:numberFont - range:NSMakeRange([numberPrefixString length] + 1, [localNumberString length])]; + range:NSMakeRange(numberPrefixString.length + 1, localNumberString.length)]; return attributedString; } @@ -155,7 +155,7 @@ static NSString *const CHECKBOX_EMPTY_IMAGE_NAME = @"checkbox_empty"; - (NSArray *)indexPathsForCells:(NSArray *)cells forRow:(NSInteger)row { NSMutableArray *indexPaths = [NSMutableArray array]; - for (NSUInteger i = 0; i < [cells count]; i++) { + for (NSUInteger i = 0; i < cells.count; i++) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(NSInteger)i inSection:row]; [indexPaths addObject:indexPath]; } @@ -255,7 +255,7 @@ static NSString *const CHECKBOX_EMPTY_IMAGE_NAME = @"checkbox_empty"; #pragma mark - UITableViewDelegate - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return (NSInteger)[_sectionHeaderViews count]; + return (NSInteger)_sectionHeaderViews.count; } - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { @@ -269,9 +269,9 @@ static NSString *const CHECKBOX_EMPTY_IMAGE_NAME = @"checkbox_empty"; - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { UIView *headerView = _sectionHeaderViews[(NSUInteger)section]; if (headerView == _privacyAndSecurityHeaderView) { - return (NSInteger)[_privacyTableViewCells count]; + return (NSInteger)_privacyTableViewCells.count; } else if (headerView == _debuggingHeaderView){ - return (NSInteger)[_debuggingTableViewCells count]; + return (NSInteger)_debuggingTableViewCells.count; }else { return 0; } diff --git a/Signal/src/views/InboxFeedTableViewCell.m b/Signal/src/views/InboxFeedTableViewCell.m index a84708314..f98487829 100644 --- a/Signal/src/views/InboxFeedTableViewCell.m +++ b/Signal/src/views/InboxFeedTableViewCell.m @@ -80,19 +80,19 @@ [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] - range:NSMakeRange(0, [timeString length])]; + range:NSMakeRange(0, timeString.length)]; [attributedString addAttribute:NSForegroundColorAttributeName value:[UIUtil darkBackgroundColor] - range:NSMakeRange([timeString length],[dateString length])]; + range:NSMakeRange(timeString.length,dateString.length)]; [attributedString addAttribute:NSFontAttributeName value:[UIUtil helveticaLightWithSize:TIME_LABEL_SIZE] - range:NSMakeRange(0, [timeString length])]; + range:NSMakeRange(0, timeString.length)]; [attributedString addAttribute:NSFontAttributeName value:[UIUtil helveticaRegularWithSize:DATE_LABEL_SIZE] - range:NSMakeRange([timeString length],[dateString length])]; + range:NSMakeRange(timeString.length,dateString.length)]; return attributedString; } diff --git a/Signal/test/audio/AudioStretcherTest.m b/Signal/test/audio/AudioStretcherTest.m index 362690e6f..9761aad60 100644 --- a/Signal/test/audio/AudioStretcherTest.m +++ b/Signal/test/audio/AudioStretcherTest.m @@ -17,7 +17,7 @@ NSData* inputData = sineWave(freq, 8000, 8000); NSData* outputData = [a stretchAudioData:inputData stretchFactor:stretch]; - NSUInteger outputSampleCount = [outputData length]/sizeof(int16_t); + NSUInteger outputSampleCount = outputData.length/sizeof(int16_t); if ([s doubleValue] == 1) { test([inputData isEqualToData:outputData]); } diff --git a/Signal/test/audio/JitterQueueTest.m b/Signal/test/audio/JitterQueueTest.m index b0223f09c..b62983c99 100644 --- a/Signal/test/audio/JitterQueueTest.m +++ b/Signal/test/audio/JitterQueueTest.m @@ -6,8 +6,8 @@ #import "DiscardingLog.h" #import "Queue.h" -#define testLoggedNothing(q) test([q->messageQueue count] == 0) -#define testLogged(q, s) test([q->messageQueue count] > 0 && [s isEqualToString:[q->messageQueue dequeue]]) +#define testLoggedNothing(q) test(q->messageQueue.count == 0) +#define testLogged(q, s) test(q->messageQueue.count > 0 && [s isEqualToString:[q->messageQueue dequeue]]) #define testLoggedArrival(q, n) testLogged(q, ([NSString stringWithFormat:@"%d", n])) #define testLoggedBadArrival(q, sequenceNumber, arrivalType) testLogged(q, ([NSString stringWithFormat:@"bad +%d: %d", sequenceNumber, arrivalType])) #define testLoggedBadDequeueOfType(q, type) testLogged(q, ([NSString stringWithFormat:@"-%d", type])) @@ -26,18 +26,18 @@ JitterQueue* r2 = [JitterQueue jitterQueue]; EncodedAudioPacket* q1 = [EncodedAudioPacket encodedAudioPacketWithAudioData:[NSData dataWithLength:1] andSequenceNumber:100]; - test([r1 count] == 0); + test(r1.count == 0); test([r1 tryEnqueue:q1]); - test([r1 count] == 1); + test(r1.count == 1); test([r1 tryDequeue] == q1); - test([r1 count] == 0); + test(r1.count == 0); EncodedAudioPacket* q2 = [EncodedAudioPacket encodedAudioPacketWithAudioData:[NSData dataWithLength:1] andSequenceNumber:0xFF00]; - test([r2 count] == 0); + test(r2.count == 0); test([r2 tryEnqueue:q2]); - test([r2 count] == 1); + test(r2.count == 1); test([r2 tryDequeue] == q2); - test([r2 count] == 0); + test(r2.count == 0); } -(void) testJitterAdvances { JitterQueue* r = [JitterQueue jitterQueue]; @@ -45,12 +45,12 @@ for (uint16_t i = 0; i < 10; i++) { EncodedAudioPacket* q = [EncodedAudioPacket encodedAudioPacketWithAudioData:[NSData dataWithLength:1] andSequenceNumber:i]; test([r tryEnqueue:q]); - test([r count] == i+1); + test(r.count == i+1); } for (uint16_t i = 0; i < 10; i++) { test([[r tryDequeue] sequenceNumber] == i); - test([r count] == 9-i); + test(r.count == 9-i); } test([r tryDequeue] == nil); } diff --git a/Signal/test/audio/SpeexCodecTest.m b/Signal/test/audio/SpeexCodecTest.m index 59d14c5e2..76e82d4c6 100644 --- a/Signal/test/audio/SpeexCodecTest.m +++ b/Signal/test/audio/SpeexCodecTest.m @@ -11,20 +11,20 @@ -(void) testSpeexConstantBitRate { NSMutableData* x1 = [NSMutableData dataWithLength:320]; NSMutableData* x2 = [NSMutableData dataWithLength:320]; - for (NSUInteger i = 0; i < [x2 length]; i++) { + for (NSUInteger i = 0; i < x2.length; i++) { [x2 setUint8At:i to:(uint8_t)(i & 255)]; } SpeexCodec* c = [SpeexCodec speexCodec]; NSData* e100 = [c encode:x1]; NSData* e200 = [c encode:x2]; - test([e200 length] == [e100 length]); + test(e200.length == e100.length); } -(void) testSpeexRoundTripMaintainsLength { NSMutableData* x1 = [NSMutableData dataWithLength:320]; NSMutableData* x2 = [NSMutableData dataWithLength:320]; - for (NSUInteger i = 0; i < [x2 length]; i++) { + for (NSUInteger i = 0; i < x2.length; i++) { [x2 setUint8At:i to:(uint8_t)(i & 255)]; } @@ -33,7 +33,7 @@ NSData* e200 = [c encode:x2]; NSData* d100 = [c decode:e100]; NSData* d200 = [c decode:e200]; - test([d100 length] == [x1 length]); - test([d200 length] == [x2 length]); + test(d100.length == x1.length); + test(d200.length == x2.length); } @end diff --git a/Signal/test/network/IpAddressTest.m b/Signal/test/network/IpAddressTest.m index 39785835b..f1c9ebbef 100644 --- a/Signal/test/network/IpAddressTest.m +++ b/Signal/test/network/IpAddressTest.m @@ -78,7 +78,7 @@ -(void) testSockaddrDataIpv4 { NSData* d = [[IpAddress ipAddressFromString:@"4.5.6.7"] sockaddrDataWithPort:5]; struct sockaddr_in s; - test([d length] >= sizeof(struct sockaddr_in)); + test(d.length >= sizeof(struct sockaddr_in)); memcpy(&s, [d bytes], sizeof(struct sockaddr_in)); test(s.sin_port == ntohs(5)); test(s.sin_family == AF_INET); @@ -87,7 +87,7 @@ -(void) testSockaddrDataIpv6 { NSData* d = [[IpAddress ipAddressFromString:@"2001:0db8:85a3:0000:0000:8a2e:0370:7334"] sockaddrDataWithPort:5]; struct sockaddr_in6 s; - test([d length] >= sizeof(struct sockaddr_in6)); + test(d.length >= sizeof(struct sockaddr_in6)); memcpy(&s, [d bytes], sizeof(struct sockaddr_in6)); test(s.sin6_port == ntohs(5)); test(s.sin6_family == AF_INET6); diff --git a/Signal/test/network/udp/UdpSocketTest.m b/Signal/test/network/udp/UdpSocketTest.m index 9cea4f59f..1d83e8a4a 100644 --- a/Signal/test/network/udp/UdpSocketTest.m +++ b/Signal/test/network/udp/UdpSocketTest.m @@ -35,7 +35,7 @@ __block bool failed = false; [sender startWithHandler:[PacketHandler packetHandler:^(NSData* packet) { // there's a length check here because when the destination is unreachable the sender sometimes gets a superfluous empty data callback... no idea why. - senderReceivedData |= [packet length] > 0; + senderReceivedData |= packet.length > 0; } withErrorHandler:^(id error, id relatedInfo, bool causedTermination) { failed = true; }] untilCancelled:[senderLife getToken]]; @@ -91,7 +91,7 @@ onPort:[receiver localPort]]]; [sender startWithHandler:[PacketHandler packetHandler:^(NSData* packet) { // there's a length check here because when the destination is unreachable the sender sometimes gets a superfluous empty data callback... no idea why. - senderReceivedData |= [packet length] > 0; + senderReceivedData |= packet.length > 0; } withErrorHandler:^(id error, id relatedInfo, bool causedTermination) { failed = true; }] untilCancelled:[senderLife getToken]]; @@ -130,7 +130,7 @@ UdpSocket* listener = [UdpSocket udpSocketToFirstSenderOnLocalPort:port]; [listener startWithHandler:[PacketHandler packetHandler:^(NSData* packet) { listenerReceiveCount += 1; - listenerReceiveLength += [packet length]; + listenerReceiveLength += packet.length; listenerReceivedLast = packet; } withErrorHandler:^(id error, id relatedInfo, bool causedTermination) { test(false); @@ -140,7 +140,7 @@ UdpSocket* client = [UdpSocket udpSocketTo:e]; [client startWithHandler:[PacketHandler packetHandler:^(NSData* packet) { clientReceiveCount += 1; - clientReceiveLength += [packet length]; + clientReceiveLength += packet.length; clientReceivedLast = packet; } withErrorHandler:^(id error, id relatedInfo, bool causedTermination) { test(false); diff --git a/Signal/test/util/CryptoToolsTest.m b/Signal/test/util/CryptoToolsTest.m index c0df497e8..e0808f905 100644 --- a/Signal/test/util/CryptoToolsTest.m +++ b/Signal/test/util/CryptoToolsTest.m @@ -42,9 +42,9 @@ NSData* key =[@"2b7e151628aed2a6abf7158809cf4f3c" decodedAsHexString]; NSData* cipher = [plain encryptWithAesInCipherBlockChainingModeWithPkcs7PaddingWithKey:key andIv:iv]; - test([cipher length] % 16 == 0); + test(cipher.length % 16 == 0); NSData* replain = [cipher decryptWithAesInCipherBlockChainingModeWithPkcs7PaddingWithKey:key andIv:iv]; - test([plain length] == [replain length]); + test(plain.length == replain.length); } -(void) testKnownSha256 { char* valText = "The quick brown fox jumps over the lazy dog"; @@ -58,7 +58,7 @@ NSData* d2 = [CryptoTools generateSecureRandomData:8]; test(5 == [[CryptoTools generateSecureRandomData:5] length]); - test(8 == [d length]); + test(8 == d.length); // extremely unlikely to fail if any reasonable amount of entropy is going into d and d2 test(![d isEqualToData:d2]); diff --git a/Signal/test/util/PriorityQueueTest.m b/Signal/test/util/PriorityQueueTest.m index c66c52adf..3f9c2bd46 100644 --- a/Signal/test/util/PriorityQueueTest.m +++ b/Signal/test/util/PriorityQueueTest.m @@ -50,14 +50,14 @@ NSArray* Permutations(NSUInteger count) { return (NSComparisonResult)NSOrderedSame; } }]; - test([q count] == 0); + test(q.count == 0); testThrows([q peek]); testThrows([q dequeue]); [q enqueue:@1]; [q enqueue:@2]; [q enqueue:@3]; - test([q count] == 3); + test(q.count == 3); test([[q peek] intValue] == 1); test([[q dequeue] intValue] == 1); test([[q peek] intValue] == 2); @@ -105,10 +105,10 @@ NSArray* Permutations(NSUInteger count) { // dequeues in order for (NSUInteger i = 0; i < N; i++) { - test([q count] == N - i); + test(q.count == N - i); test([[q dequeue] unsignedIntegerValue] == i); } - test([q count] == 0); + test(q.count == 0); } } -(void) testSortsRandomLargePermutations { @@ -132,10 +132,10 @@ NSArray* Permutations(NSUInteger count) { // dequeues in order for (NSUInteger i = 0; i < Size; i++) { - test([q count] == Size - i); + test(q.count == Size - i); test([[q dequeue] unsignedIntegerValue] == i); } - test([q count] == 0); + test(q.count == 0); } } diff --git a/Signal/test/util/QueueTest.m b/Signal/test/util/QueueTest.m index 7a0be6a52..dcb53639d 100644 --- a/Signal/test/util/QueueTest.m +++ b/Signal/test/util/QueueTest.m @@ -6,24 +6,24 @@ -(void) queueTest { Queue* q = [Queue new]; - test([q count] == 0); + test(q.count == 0); testThrows([q peek]); testThrows([q dequeue]); [q enqueue:@5]; - test([q count] == 1); + test(q.count == 1); test([[q peek] isEqualToNumber:@5]); [q enqueue:@23]; - test([q count] == 2); + test(q.count == 2); test([[q peek] isEqualToNumber:@5]); test([[q dequeue] isEqualToNumber:@5]); - test([q count] == 1); + test(q.count == 1); test([[q peek] isEqualToNumber:@23]); test([[q dequeue] isEqualToNumber:@23]); - test([q count] == 0); + test(q.count == 0); testThrows([q peek]); testThrows([q dequeue]); } diff --git a/Signal/test/util/UtilTest.m b/Signal/test/util/UtilTest.m index 6d898d3a7..651b0623c 100644 --- a/Signal/test/util/UtilTest.m +++ b/Signal/test/util/UtilTest.m @@ -26,7 +26,7 @@ test([[(@[]) toUint8Data] length] == 0); NSData* d = [@[@0, @1] toUint8Data]; - test([d length] == 2); + test(d.length == 2); test(((uint8_t*)[d bytes])[0] == 0); test(((uint8_t*)[d bytes])[1] == 1); }