mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Prefix NSArray categories.
Begin process of prefixing categories on Foundation and UIKit. This follows Cocoa best practices. This makes sense given the number of third party libraries the project incorporates, which may include their own colliding category method names. Use OWS prefix on classes that may be used across apps.
This commit is contained in:
parent
135f139dae
commit
f65d552f6d
20 changed files with 110 additions and 110 deletions
|
@ -29,7 +29,7 @@
|
|||
if (framesToSend.count < AUDIO_FRAMES_PER_PACKET) return nil;
|
||||
|
||||
uint16_t sequenceNumber = nextSequenceNumber++;
|
||||
NSData* payload = [framesToSend concatDatas];
|
||||
NSData* payload = [framesToSend ows_concatDatas];
|
||||
|
||||
[framesToSend removeAllObjects];
|
||||
return [EncodedAudioPacket encodedAudioPacketWithAudioData:payload
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
NSData* signalingCipherKey = SGNKeychainUtil.signalingCipherKey;
|
||||
NSData* signalingMacKey = SGNKeychainUtil.signalingMacKey;
|
||||
NSData* signalingExtraKeyData = SGNKeychainUtil.signalingCipherKey;
|
||||
NSString* encodedSignalingKey = @[signalingCipherKey, signalingMacKey, signalingExtraKeyData].concatDatas.encodedAsBase64;
|
||||
NSString* encodedSignalingKey = @[signalingCipherKey, signalingMacKey, signalingExtraKeyData].ows_concatDatas.encodedAsBase64;
|
||||
apiCall.parameters = @{@"key" : encodedSignalingKey, @"challenge" : verificationCode};
|
||||
return apiCall;
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier
|
|||
-(NSData*) generateCcrcData {
|
||||
return [[contributingSourceIdentifiers map:^id(NSNumber* ccsrc) {
|
||||
return [NSData dataWithBigEndianBytesOfUInt32:[ccsrc unsignedIntValue]];
|
||||
}] concatDatas];
|
||||
}] ows_concatDatas];
|
||||
}
|
||||
-(NSData*) generateExtensionHeaderData {
|
||||
if (!hasExtensionHeader) return [NSData data];
|
||||
|
@ -276,7 +276,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier
|
|||
[NSData dataWithBigEndianBytesOfUInt16:extensionHeaderIdentifier],
|
||||
[NSData dataWithBigEndianBytesOfUInt16:(uint16_t)extensionHeaderData.length],
|
||||
extensionHeaderData
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
-(NSData*) generatePaddingData {
|
||||
NSMutableData* paddingData = [NSMutableData dataWithLength:padding];
|
||||
|
@ -310,7 +310,7 @@ andSynchronizationSourceIdentifier:(uint32_t)synchronizedSourceIdentifier
|
|||
[self generateExtensionHeaderData],
|
||||
payload,
|
||||
[self generatePaddingData]
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
|
||||
-(RtpPacket*) withSequenceNumber:(uint16_t)newSequenceNumber {
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
RtpPacket* encryptedRtpPacket = [normalRtpPacket withPayload:encryptedPayload];
|
||||
NSData* hmac = [[encryptedRtpPacket rawPacketDataUsingInteropOptions:@[]] hmacWithSha1WithKey:macKey];
|
||||
NSData* authenticatedEncryptedPayload = [@[encryptedPayload, hmac] concatDatas];
|
||||
NSData* authenticatedEncryptedPayload = [@[encryptedPayload, hmac] ows_concatDatas];
|
||||
|
||||
return [encryptedRtpPacket withPayload:authenticatedEncryptedPayload];
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@
|
|||
s2Length,
|
||||
s3Length
|
||||
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
|
||||
return [data hashWithSha256];
|
||||
}
|
||||
|
@ -107,7 +107,7 @@
|
|||
[[dhPart1 embeddedIntoHandshakePacket] dataUsedForAuthentication],
|
||||
[[dhPart2 embeddedIntoHandshakePacket] dataUsedForAuthentication]
|
||||
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
|
||||
return [data hashWithSha256];
|
||||
|
||||
|
@ -148,13 +148,13 @@
|
|||
|
||||
counter,
|
||||
label.encodedAsUtf8,
|
||||
[@[@0] toUint8Data],
|
||||
[@[@0] ows_toUint8Data],
|
||||
initiatorZid.getData,
|
||||
responderZid.getData,
|
||||
totalHash,
|
||||
[NSData dataWithBigEndianBytesOfUInt32:truncatedLength]
|
||||
|
||||
].concatDatas;
|
||||
].ows_concatDatas;
|
||||
|
||||
NSData* digest = [input hmacWithSha256WithKey:sharedSecret];
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
andAuthSpecId:COMMIT_DEFAULT_AUTH_SPEC_ID
|
||||
andAgreeSpecId:keyAgreementProtocol.getId
|
||||
andSasSpecId:COMMIT_DEFAULT_SAS_SPEC_ID
|
||||
andDhPart2HelloCommitment:@[dhPart2Data, helloData].concatDatas.hashWithSha256
|
||||
andDhPart2HelloCommitment:@[dhPart2Data, helloData].ows_concatDatas.hashWithSha256
|
||||
andHmacKey:hashChain.h1];
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@
|
|||
agreementSpecId,
|
||||
sasSpecId,
|
||||
dhPart2HelloCommitment
|
||||
].concatDatas;
|
||||
].ows_concatDatas;
|
||||
|
||||
return [[HandshakePacket handshakePacketWithTypeId:HANDSHAKE_TYPE_COMMIT andPayload:payload] withHmacAppended:hmacKey];
|
||||
}
|
||||
|
@ -120,7 +120,7 @@
|
|||
NSData* expected = [[@[
|
||||
[[dhPart2 embeddedIntoHandshakePacket] dataUsedForAuthentication],
|
||||
[[hello embeddedIntoHandshakePacket] dataUsedForAuthentication]]
|
||||
concatDatas] hashWithSha256];
|
||||
ows_concatDatas] hashWithSha256];
|
||||
checkOperation([dhPart2HelloCommitment isEqualToData_TimingSafe:expected]);
|
||||
}
|
||||
-(void) verifyMacWithHashChainH1:(NSData*)hashChainH1 {
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
hashChainH0,
|
||||
[NSData dataWithBigEndianBytesOfUInt32:unusedAndSignatureLengthAndFlags],
|
||||
[NSData dataWithBigEndianBytesOfUInt32:cacheExperationInterval]
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
|
||||
NSData* encrytedSensitiveData = [sensitiveData encryptWithAesInCipherFeedbackModeWithKey:cipherKey andIv:iv];
|
||||
NSData* hmacForSensitiveData = [[encrytedSensitiveData hmacWithSha256WithKey:macKey] take:TRUNCATED_HMAC_LENGTH];
|
||||
|
@ -100,7 +100,7 @@
|
|||
hmacForSensitiveData,
|
||||
iv,
|
||||
encrytedSensitiveData
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
|
||||
return [HandshakePacket handshakePacketWithTypeId:typeId andPayload:payload];
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
[sharedSecretHashes aux],
|
||||
[sharedSecretHashes pbx],
|
||||
publicKeyData
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
|
||||
return [[HandshakePacket handshakePacketWithTypeId:typeId andPayload:payload] withHmacAppended:macKey];
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
-(HandshakePacket*) withHmacAppended:(NSData*)macKey {
|
||||
require(macKey != nil);
|
||||
NSData* digest = [[[self rtpExtensionPayloadUsedForHmacBeforeHmacAppended] hmacWithSha256WithKey:macKey] take:HANDSHAKE_TRUNCATED_HMAC_LENGTH];
|
||||
NSData* authenticatedPayload = [@[payload, digest] concatDatas];
|
||||
NSData* authenticatedPayload = [@[payload, digest] ows_concatDatas];
|
||||
return [HandshakePacket handshakePacketWithTypeId:typeId andPayload:authenticatedPayload];
|
||||
}
|
||||
-(HandshakePacket*) withHmacVerifiedAndRemoved:(NSData*)macKey {
|
||||
|
@ -96,14 +96,14 @@
|
|||
[NSData dataWithBigEndianBytesOfUInt16:(uint16_t)(payload.length + HEADER_FOOTER_LENGTH_WITHOUT_HMAC)],
|
||||
typeId,
|
||||
payload
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
|
||||
-(NSData*) rtpExtensionPayloadExceptCrc {
|
||||
return [@[
|
||||
typeId,
|
||||
payload
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
|
||||
-(NSData*) rtpExtensionPayloadUsedForHmacBeforeHmacAppended {
|
||||
|
@ -113,14 +113,14 @@
|
|||
[NSData dataWithBigEndianBytesOfUInt16:(uint16_t)(payload.length + HEADER_FOOTER_LENGTH_WITH_HMAC)],
|
||||
typeId,
|
||||
payload
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
|
||||
-(RtpPacket*) embeddedIntoRtpPacketWithSequenceNumber:(uint16_t)sequenceNumber usingInteropOptions:(NSArray*)interopOptions {
|
||||
requireState(typeId.length == HANDSHAKE_TYPE_ID_LENGTH);
|
||||
|
||||
NSData* payloadExceptCrc = [self rtpExtensionPayloadExceptCrc];
|
||||
NSData* extensionDataWithZeroCrc = [(@[payloadExceptCrc, [NSData dataWithBigEndianBytesOfUInt32:0]]) concatDatas];
|
||||
NSData* extensionDataWithZeroCrc = [(@[payloadExceptCrc, [NSData dataWithBigEndianBytesOfUInt32:0]]) ows_concatDatas];
|
||||
RtpPacket* packetWithZeroCrc = [RtpPacket rtpPacketWithVersion:0 // invalid version 0 indicates a zrtp handshake packet
|
||||
andPadding:false
|
||||
andContributingSourceIdentifiers:@[]
|
||||
|
@ -134,7 +134,7 @@
|
|||
andPayload:[NSData data]];
|
||||
|
||||
uint32_t crc = [[[packetWithZeroCrc rawPacketDataUsingInteropOptions:interopOptions] skipLastVolatile:4] crc32];
|
||||
NSData* extensionData = [(@[payloadExceptCrc, [NSData dataWithBigEndianBytesOfUInt32:crc]]) concatDatas];
|
||||
NSData* extensionData = [(@[payloadExceptCrc, [NSData dataWithBigEndianBytesOfUInt32:crc]]) ows_concatDatas];
|
||||
|
||||
return [RtpPacket rtpPacketWithVersion:0 // invalid version 0 indicates a zrtp handshake packet
|
||||
andPadding:false
|
||||
|
|
|
@ -157,9 +157,9 @@
|
|||
hashChainH3,
|
||||
zid.getData,
|
||||
[self generateFlags],
|
||||
[[@[hashIds, cipherIds, authIds, agreeIds, sasIds] concatArrays] concatDatas]
|
||||
[[@[hashIds, cipherIds, authIds, agreeIds, sasIds] ows_concatArrays] ows_concatDatas]
|
||||
|
||||
] concatDatas];
|
||||
] ows_concatDatas];
|
||||
}
|
||||
|
||||
-(void) verifyMacWithHashChainH2:(NSData*)hashChainH2 {
|
||||
|
|
|
@ -87,7 +87,7 @@
|
|||
NSData* signalingCipherKey = SGNKeychainUtil.signalingCipherKey;
|
||||
NSData* signalingMacKey = SGNKeychainUtil.signalingMacKey;
|
||||
NSData* signalingExtraKeyData = SGNKeychainUtil.signalingCipherKey;
|
||||
NSString* encodedSignalingKey = @[signalingCipherKey, signalingMacKey, signalingExtraKeyData].concatDatas.encodedAsBase64;
|
||||
NSString* encodedSignalingKey = @[signalingCipherKey, signalingMacKey, signalingExtraKeyData].ows_concatDatas.encodedAsBase64;
|
||||
NSString* body = @{@"key" : encodedSignalingKey, @"challenge" : challenge}.encodedAsJson;
|
||||
|
||||
return [HttpRequest httpRequestWithBasicAuthenticationAndMethod:@"PUT"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface NSArray (Util)
|
||||
-(NSData*) toUint8Data;
|
||||
-(NSData*) concatDatas;
|
||||
-(NSArray*) concatArrays;
|
||||
-(NSData*)ows_toUint8Data;
|
||||
-(NSData*)ows_concatDatas;
|
||||
-(NSArray*)ows_concatArrays;
|
||||
@end
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
@implementation NSArray (Util)
|
||||
|
||||
-(NSData*) toUint8Data {
|
||||
-(NSData*)ows_toUint8Data {
|
||||
NSUInteger n = self.count;
|
||||
uint8_t x[n];
|
||||
for (NSUInteger i = 0; i < n; i++) {
|
||||
|
@ -11,7 +11,7 @@
|
|||
}
|
||||
return [NSData dataWithBytes:x length:n];
|
||||
}
|
||||
-(NSData*) concatDatas {
|
||||
-(NSData*)ows_concatDatas {
|
||||
NSUInteger t = 0;
|
||||
for (id d in self) {
|
||||
require([d isKindOfClass:NSData.class]);
|
||||
|
@ -26,7 +26,7 @@
|
|||
}
|
||||
return result;
|
||||
}
|
||||
-(NSArray*) concatArrays {
|
||||
-(NSArray*)ows_concatArrays {
|
||||
NSMutableArray* r = [NSMutableArray array];
|
||||
for (id e in self) {
|
||||
require([e isKindOfClass:NSArray.class]);
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
@0x80,@0,@0,@5,
|
||||
@0,@0,@0,@0,
|
||||
@0,@0,@0,@0,
|
||||
@0,@1,@2,@3,@4] toUint8Data];
|
||||
@0,@1,@2,@3,@4] ows_toUint8Data];
|
||||
test([[r rawPacketDataUsingInteropOptions:@[]] isEqualToData:expectedData]);
|
||||
|
||||
// reparsing packed data gives same packet
|
||||
|
@ -80,7 +80,7 @@
|
|||
@0,@0,@0,@101,
|
||||
@0,@0,@0,@102,
|
||||
@0,@1,@2,@3,@4,@5,
|
||||
@0,@0,@3] toUint8Data];
|
||||
@0,@0,@3] ows_toUint8Data];
|
||||
|
||||
test([[r rawPacketDataUsingInteropOptions:@[]] isEqualToData:expectedData]);
|
||||
test([r isEqualToRtpPacket:[RtpPacket rtpPacketParsedFromPacketData:expectedData]]);
|
||||
|
@ -120,7 +120,7 @@
|
|||
@0xFE,@0xAB,
|
||||
@0, @5,
|
||||
@10,@11,@12,@13,@14,
|
||||
@0,@1,@2,@3,@4] toUint8Data];
|
||||
@0,@1,@2,@3,@4] ows_toUint8Data];
|
||||
test([[r rawPacketDataUsingInteropOptions:@[]] isEqualToData:expectedData]);
|
||||
test([r isEqualToRtpPacket:[RtpPacket rtpPacketParsedFromPacketData:expectedData]]);
|
||||
test(![r isEqualToRtpPacket:[RtpPacket rtpPacketWithDefaultsAndSequenceNumber:0 andPayload:[NSData data]]]);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
-(void) testHashChainKnown {
|
||||
testThrows([HashChain hashChainWithSeed:nil]);
|
||||
NSData* d0 = [NSMutableData dataWithLength:32];
|
||||
NSData* d1 = [@[@0x66,@0x68,@0x7A,@0xAD,@0xF8,@0x62,@0xBD,@0x77,@0x6C,@0x8F,@0xC1,@0x8B,@0x8E,@0x9F,@0x8E,@0x20,@0x08,@0x97,@0x14,@0x85,@0x6E,@0xE2,@0x33,@0xB3,@0x90,@0x2A,@0x59,@0x1D,@0x0D,@0x5F,@0x29,@0x25] toUint8Data];
|
||||
NSData* d1 = [@[@0x66,@0x68,@0x7A,@0xAD,@0xF8,@0x62,@0xBD,@0x77,@0x6C,@0x8F,@0xC1,@0x8B,@0x8E,@0x9F,@0x8E,@0x20,@0x08,@0x97,@0x14,@0x85,@0x6E,@0xE2,@0x33,@0xB3,@0x90,@0x2A,@0x59,@0x1D,@0x0D,@0x5F,@0x29,@0x25] ows_toUint8Data];
|
||||
NSData* d2 = [d1 hashWithSha256];
|
||||
NSData* d3 = [d2 hashWithSha256];
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
andInitiatorZid:initiatorZid
|
||||
andResponderZid:responderZid];
|
||||
// the expected data here was obtained from the android redphone implementation
|
||||
NSData* expectedSharedSecret = [(@[@54,@78,@99,@226,@49,@17,@8,@135,@65,@33,@247,@134,@235,@29,@164,@217,@18,@44,@241,@18,@172,@63,@197,@178,@71,@42,@253,@150,@238,@173,@218,@131]) toUint8Data];
|
||||
NSData* expectedSharedSecret = [(@[@54,@78,@99,@226,@49,@17,@8,@135,@65,@33,@247,@134,@235,@29,@164,@217,@18,@44,@241,@18,@172,@63,@197,@178,@71,@42,@253,@150,@238,@173,@218,@131]) ows_toUint8Data];
|
||||
test([sharedSecret isEqualToData:expectedSharedSecret]);
|
||||
}
|
||||
-(void) testKnownMasterSecret {
|
||||
|
@ -29,14 +29,14 @@
|
|||
|
||||
// the expected data here was obtained from the android redphone implementation
|
||||
MasterSecret* m = [MasterSecret masterSecretFromSharedSecret:sharedSecret andTotalHash:totalHash andInitiatorZid:initiatorZid andResponderZid:responderZid];
|
||||
test([[m shortAuthenticationStringData] isEqualToData:[(@[@241,@140,@246,@102]) toUint8Data]]);
|
||||
test([[m initiatorSrtpKey] isEqualToData:[(@[@202,@139,@183,@119,@244,@164,@247,@11,@232,@161,@199,@120,@229,@49,@239,@141]) toUint8Data]]);
|
||||
test([[m responderSrtpKey] isEqualToData:[(@[@35,@126,@130,@159,@156,@218,@64,@6,@59,@170,@139,@77,@250,@103,@84,@152]) toUint8Data]]);
|
||||
test([[m initiatorSrtpSalt] isEqualToData:[(@[@92,@22,@129,@225,@169,@155,@6,@157,@34,@49,@76,@15,@196,@180]) toUint8Data]]);
|
||||
test([[m responderSrtpSalt] isEqualToData:[(@[@151,@124,@181,@201,@203,@218,@192,@141,@244,@247,@249,@144,@213,@133]) toUint8Data]]);
|
||||
test([[m initiatorMacKey] isEqualToData:[(@[@215,@167,@226,@196,@14,@124,@137,@75,@48,@110,@159,@47,@243,@238,@171,@213,@103,@181,@70,@206]) toUint8Data]]);
|
||||
test([[m responderMacKey] isEqualToData:[(@[@215,@225,@180,@37,@18,@248,@122,@2,@24,@12,@149,@241,@8,@193,@103,@102,@117,@50,@27,@138]) toUint8Data]]);
|
||||
test([[m initiatorZrtpKey] isEqualToData:[(@[@182,@239,@29,@23,@42,@7,@231,@48,@45,@244,@177,@84,@77,@62,@56,@48]) toUint8Data]]);
|
||||
test([[m responderZrtpKey] isEqualToData:[(@[@59,@57,@33,@50,@121,@161,@218,@19,@255,@246,@98,@228,@68,@142,@50,@175]) toUint8Data]]);
|
||||
test([[m shortAuthenticationStringData] isEqualToData:[(@[@241,@140,@246,@102]) ows_toUint8Data]]);
|
||||
test([[m initiatorSrtpKey] isEqualToData:[(@[@202,@139,@183,@119,@244,@164,@247,@11,@232,@161,@199,@120,@229,@49,@239,@141]) ows_toUint8Data]]);
|
||||
test([[m responderSrtpKey] isEqualToData:[(@[@35,@126,@130,@159,@156,@218,@64,@6,@59,@170,@139,@77,@250,@103,@84,@152]) ows_toUint8Data]]);
|
||||
test([[m initiatorSrtpSalt] isEqualToData:[(@[@92,@22,@129,@225,@169,@155,@6,@157,@34,@49,@76,@15,@196,@180]) ows_toUint8Data]]);
|
||||
test([[m responderSrtpSalt] isEqualToData:[(@[@151,@124,@181,@201,@203,@218,@192,@141,@244,@247,@249,@144,@213,@133]) ows_toUint8Data]]);
|
||||
test([[m initiatorMacKey] isEqualToData:[(@[@215,@167,@226,@196,@14,@124,@137,@75,@48,@110,@159,@47,@243,@238,@171,@213,@103,@181,@70,@206]) ows_toUint8Data]]);
|
||||
test([[m responderMacKey] isEqualToData:[(@[@215,@225,@180,@37,@18,@248,@122,@2,@24,@12,@149,@241,@8,@193,@103,@102,@117,@50,@27,@138]) ows_toUint8Data]]);
|
||||
test([[m initiatorZrtpKey] isEqualToData:[(@[@182,@239,@29,@23,@42,@7,@231,@48,@45,@244,@177,@84,@77,@62,@56,@48]) ows_toUint8Data]]);
|
||||
test([[m responderZrtpKey] isEqualToData:[(@[@59,@57,@33,@50,@121,@161,@218,@19,@255,@246,@98,@228,@68,@142,@50,@175]) ows_toUint8Data]]);
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
@implementation ShortAuthenticationStringGeneratorTest
|
||||
-(void) testSAS {
|
||||
test([[ShortAuthenticationStringGenerator generateFromData:[(@[@0,@0]) toUint8Data]] isEqualToString:@"aardvark adroitness"]);
|
||||
test([[ShortAuthenticationStringGenerator generateFromData:[(@[@0xFF,@0xFF]) toUint8Data]] isEqualToString:@"Zulu Yucatan"]);
|
||||
test([[ShortAuthenticationStringGenerator generateFromData:[(@[@0,@0]) ows_toUint8Data]] isEqualToString:@"aardvark adroitness"]);
|
||||
test([[ShortAuthenticationStringGenerator generateFromData:[(@[@0xFF,@0xFF]) ows_toUint8Data]] isEqualToString:@"Zulu Yucatan"]);
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
__block NSData* received = nil;
|
||||
__block bool senderReceivedData = false;
|
||||
NSData* r1 = [@[@2,@3,@5] toUint8Data];
|
||||
NSData* r2 = [@[@7,@11,@13] toUint8Data];
|
||||
NSData* r3 = [@[@17,@19,@23] toUint8Data];
|
||||
NSData* r1 = [@[@2,@3,@5] ows_toUint8Data];
|
||||
NSData* r2 = [@[@7,@11,@13] ows_toUint8Data];
|
||||
NSData* r3 = [@[@17,@19,@23] ows_toUint8Data];
|
||||
|
||||
in_port_t port1 = (in_port_t)(arc4random_uniform(40000) + 10000);
|
||||
in_port_t port2 = port1 + (in_port_t)1;
|
||||
|
@ -68,9 +68,9 @@
|
|||
|
||||
__block NSData* received = nil;
|
||||
__block bool senderReceivedData = false;
|
||||
NSData* r1 = [@[@2,@3,@5] toUint8Data];
|
||||
NSData* r2 = [@[@7,@11,@13] toUint8Data];
|
||||
NSData* r3 = [@[@17,@19,@23] toUint8Data];
|
||||
NSData* r1 = [@[@2,@3,@5] ows_toUint8Data];
|
||||
NSData* r2 = [@[@7,@11,@13] ows_toUint8Data];
|
||||
NSData* r3 = [@[@17,@19,@23] ows_toUint8Data];
|
||||
|
||||
in_port_t unusedPort = (in_port_t)(arc4random_uniform(40000) + 10000);
|
||||
|
||||
|
|
|
@ -6,14 +6,14 @@
|
|||
@implementation ConversionsTest
|
||||
|
||||
-(void) testDataWithBigEndianBytesOfUInt16 {
|
||||
test([[NSData dataWithBigEndianBytesOfUInt16:0x1234u] isEqualToData:[(@[@0x12, @0x34]) toUint8Data]]);
|
||||
test([[NSData dataWithBigEndianBytesOfUInt16:0x1234u] isEqualToData:[(@[@0x12, @0x34]) ows_toUint8Data]]);
|
||||
}
|
||||
-(void) testDataWithBigEndianBytesOfUInt32 {
|
||||
test([[NSData dataWithBigEndianBytesOfUInt32:0x12345678u] isEqualToData:[(@[@0x12, @0x34, @0x56, @0x78]) toUint8Data]]);
|
||||
test([[NSData dataWithBigEndianBytesOfUInt32:0x12345678u] isEqualToData:[(@[@0x12, @0x34, @0x56, @0x78]) ows_toUint8Data]]);
|
||||
}
|
||||
|
||||
-(void) testBigEndianUInt16At {
|
||||
NSData* d = [@[@0, @1, @2, @0xFF, @3, @4] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @0xFF, @3, @4] ows_toUint8Data];
|
||||
test(0x1 == [d bigEndianUInt16At:0]);
|
||||
test(0x102 == [d bigEndianUInt16At:1]);
|
||||
test(0x2FF == [d bigEndianUInt16At:2]);
|
||||
|
@ -22,7 +22,7 @@
|
|||
testThrows([d bigEndianUInt16At:5]);
|
||||
}
|
||||
-(void) testBigEndianUInt32At {
|
||||
NSData* d = [@[@0, @1, @2, @0xFF, @3, @4] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @0xFF, @3, @4] ows_toUint8Data];
|
||||
test(0x000102FFu == [d bigEndianUInt32At:0]);
|
||||
test(0x0102FF03u == [d bigEndianUInt32At:1]);
|
||||
test(0x02FF0304u == [d bigEndianUInt32At:2]);
|
||||
|
|
|
@ -23,37 +23,37 @@
|
|||
}
|
||||
|
||||
-(void) testArrayToUint8Data {
|
||||
test([[(@[]) toUint8Data] length] == 0);
|
||||
test([[(@[]) ows_toUint8Data] length] == 0);
|
||||
|
||||
NSData* d = [@[@0, @1] toUint8Data];
|
||||
NSData* d = [@[@0, @1] ows_toUint8Data];
|
||||
test(d.length == 2);
|
||||
test(((uint8_t*)[d bytes])[0] == 0);
|
||||
test(((uint8_t*)[d bytes])[1] == 1);
|
||||
}
|
||||
-(void) testArrayConcatDatas {
|
||||
NSData* d1 = [@[@0, @1] toUint8Data];
|
||||
NSData* d2 = [@[@3, @4] toUint8Data];
|
||||
NSData* d3 = [@[@6, @7] toUint8Data];
|
||||
test([[@[] concatDatas] isEqualToData:[(@[]) toUint8Data]]);
|
||||
test([[@[d1] concatDatas] isEqualToData:d1]);
|
||||
test([[(@[d1, d2, d3]) concatDatas] isEqualToData:[(@[@0, @1, @3, @4, @6, @7]) toUint8Data]]);
|
||||
NSData* d1 = [@[@0, @1] ows_toUint8Data];
|
||||
NSData* d2 = [@[@3, @4] ows_toUint8Data];
|
||||
NSData* d3 = [@[@6, @7] ows_toUint8Data];
|
||||
test([[@[] ows_concatDatas] isEqualToData:[(@[]) ows_toUint8Data]]);
|
||||
test([[@[d1] ows_concatDatas] isEqualToData:d1]);
|
||||
test([[(@[d1, d2, d3]) ows_concatDatas] isEqualToData:[(@[@0, @1, @3, @4, @6, @7]) ows_toUint8Data]]);
|
||||
}
|
||||
|
||||
-(void) testDatadDecodedAsUtf8 {
|
||||
testThrows([[(@[@0xC3, @0x28]) toUint8Data] decodedAsUtf8]);
|
||||
testThrows([[(@[@0xC3, @0x28]) ows_toUint8Data] decodedAsUtf8]);
|
||||
|
||||
NSString* ab = [[(@[@97, @98]) toUint8Data] decodedAsUtf8];
|
||||
NSString* ab0 = [[(@[@97, @98, @0]) toUint8Data] decodedAsUtf8];
|
||||
NSString* ab = [[(@[@97, @98]) ows_toUint8Data] decodedAsUtf8];
|
||||
NSString* ab0 = [[(@[@97, @98, @0]) ows_toUint8Data] decodedAsUtf8];
|
||||
test([ab isEqualToString:@"ab"]);
|
||||
test([ab0 isEqualToString:@"ab\0"]);
|
||||
test(![ab0 isEqualToString:ab]);
|
||||
}
|
||||
-(void) testTryFindFirstIndexOf {
|
||||
NSData* d = [@[@0, @1, @2, @3, @4, @5] toUint8Data];
|
||||
NSData* d34 = [@[@3, @4] toUint8Data];
|
||||
NSData* d67 = [@[@6, @7] toUint8Data];
|
||||
NSData* d01 = [@[@0, @1] toUint8Data];
|
||||
NSData* d02 = [@[@0, @2] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3, @4, @5] ows_toUint8Data];
|
||||
NSData* d34 = [@[@3, @4] ows_toUint8Data];
|
||||
NSData* d67 = [@[@6, @7] ows_toUint8Data];
|
||||
NSData* d01 = [@[@0, @1] ows_toUint8Data];
|
||||
NSData* d02 = [@[@0, @2] ows_toUint8Data];
|
||||
|
||||
test([[d tryFindIndexOf:[NSData data]] intValue] == 0);
|
||||
test([d tryFindIndexOf:d].intValue == 0);
|
||||
|
@ -65,23 +65,23 @@
|
|||
test([d tryFindIndexOf:d67] == nil);
|
||||
}
|
||||
-(void) testDatadDecodedAsAscii {
|
||||
testThrows([[(@[@97, @0xAA]) toUint8Data] decodedAsAscii]);
|
||||
testThrows([[(@[@97, @0xAA]) ows_toUint8Data] decodedAsAscii]);
|
||||
|
||||
NSString* ab = [[(@[@97, @98]) toUint8Data] decodedAsAscii];
|
||||
NSString* ab0 = [[(@[@97, @98, @0]) toUint8Data] decodedAsAscii];
|
||||
NSString* ab = [[(@[@97, @98]) ows_toUint8Data] decodedAsAscii];
|
||||
NSString* ab0 = [[(@[@97, @98, @0]) ows_toUint8Data] decodedAsAscii];
|
||||
test([ab isEqualToString:@"ab"]);
|
||||
test([ab0 isEqualToString:@"ab\0"]);
|
||||
test(![ab0 isEqualToString:ab]);
|
||||
}
|
||||
-(void) testDatadDecodedAsAsciiReplacingErrorsWithDots {
|
||||
test([[[(@[@97, @98]) toUint8Data] decodedAsAsciiReplacingErrorsWithDots] isEqualToString:@"ab"]);
|
||||
test([[[(@[@97, @98, @0, @127, @250]) toUint8Data] decodedAsAsciiReplacingErrorsWithDots] isEqualToString:@"ab..."]);
|
||||
test([[[(@[@97, @98]) ows_toUint8Data] decodedAsAsciiReplacingErrorsWithDots] isEqualToString:@"ab"]);
|
||||
test([[[(@[@97, @98, @0, @127, @250]) ows_toUint8Data] decodedAsAsciiReplacingErrorsWithDots] isEqualToString:@"ab..."]);
|
||||
}
|
||||
-(void) testDataSkip {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d skip:0] isEqualToData:d]);
|
||||
test([[d skip:1] isEqualToData:[(@[@1, @2, @3]) toUint8Data]]);
|
||||
test([[d skip:3] isEqualToData:[@[@3] toUint8Data]]);
|
||||
test([[d skip:1] isEqualToData:[(@[@1, @2, @3]) ows_toUint8Data]]);
|
||||
test([[d skip:3] isEqualToData:[@[@3] ows_toUint8Data]]);
|
||||
test([[d skip:4] length] == 0);
|
||||
testThrows([d skip:5]);
|
||||
|
||||
|
@ -95,10 +95,10 @@
|
|||
test([b2 uint8At:0] == 0);
|
||||
}
|
||||
-(void) testDataTake {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d take:0] length] == 0);
|
||||
test([[d take:1] isEqualToData:[(@[@0]) toUint8Data]]);
|
||||
test([[d take:3] isEqualToData:[(@[@0, @1, @2]) toUint8Data]]);
|
||||
test([[d take:1] isEqualToData:[(@[@0]) ows_toUint8Data]]);
|
||||
test([[d take:3] isEqualToData:[(@[@0, @1, @2]) ows_toUint8Data]]);
|
||||
test([[d take:4] isEqualToData:d]);
|
||||
testThrows([d take:5]);
|
||||
|
||||
|
@ -112,10 +112,10 @@
|
|||
test([b2 uint8At:0] == 0);
|
||||
}
|
||||
-(void) testDataSkipLast {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d skipLast:0] isEqualToData:d]);
|
||||
test([[d skipLast:1] isEqualToData:[(@[@0, @1, @2]) toUint8Data]]);
|
||||
test([[d skipLast:3] isEqualToData:[@[@0] toUint8Data]]);
|
||||
test([[d skipLast:1] isEqualToData:[(@[@0, @1, @2]) ows_toUint8Data]]);
|
||||
test([[d skipLast:3] isEqualToData:[@[@0] ows_toUint8Data]]);
|
||||
test([[d skipLast:4] length] == 0);
|
||||
testThrows([d skipLast:5]);
|
||||
|
||||
|
@ -129,10 +129,10 @@
|
|||
test([b2 uint8At:0] == 0);
|
||||
}
|
||||
-(void) testDataTakeLast {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d takeLast:0] length] == 0);
|
||||
test([[d takeLast:1] isEqualToData:[(@[@3]) toUint8Data]]);
|
||||
test([[d takeLast:3] isEqualToData:[(@[@1, @2, @3]) toUint8Data]]);
|
||||
test([[d takeLast:1] isEqualToData:[(@[@3]) ows_toUint8Data]]);
|
||||
test([[d takeLast:3] isEqualToData:[(@[@1, @2, @3]) ows_toUint8Data]]);
|
||||
test([[d takeLast:4] isEqualToData:d]);
|
||||
testThrows([d takeLast:5]);
|
||||
|
||||
|
@ -180,40 +180,40 @@
|
|||
testThrows([d subdataVolatileWithRange:NSMakeRange(1, NSUIntegerMax)]);
|
||||
}
|
||||
-(void) testDataSkipVolatile {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d skipVolatile:0] isEqualToData:d]);
|
||||
test([[d skipVolatile:1] isEqualToData:[(@[@1, @2, @3]) toUint8Data]]);
|
||||
test([[d skipVolatile:3] isEqualToData:[@[@3] toUint8Data]]);
|
||||
test([[d skipVolatile:1] isEqualToData:[(@[@1, @2, @3]) ows_toUint8Data]]);
|
||||
test([[d skipVolatile:3] isEqualToData:[@[@3] ows_toUint8Data]]);
|
||||
test([[d skipVolatile:4] length] == 0);
|
||||
testThrows([d skipVolatile:5]);
|
||||
}
|
||||
-(void) testDataTakeVolatile {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d takeVolatile:0] length] == 0);
|
||||
test([[d takeVolatile:1] isEqualToData:[(@[@0]) toUint8Data]]);
|
||||
test([[d takeVolatile:3] isEqualToData:[(@[@0, @1, @2]) toUint8Data]]);
|
||||
test([[d takeVolatile:1] isEqualToData:[(@[@0]) ows_toUint8Data]]);
|
||||
test([[d takeVolatile:3] isEqualToData:[(@[@0, @1, @2]) ows_toUint8Data]]);
|
||||
test([[d takeVolatile:4] isEqualToData:d]);
|
||||
testThrows([d takeVolatile:5]);
|
||||
}
|
||||
-(void) testDataSkipLastVolatile {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d skipLastVolatile:0] isEqualToData:d]);
|
||||
test([[d skipLastVolatile:1] isEqualToData:[(@[@0, @1, @2]) toUint8Data]]);
|
||||
test([[d skipLastVolatile:3] isEqualToData:[@[@0] toUint8Data]]);
|
||||
test([[d skipLastVolatile:1] isEqualToData:[(@[@0, @1, @2]) ows_toUint8Data]]);
|
||||
test([[d skipLastVolatile:3] isEqualToData:[@[@0] ows_toUint8Data]]);
|
||||
test([[d skipLastVolatile:4] length] == 0);
|
||||
testThrows([d skipLastVolatile:5]);
|
||||
}
|
||||
-(void) testDataTakeLastVolatile {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([[d takeLastVolatile:0] length] == 0);
|
||||
test([[d takeLastVolatile:1] isEqualToData:[(@[@3]) toUint8Data]]);
|
||||
test([[d takeLastVolatile:3] isEqualToData:[(@[@1, @2, @3]) toUint8Data]]);
|
||||
test([[d takeLastVolatile:1] isEqualToData:[(@[@3]) ows_toUint8Data]]);
|
||||
test([[d takeLastVolatile:3] isEqualToData:[(@[@1, @2, @3]) ows_toUint8Data]]);
|
||||
test([[d takeLastVolatile:4] isEqualToData:d]);
|
||||
testThrows([d takeLastVolatile:5]);
|
||||
}
|
||||
|
||||
-(void) testDataUint8At {
|
||||
NSData* d = [@[@0, @1, @2, @3] toUint8Data];
|
||||
NSData* d = [@[@0, @1, @2, @3] ows_toUint8Data];
|
||||
test([d uint8At:0] == 0);
|
||||
test([d uint8At:1] == 1);
|
||||
test([d uint8At:2] == 2);
|
||||
|
@ -227,26 +227,26 @@
|
|||
[d setUint8At:2 to:13];
|
||||
[d setUint8At:3 to:14];
|
||||
testThrows([d setUint8At:4 to:15]);
|
||||
test([d isEqualToData:[(@[@11, @12, @13, @14]) toUint8Data]]);
|
||||
test([d isEqualToData:[(@[@11, @12, @13, @14]) ows_toUint8Data]]);
|
||||
}
|
||||
-(void) testMutableDataReplaceBytesStartingAt {
|
||||
NSMutableData* d = [NSMutableData dataWithLength:6];
|
||||
NSData* d2 = [@[@1, @2, @3] toUint8Data];
|
||||
NSData* d2 = [@[@1, @2, @3] ows_toUint8Data];
|
||||
testThrows([d replaceBytesStartingAt:0 withData:nil]);
|
||||
testThrows([d replaceBytesStartingAt:4 withData:d2]);
|
||||
|
||||
[d replaceBytesStartingAt:0 withData:d2];
|
||||
test([d isEqualToData:[(@[@1, @2, @3, @0, @0, @0]) toUint8Data]]);
|
||||
test([d isEqualToData:[(@[@1, @2, @3, @0, @0, @0]) ows_toUint8Data]]);
|
||||
[d replaceBytesStartingAt:2 withData:d2];
|
||||
test([d isEqualToData:[(@[@1, @2, @1, @2, @3, @0]) toUint8Data]]);
|
||||
test([d isEqualToData:[(@[@1, @2, @1, @2, @3, @0]) ows_toUint8Data]]);
|
||||
[d replaceBytesStartingAt:3 withData:d2];
|
||||
test([d isEqualToData:[(@[@1, @2, @1, @1, @2, @3]) toUint8Data]]);
|
||||
test([d isEqualToData:[(@[@1, @2, @1, @1, @2, @3]) ows_toUint8Data]]);
|
||||
}
|
||||
-(void) testStringEncodedAsUtf8 {
|
||||
test([@"ab".encodedAsUtf8 isEqualToData:[(@[@97, @98]) toUint8Data]]);
|
||||
test([@"ab".encodedAsUtf8 isEqualToData:[(@[@97, @98]) ows_toUint8Data]]);
|
||||
}
|
||||
-(void) testStringEncodedAsAscii {
|
||||
test([@"ab".encodedAsAscii isEqualToData:[(@[@97, @98]) toUint8Data]]);
|
||||
test([@"ab".encodedAsAscii isEqualToData:[(@[@97, @98]) ows_toUint8Data]]);
|
||||
testThrows(@"√".encodedAsAscii);
|
||||
}
|
||||
-(void) testBase64EncodeKnown {
|
||||
|
|
Loading…
Reference in a new issue