Use dot syntax

This commit is contained in:
Jonathan Schleifer 2019-03-14 23:02:31 +01:00
parent 056f31ddad
commit bdd641b92d
No known key found for this signature in database
GPG key ID: 79D21189A2D4708D
3 changed files with 37 additions and 35 deletions

View file

@ -148,6 +148,6 @@
_host, _port, [_socket class], error]; _host, _port, [_socket class], error];
} }
return [super description]; return super.description;
} }
@end @end

View file

@ -71,13 +71,13 @@ static SSL_CTX *ctx;
static of_mutex_t *ssl_mutexes; static of_mutex_t *ssl_mutexes;
static unsigned long static unsigned long
get_thread_id(void) threadID(void)
{ {
return (unsigned long)(uintptr_t)[OFThread currentThread]; return (unsigned long)(uintptr_t)[OFThread currentThread];
} }
static void static void
locking_callback(int mode, int n, const char *file, int line) lockingCallback(int mode, int n, const char *file, int line)
{ {
/* /*
* This function must handle up to CRYPTO_num_locks() mutexes. * This function must handle up to CRYPTO_num_locks() mutexes.
@ -124,7 +124,7 @@ locking_callback(int mode, int n, const char *file, int line)
_port = port; _port = port;
_delegate = [delegate retain]; _delegate = [delegate retain];
[_socket setDelegate: self]; _socket.delegate = self;
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -135,8 +135,8 @@ locking_callback(int mode, int n, const char *file, int line)
- (void)dealloc - (void)dealloc
{ {
if ([_socket delegate] == self) if (_socket.delegate == self)
[_socket setDelegate: _delegate]; _socket.delegate = _delegate;
[_socket release]; [_socket release];
[_delegate release]; [_delegate release];
@ -158,7 +158,7 @@ locking_callback(int mode, int n, const char *file, int line)
} }
} }
[_socket setDelegate: _delegate]; _socket.delegate = _delegate;
[_delegate socket: sock [_delegate socket: sock
didConnectToHost: host didConnectToHost: host
port: port port: port
@ -187,9 +187,9 @@ locking_callback(int mode, int n, const char *file, int line)
if (self != [SSLSocket class]) if (self != [SSLSocket class])
return; return;
CRYPTO_set_id_callback(&get_thread_id); CRYPTO_set_id_callback(&threadID);
/* OpenSSL >= 1.1 defines the line above to a nop */ /* OpenSSL >= 1.1 defines the line above to a nop */
(void)get_thread_id; (void)threadID;
/* Generate number of mutexes needed */ /* Generate number of mutexes needed */
m = CRYPTO_num_locks(); m = CRYPTO_num_locks();
@ -197,9 +197,9 @@ locking_callback(int mode, int n, const char *file, int line)
for (m--; m >= 0; m--) for (m--; m >= 0; m--)
of_mutex_new(&ssl_mutexes[m]); of_mutex_new(&ssl_mutexes[m]);
CRYPTO_set_locking_callback(&locking_callback); CRYPTO_set_locking_callback(&lockingCallback);
/* OpenSSL >= 1.1 defines the line above to a nop */ /* OpenSSL >= 1.1 defines the line above to a nop */
(void)locking_callback; (void)lockingCallback;
SSL_library_init(); SSL_library_init();
@ -272,7 +272,7 @@ locking_callback(int mode, int n, const char *file, int line)
SSLError: error]; SSLError: error];
} }
if (SSL_set_tlsext_host_name(_SSL, [host UTF8String]) != 1) { if (SSL_set_tlsext_host_name(_SSL, host.UTF8String) != 1) {
unsigned long error = ERR_get_error(); unsigned long error = ERR_get_error();
[self close]; [self close];
@ -290,7 +290,7 @@ locking_callback(int mode, int n, const char *file, int line)
X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
if (X509_VERIFY_PARAM_set1_host(param, if (X509_VERIFY_PARAM_set1_host(param,
[host UTF8String], [host UTF8StringLength]) != 1) { host.UTF8String, host.UTF8StringLength) != 1) {
unsigned long error = ERR_get_error(); unsigned long error = ERR_get_error();
[self close]; [self close];
@ -313,8 +313,7 @@ locking_callback(int mode, int n, const char *file, int line)
[_privateKeyFile cStringWithEncoding: encoding], [_privateKeyFile cStringWithEncoding: encoding],
SSL_FILETYPE_PEM)) || (_certificateFile != nil && SSL_FILETYPE_PEM)) || (_certificateFile != nil &&
!SSL_use_certificate_file(_SSL, [_certificateFile !SSL_use_certificate_file(_SSL, [_certificateFile
cStringWithEncoding: encoding], cStringWithEncoding: encoding], SSL_FILETYPE_PEM))) {
SSL_FILETYPE_PEM))) {
unsigned long error = ERR_get_error(); unsigned long error = ERR_get_error();
[super close]; [super close];
@ -500,7 +499,7 @@ locking_callback(int mode, int n, const char *file, int line)
if (_SSL != NULL && SSL_pending(_SSL) > 0) if (_SSL != NULL && SSL_pending(_SSL) > 0)
return true; return true;
return [super hasDataInReadBuffer]; return super.hasDataInReadBuffer;
} }
- (void)setCertificateFile: (OFString *)certificateFile - (void)setCertificateFile: (OFString *)certificateFile

View file

@ -73,12 +73,12 @@ OF_ASSUME_NONNULL_END
@try { @try {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFData *data = [OFData dataWithContentsOfFile: path]; OFData *data = [OFData dataWithContentsOfFile: path];
const unsigned char *dataC = [data items]; const unsigned char *dataItems = data.items;
_certificate = d2i_X509(NULL, &dataC, [data count]); _certificate = d2i_X509(NULL, &dataItems, data.count);
if (_certificate == NULL) if (_certificate == NULL)
@throw [OFInitializationFailedException @throw [OFInitializationFailedException
exceptionWithClass: [self class]]; exceptionWithClass: self.class];
[pool release]; [pool release];
} @catch (id e) { } @catch (id e) {
@ -97,7 +97,7 @@ OF_ASSUME_NONNULL_END
_certificate = X509_dup(certificate); _certificate = X509_dup(certificate);
if (_certificate == NULL) if (_certificate == NULL)
@throw [OFInitializationFailedException @throw [OFInitializationFailedException
exceptionWithClass: [self class]]; exceptionWithClass: self.class];
} @catch (id e) { } @catch (id e) {
[self release]; [self release];
@throw e; @throw e;
@ -120,14 +120,17 @@ OF_ASSUME_NONNULL_END
- (OFString *)description - (OFString *)description
{ {
OFMutableString *ret = [OFMutableString string]; OFString *issuer = [self.issuer.description
stringByReplacingOccurrencesOfString: @"\n"
withString: @"\n\t"];
[ret appendFormat: @"Issuer: %@\n\n", [self issuer]]; return [OFString stringWithFormat:
[ret appendFormat: @"Subject: %@\n\n", [self subject]]; @"<%@\n"
[ret appendFormat: @"SANs: %@", [self subjectAlternativeName]]; @"\tIssuer: %@\n"
@"\tSubject: %@\n"
[ret makeImmutable]; @"\tSANs: %@\n"
return ret; @">",
self.class, issuer, self.subject, self.subjectAlternativeName];
} }
- (OFDictionary *)issuer - (OFDictionary *)issuer
@ -317,7 +320,7 @@ OF_ASSUME_NONNULL_END
{ {
size_t serviceLength; size_t serviceLength;
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
OFDictionary *SANs = [self subjectAlternativeName]; OFDictionary *SANs = self.subjectAlternativeName;
OFList *assertedNames = [[SANs objectForKey: @"otherName"] OFList *assertedNames = [[SANs objectForKey: @"otherName"]
objectForKey: OID_SRVName]; objectForKey: OID_SRVName];
@ -325,13 +328,13 @@ OF_ASSUME_NONNULL_END
service = [service stringByPrependingString: @"_"]; service = [service stringByPrependingString: @"_"];
service = [service stringByAppendingString: @"."]; service = [service stringByAppendingString: @"."];
serviceLength = [service length]; serviceLength = service.length;
for (OFString *name in assertedNames) { for (OFString *name in assertedNames) {
if ([name hasPrefix: service]) { if ([name hasPrefix: service]) {
OFString *asserted; OFString *asserted;
asserted = [name substringWithRange: of_range( asserted = [name substringWithRange: of_range(
serviceLength, [name length] - serviceLength)]; serviceLength, name.length - serviceLength)];
if ([self X509_isAssertedDomain: asserted if ([self X509_isAssertedDomain: asserted
equalDomain: domain]) { equalDomain: domain]) {
[pool release]; [pool release];
@ -363,14 +366,14 @@ OF_ASSUME_NONNULL_END
return false; return false;
asserted = [asserted substringWithRange: asserted = [asserted substringWithRange:
of_range(2, [asserted length] - 2)]; of_range(2, asserted.length - 2)];
firstDot = [domain rangeOfString: @"."].location; firstDot = [domain rangeOfString: @"."].location;
if (firstDot == OF_NOT_FOUND) if (firstDot == OF_NOT_FOUND)
return false; return false;
domain = [domain substringWithRange: domain = [domain substringWithRange:
of_range(firstDot + 1, [domain length] - firstDot - 1)]; of_range(firstDot + 1, domain.length - firstDot - 1)];
if (![asserted caseInsensitiveCompare: domain]) if (![asserted caseInsensitiveCompare: domain])
return true; return true;
@ -479,7 +482,7 @@ OF_ASSUME_NONNULL_END
- (OFString *)description - (OFString *)description
{ {
char tmp[1024]; char tmp[1024];
OBJ_obj2txt(tmp, sizeof(tmp), OBJ_txt2obj([_string UTF8String], 1), 0); OBJ_obj2txt(tmp, sizeof(tmp), OBJ_txt2obj(_string.UTF8String, 1), 0);
return [OFString stringWithUTF8String: tmp]; return [OFString stringWithUTF8String: tmp];
} }
@ -499,7 +502,7 @@ OF_ASSUME_NONNULL_END
- (uint32_t)hash - (uint32_t)hash
{ {
return [_string hash]; return _string.hash;
} }
- copy - copy