Index: src/XMPPAuthenticator.h ================================================================== --- src/XMPPAuthenticator.h +++ src/XMPPAuthenticator.h @@ -63,21 +63,21 @@ - initWithAuthzid: (nullable OFString *)authzid authcid: (nullable OFString *)authcid password: (nullable OFString *)password OF_DESIGNATED_INITIALIZER; /** - * \brief Returns an OFDataArray containing the initial authentication message. + * \brief Returns OFData containing the initial authentication message. * * \return An OFDataAray containing the initial authentication message */ -- (OFDataArray *)initialMessage; +- (nullable OFData *)initialMessage; /** * \brief Continue authentication with the specified data. * * \param data The continuation data send by the server * \return The appropriate response if the data was a challenge, nil otherwise */ -- (nullable OFDataArray *)continueWithData: (OFDataArray *)data; +- (nullable OFData *)continueWithData: (OFData *)data; @end OF_ASSUME_NONNULL_END Index: src/XMPPAuthenticator.m ================================================================== --- src/XMPPAuthenticator.m +++ src/XMPPAuthenticator.m @@ -63,15 +63,15 @@ [_password release]; [super dealloc]; } -- (OFDataArray *)initialMessage +- (OFData *)initialMessage { return nil; } -- (OFDataArray *)continueWithData: (OFDataArray *)challenge +- (OFData *)continueWithData: (OFData *)challenge { return nil; } @end Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -893,14 +893,13 @@ - (void)XMPP_handleSASL: (OFXMLElement *)element { if ([[element name] isEqual: @"challenge"]) { OFXMLElement *responseTag; - OFDataArray *challenge = [OFDataArray - dataArrayWithBase64EncodedString: [element stringValue]]; - OFDataArray *response = [_authModule - continueWithData: challenge]; + OFData *challenge = + [OFData dataWithBase64EncodedString: [element stringValue]]; + OFData *response = [_authModule continueWithData: challenge]; responseTag = [OFXMLElement elementWithName: @"response" namespace: XMPP_NS_SASL]; if (response) { if ([response count] == 0) @@ -913,12 +912,12 @@ [self sendStanza: responseTag]; return; } if ([[element name] isEqual: @"success"]) { - [_authModule continueWithData: [OFDataArray - dataArrayWithBase64EncodedString: [element stringValue]]]; + [_authModule continueWithData: [OFData + dataWithBase64EncodedString: [element stringValue]]]; [_delegates broadcastSelector: @selector( connectionWasAuthenticated:) withObject: self]; @@ -1076,11 +1075,11 @@ } - (void)XMPP_sendAuth: (OFString *)authName { OFXMLElement *authTag; - OFDataArray *initialMessage = [_authModule initialMessage]; + OFData *initialMessage = [_authModule initialMessage]; authTag = [OFXMLElement elementWithName: @"auth" namespace: XMPP_NS_SASL]; [authTag addAttributeWithName: @"mechanism" stringValue: authName]; Index: src/XMPPDiscoEntity.m ================================================================== --- src/XMPPDiscoEntity.m +++ src/XMPPDiscoEntity.m @@ -96,11 +96,11 @@ OFEnumerator *enumerator; XMPPDiscoIdentity *identity; OFString *feature; OFMutableString *caps = [OFMutableString string]; OFSHA1Hash *hash = [OFSHA1Hash cryptoHash]; - OFDataArray *digest = [OFDataArray dataArray]; + OFData *digest; enumerator = [_identities objectEnumerator]; while ((identity = [enumerator nextObject]) != nil) [caps appendFormat: @"%@/%@//%@<", [identity category], [identity type], [identity name]]; @@ -110,12 +110,12 @@ [caps appendFormat: @"%@<", feature]; [hash updateWithBuffer: [caps UTF8String] length: [caps UTF8StringLength]]; - [digest addItems: [hash digest] - count: [OFSHA1Hash digestSize]]; + digest = [OFData dataWithItems: [hash digest] + count: [[hash class] digestSize]]; return [digest stringByBase64Encoding]; } - (void)connection: (XMPPConnection *)connection Index: src/XMPPEXTERNALAuth.m ================================================================== --- src/XMPPEXTERNALAuth.m +++ src/XMPPEXTERNALAuth.m @@ -38,16 +38,19 @@ return [[[self alloc] initWithAuthzid: authzid authcid: nil password: nil] autorelease]; } -- (OFDataArray *)initialMessage +- (OFData *)initialMessage { - OFDataArray *message = [OFDataArray dataArray]; + OFMutableData *message = [OFMutableData data]; /* authzid */ - if (_authzid) - [message addItem: _authzid]; + if (_authzid != nil) + [message addItems: [_authzid UTF8String] + count: [_authzid UTF8StringLength]]; + + [message makeImmutable]; return message; } @end Index: src/XMPPFileStorage.m ================================================================== --- src/XMPPFileStorage.m +++ src/XMPPFileStorage.m @@ -28,11 +28,11 @@ #import #import #import #import -#import +#import #import #import #import "XMPPFileStorage.h" @@ -50,12 +50,12 @@ @try { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; _file = [file copy]; @try { - _data = [[[OFDataArray dataArrayWithContentsOfFile: - file] messagePackValue] retain]; + _data = [[[OFData dataWithContentsOfFile: file] + messagePackValue] retain]; } @catch (id e) { _data = [[OFMutableDictionary alloc] init]; } [pool release]; Index: src/XMPPMulticastDelegate.h ================================================================== --- src/XMPPMulticastDelegate.h +++ src/XMPPMulticastDelegate.h @@ -22,18 +22,18 @@ #import OF_ASSUME_NONNULL_BEGIN -@class OFDataArray; +@class OFMutableData; /** * \brief A class to provide multiple delegates in a single class */ @interface XMPPMulticastDelegate: OFObject { - OFDataArray *_delegates; + OFMutableData *_delegates; } /** * \brief Adds a delegate which should receive the broadcasts. * Index: src/XMPPMulticastDelegate.m ================================================================== --- src/XMPPMulticastDelegate.m +++ src/XMPPMulticastDelegate.m @@ -23,21 +23,22 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif #import -#import +#import #import "XMPPMulticastDelegate.h" @implementation XMPPMulticastDelegate - init { self = [super init]; @try { - _delegates = [[OFDataArray alloc] initWithItemSize: sizeof(id)]; + _delegates = [[OFMutableData alloc] + initWithItemSize: sizeof(id)]; } @catch (id e) { [self release]; @throw e; } @@ -71,11 +72,12 @@ } - (bool)broadcastSelector: (SEL)selector withObject: (id)object { - OFDataArray *currentDelegates = [_delegates copy]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFMutableData *currentDelegates = [[_delegates copy] autorelease]; id *items = [currentDelegates items]; size_t i, count = [currentDelegates count]; bool handled = false; for (i = 0; i < count; i++) { @@ -88,18 +90,21 @@ [responder methodForSelector: selector]; handled |= imp(responder, selector, object); } + [pool release]; + return handled; } - (bool)broadcastSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 { - OFDataArray *currentDelegates = [_delegates copy]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFMutableData *currentDelegates = [[_delegates copy] autorelease]; id *items = [currentDelegates items]; size_t i, count = [currentDelegates count]; bool handled = false; for (i = 0; i < count; i++) { @@ -111,9 +116,11 @@ bool (*imp)(id, SEL, id, id) = (bool(*)(id, SEL, id, id)) [responder methodForSelector: selector]; handled |= imp(responder, selector, object1, object2); } + + [pool release]; return handled; } @end Index: src/XMPPPLAINAuth.m ================================================================== --- src/XMPPPLAINAuth.m +++ src/XMPPPLAINAuth.m @@ -42,17 +42,18 @@ return [[[self alloc] initWithAuthzid: authzid authcid: authcid password: password] autorelease]; } -- (OFDataArray *)initialMessage +- (OFData *)initialMessage { - OFDataArray *message = [OFDataArray dataArray]; + OFMutableData *message = [OFMutableData data]; /* authzid */ - if (_authzid) - [message addItem: _authzid]; + if (_authzid != nil) + [message addItems: [_authzid UTF8String] + count: [_authzid UTF8StringLength]]; /* separator */ [message addItem: ""]; /* authcid */ @@ -63,9 +64,11 @@ [message addItem: ""]; /* passwd */ [message addItems: [_password UTF8String] count: [_password UTF8StringLength]]; + + [message makeImmutable]; return message; } @end Index: src/XMPPSCRAMAuth.h ================================================================== --- src/XMPPSCRAMAuth.h +++ src/XMPPSCRAMAuth.h @@ -33,11 +33,11 @@ { Class _hashType; OFString *_cNonce; OFString *_GS2Header; OFString *_clientFirstMessageBare; - OFDataArray *_serverSignature; + OFData *_serverSignature; XMPPConnection *_connection; bool _plusAvailable; bool _authenticated; } Index: src/XMPPSCRAMAuth.m ================================================================== --- src/XMPPSCRAMAuth.m +++ src/XMPPSCRAMAuth.m @@ -39,17 +39,17 @@ OF_ASSUME_NONNULL_BEGIN @interface XMPPSCRAMAuth () - (OFString *)XMPP_genNonce; -- (const uint8_t *)XMPP_HMACWithKey: (OFDataArray *)key - data: (OFDataArray *)data; -- (OFDataArray *)XMPP_hiWithData: (OFDataArray *)str - salt: (OFDataArray *)salt - iterationCount: (intmax_t)i; -- (OFDataArray *)XMPP_parseServerFirstMessage: (OFDataArray *)data; -- (OFDataArray *)XMPP_parseServerFinalMessage: (OFDataArray *)data; +- (const uint8_t *)XMPP_HMACWithKey: (OFData *)key + data: (OFData *)data; +- (OFData *)XMPP_hiWithData: (OFData *)str + salt: (OFData *)salt + iterationCount: (intmax_t)i; +- (OFData *)XMPP_parseServerFirstMessage: (OFData *)data; +- (OFData *)XMPP_parseServerFinalMessage: (OFData *)data; @end OF_ASSUME_NONNULL_END @implementation XMPPSCRAMAuth @@ -156,13 +156,13 @@ _authcid = nil; [old release]; } -- (OFDataArray *)initialMessage +- (OFData *)initialMessage { - OFDataArray *ret = [OFDataArray dataArray]; + OFMutableData *ret = [OFMutableData data]; /* New authentication attempt, reset status */ [_cNonce release]; _cNonce = nil; [_GS2Header release]; @@ -169,11 +169,11 @@ _GS2Header = nil; [_serverSignature release]; _serverSignature = nil; _authenticated = false; - if (_authzid) + if (_authzid != nil) _GS2Header = [[OFString alloc] initWithFormat: @"%@,a=%@,", (_plusAvailable ? @"p=tls-unique" : @"y"), _authzid]; else @@ -190,17 +190,19 @@ count: [_GS2Header UTF8StringLength]]; [ret addItems: [_clientFirstMessageBare UTF8String] count: [_clientFirstMessageBare UTF8StringLength]]; + [ret makeImmutable]; + return ret; } -- (OFDataArray *)continueWithData: (OFDataArray *)data +- (OFData *)continueWithData: (OFData *)data { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFDataArray *ret; + OFData *ret; if (!_serverSignature) ret = [self XMPP_parseServerFirstMessage: data]; else ret = [self XMPP_parseServerFinalMessage: data]; @@ -209,17 +211,18 @@ [pool release]; return [ret autorelease]; } -- (OFDataArray *)XMPP_parseServerFirstMessage: (OFDataArray *)data +- (OFData *)XMPP_parseServerFirstMessage: (OFData *)data { size_t i; const uint8_t *clientKey, *serverKey, *clientSignature; intmax_t iterCount = 0; id hash; - OFDataArray *ret, *authMessage, *tmpArray, *salt = nil, *saltedPassword; + OFMutableData *ret, *authMessage, *tmpArray; + OFData *salt = nil, *saltedPassword; OFString *tmpString, *sNonce = nil; OFEnumerator *enumerator; OFString *comp; enum { GOT_SNONCE = 0x01, @@ -226,12 +229,12 @@ GOT_SALT = 0x02, GOT_ITERCOUNT = 0x04 } got = 0; hash = [[[_hashType alloc] init] autorelease]; - ret = [OFDataArray dataArray]; - authMessage = [OFDataArray dataArray]; + ret = [OFMutableData data]; + authMessage = [OFMutableData data]; OFString *chal = [OFString stringWithUTF8String: [data items] length: [data count] * [data itemSize]]; @@ -249,12 +252,11 @@ @"nonce"]; sNonce = entry; got |= GOT_SNONCE; } else if ([comp hasPrefix: @"s="]) { - salt = [OFDataArray - dataArrayWithBase64EncodedString: entry]; + salt = [OFData dataWithBase64EncodedString: entry]; got |= GOT_SALT; } else if ([comp hasPrefix: @"i="]) { iterCount = [entry decimalValue]; got |= GOT_ITERCOUNT; } @@ -262,16 +264,15 @@ if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT)) @throw [OFInvalidServerReplyException exception]; // Add c= - tmpArray = [OFDataArray dataArray]; + tmpArray = [OFMutableData data]; [tmpArray addItems: [_GS2Header UTF8String] count: [_GS2Header UTF8StringLength]]; if (_plusAvailable && [_connection encrypted]) { - OFDataArray *channelBinding = - [((SSLSocket *)[_connection socket]) + OFData *channelBinding = [((SSLSocket *)[_connection socket]) channelBindingDataWithType: @"tls-unique"]; [tmpArray addItems: [channelBinding items] count: [channelBinding count]]; } tmpString = [tmpArray stringByBase64Encoding]; @@ -289,14 +290,12 @@ /* * IETF RFC 5802: * SaltedPassword := Hi(Normalize(password), salt, i) */ - tmpArray = [OFDataArray dataArray]; - [tmpArray addItems: [_password UTF8String] - count: [_password UTF8StringLength]]; - + tmpArray = [OFMutableData dataWithItems: [_password UTF8String] + count: [_password UTF8StringLength]]; saltedPassword = [self XMPP_hiWithData: tmpArray salt: salt iterationCount: iterCount]; /* @@ -316,25 +315,22 @@ /* * IETF RFC 5802: * ClientKey := HMAC(SaltedPassword, "Client Key") */ - tmpArray = [OFDataArray dataArray]; - [tmpArray addItems: "Client Key" - count: 10]; clientKey = [self XMPP_HMACWithKey: saltedPassword - data: tmpArray]; + data: [OFData dataWithItems: @"Client key" + count: 10]]; /* * IETF RFC 5802: * StoredKey := H(ClientKey) */ [hash updateWithBuffer: (void *)clientKey length: [_hashType digestSize]]; - tmpArray = [OFDataArray dataArray]; - [tmpArray addItems: [hash digest] - count: [_hashType digestSize]]; + tmpArray = [OFMutableData dataWithItems: [hash digest] + count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientSignature := HMAC(StoredKey, AuthMessage) */ @@ -343,33 +339,33 @@ /* * IETF RFC 5802: * ServerKey := HMAC(SaltedPassword, "Server Key") */ - tmpArray = [OFDataArray dataArray]; - [tmpArray addItems: "Server Key" - count: 10]; + tmpArray = [OFMutableData dataWithItems: "Server Key" + count: 10]; serverKey = [self XMPP_HMACWithKey: saltedPassword data: tmpArray]; /* * IETF RFC 5802: * ServerSignature := HMAC(ServerKey, AuthMessage) */ - tmpArray = [OFDataArray dataArray]; - [tmpArray addItems: serverKey - count: [_hashType digestSize]]; - _serverSignature = [[OFDataArray alloc] init]; - [_serverSignature addItems: [self XMPP_HMACWithKey: tmpArray - data: authMessage] - count: [_hashType digestSize]]; + tmpArray = [OFMutableData dataWithItems: serverKey + count: [_hashType digestSize]]; + + [_serverSignature release]; + _serverSignature = [[OFMutableData alloc] + initWithItems: [self XMPP_HMACWithKey: tmpArray + data: authMessage] + count: [_hashType digestSize]]; /* * IETF RFC 5802: * ClientProof := ClientKey XOR ClientSignature */ - tmpArray = [OFDataArray dataArray]; + tmpArray = [OFMutableData data]; for (i = 0; i < [_hashType digestSize]; i++) { uint8_t c = clientKey[i] ^ clientSignature[i]; [tmpArray addItem: &c]; } @@ -382,11 +378,11 @@ count: [tmpString UTF8StringLength]]; return ret; } -- (OFDataArray *)XMPP_parseServerFinalMessage: (OFDataArray *)data +- (OFData *)XMPP_parseServerFinalMessage: (OFData *)data { OFString *mess, *value; /* * server-final-message already received, @@ -394,12 +390,11 @@ */ if (_authenticated) return nil; mess = [OFString stringWithUTF8String: [data items] - length: [data count] * - [data itemSize]]; + length: [data count] * [data itemSize]]; value = [mess substringWithRange: of_range(2, [mess length] - 2)]; if ([mess hasPrefix: @"v="]) { if (![value isEqual: [_serverSignature stringByBase64Encoding]]) @throw [XMPPAuthFailedException @@ -433,15 +428,15 @@ return [OFString stringWithCString: (char *)buf encoding: OF_STRING_ENCODING_ASCII length: 64]; } -- (const uint8_t *)XMPP_HMACWithKey: (OFDataArray *)key - data: (OFDataArray *)data +- (const uint8_t *)XMPP_HMACWithKey: (OFData *)key + data: (OFData *)data { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFDataArray *k = [OFDataArray dataArray]; + OFMutableData *k = [OFMutableData data]; size_t i, kSize, blockSize = [_hashType blockSize]; uint8_t *kI = NULL, *kO = NULL; id hashI, hashO; if ([key itemSize] * [key count] > blockSize) { @@ -488,20 +483,20 @@ [pool release]; return [[hashO autorelease] digest]; } -- (OFDataArray *)XMPP_hiWithData: (OFDataArray *)str - salt: (OFDataArray *)salt - iterationCount: (intmax_t)i +- (OFData *)XMPP_hiWithData: (OFData *)str + salt: (OFData *)salt + iterationCount: (intmax_t)i { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t digestSize = [_hashType digestSize]; uint8_t *result = NULL; const uint8_t *u, *uOld; intmax_t j, k; - OFDataArray *salty, *tmp, *ret; + OFMutableData *salty, *tmp, *ret; result = [self allocMemoryWithSize: digestSize]; @try { memset(result, 0, digestSize); @@ -515,11 +510,11 @@ for (j = 0; j < digestSize; j++) result[j] ^= uOld[j]; for (j = 0; j < i - 1; j++) { - tmp = [[OFDataArray alloc] init]; + tmp = [[OFMutableData alloc] init]; [tmp addItems: uOld count: digestSize]; [pool releaseObjects]; // releases uOld and previous tmp [tmp autorelease]; @@ -531,13 +526,12 @@ result[k] ^= u[k]; uOld = u; } - ret = [OFDataArray dataArray]; - [ret addItems: result - count: digestSize]; + ret = [OFMutableData dataWithItems: result + count: digestSize]; } @finally { [self freeMemory: result]; } [ret retain]; Index: src/XMPPStanza.m ================================================================== --- src/XMPPStanza.m +++ src/XMPPStanza.m @@ -109,11 +109,12 @@ - initWithName: (OFString *)name type: (OFString *)type ID: (OFString *)ID { self = [super initWithName: name - namespace: XMPP_NS_CLIENT]; + namespace: XMPP_NS_CLIENT + stringValue: nil]; @try { if (![name isEqual: @"iq"] && ![name isEqual: @"message"] && ![name isEqual: @"presence"]) @throw [OFInvalidArgumentException exception];