mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Refactor generation of mbedTLS errors
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
|
||||
#import "NSError+OpenVPNError.h"
|
||||
|
||||
#import <mbedtls/error.h>
|
||||
|
||||
#import "OpenVPNError.h"
|
||||
|
||||
@implementation NSError (OpenVPNAdapterErrorGeneration)
|
||||
@@ -179,3 +181,23 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSError (OpenVPNMbedTLSErrorGeneration)
|
||||
|
||||
+ (NSError *)ovpn_errorObjectForMbedTLSError:(NSInteger)errorCode description:(NSString *)description {
|
||||
size_t length = 1024;
|
||||
char *buffer = malloc(length);
|
||||
|
||||
mbedtls_strerror(errorCode, buffer, length);
|
||||
|
||||
NSString *reason = [NSString stringWithUTF8String:buffer];
|
||||
|
||||
free(buffer);
|
||||
|
||||
return [NSError errorWithDomain:OpenVPNIdentityErrorDomain code:errorCode userInfo:@{
|
||||
NSLocalizedDescriptionKey: description,
|
||||
NSLocalizedFailureReasonErrorKey: reason
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user