Modify -descriptionForErrorCode:

The method is now nonnull and returns "Unknown" for out of range error codes
This commit is contained in:
Michael
2018-07-12 19:15:19 -04:00
parent ac55556550
commit 6d7c07ecd4
4 changed files with 15 additions and 9 deletions
+3 -1
View File
@@ -32,7 +32,8 @@ typedef NS_ENUM(NSUInteger, RCMCipherSuiteCollection) {
+ (BOOL)isTLSError:(NSError *)error;
+ (nullable NSString *)descriptionForError:(NSError *)error;
+ (nullable NSString *)descriptionForErrorCode:(NSInteger)errorCode;
/* -descriptionForErrorCode: returns "Unknown" for out of range error codes */
+ (NSString *)descriptionForErrorCode:(NSInteger)errorCode;
+ (nullable NSString *)descriptionForBadCertificateError:(NSError *)error;
+ (nullable NSString *)descriptionForBadCertificateErrorCode:(NSInteger)errorCode;
+ (BOOL)isBadCertificateError:(NSError *)error;
@@ -45,3 +46,4 @@ typedef NS_ENUM(NSUInteger, RCMCipherSuiteCollection) {
@end
NS_ASSUME_NONNULL_END
+4 -2
View File
@@ -58,6 +58,8 @@
NS_ASSUME_NONNULL_BEGIN
static OSStatus errSSLUnknownError = -9999;
static const int kAEADMACValue = 7;
static const int kTLS13KeyExchangeValue = 31;
@@ -561,10 +563,10 @@ static const char * _Nonnull kMacNames[] = {
return [self descriptionForErrorCode:error.code];
}
+ (nullable NSString *)descriptionForErrorCode:(NSInteger)errorCode
+ (NSString *)descriptionForErrorCode:(NSInteger)errorCode
{
if (errorCode > (-9800) || errorCode < (-9865)) {
return nil;
errorCode = errSSLUnknownError;
}
/* Request the heading for the formatted error message. */
@@ -208,19 +208,18 @@ extension ConnectionError
self.init(tlsError: error.code)
}
init? (tlsError errorCode: Int)
/// init(tlsError:) returns .unableToSecure("Unknown") for out of range error codes
init (tlsError errorCode: Int)
{
if let certError = RCMSecureTransport.description(forBadCertificateErrorCode: errorCode) {
self = .badCertificate(failureReason: certError)
return
} else if let tlsError = RCMSecureTransport.description(forErrorCode: errorCode) {
self = .unableToSecure(failureReason: tlsError)
return
}
return nil
let tlsError = RCMSecureTransport.description(forErrorCode: errorCode)
self = .unableToSecure(failureReason: tlsError)
}
}
@@ -103,3 +103,6 @@
"-9863" = "Certificate required"; // errSSLCertificateRequired
"-9864" = "Unknown PSK identity"; // errSSLUnknownPSKIdentity
"-9865" = "Unknown or unrecognized name"; // errSSLUnrecognizedName
/* errSSLUnknownError is defined by our own library. Not Secure Transport. */
"-9999" = "Unknown"; // errSSLUnknownError