Convert integer result to error reason

This commit is contained in:
Sergey Abramchuk
2017-09-06 22:57:35 +03:00
parent 1d10acb6cf
commit aa6eb81f97
2 changed files with 43 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
//
// NSError+Message.h
// OpenVPN Adapter
//
// Created by Sergey Abramchuk on 06.09.17.
//
//
#import <Foundation/Foundation.h>
@interface NSError (Message)
+ (NSString *)reasonFromResult:(NSInteger)result;
@end

View File

@@ -0,0 +1,28 @@
//
// NSError+Message.m
// OpenVPN Adapter
//
// Created by Sergey Abramchuk on 06.09.17.
//
//
#import <mbedtls/error.h>
#import "NSError+Message.h"
@implementation NSError (Message)
+ (NSString *)reasonFromResult:(NSInteger)result {
size_t length = 1024;
char *buffer = malloc(length);
mbedtls_strerror(result, buffer, length);
NSString *reason = [NSString stringWithUTF8String:buffer];
free(buffer);
return reason;
}
@end