-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMBEDTLSException.m
62 lines (42 loc) · 1.02 KB
/
MBEDTLSException.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#import <ObjFW/ObjFW.h>
#import "MBEDTLSException.h"
#include <mbedtls/error.h>
@interface MBEDTLSException()
@property (assign, readwrite)int errNo;
@property (retain, readwrite)id sourceObject;
@end
@implementation MBEDTLSException
- (instancetype)init
{
self = [super init];
self.sourceObject = nil;
self.errNo = 0;
return self;
}
- (void)dealloc
{
[_sourceObject release];
[super dealloc];
}
- (instancetype)initWithObject:(id)object errorNumber:(int)errNo
{
self = [self init];
self.sourceObject = object;
self.errNo = errNo;
return self;
}
+ (instancetype)exceptionWithObject:(id)object errorNumber:(int)errNo
{
return [[[self alloc] initWithObject:object errorNumber:errNo] autorelease];
}
- (OFString *)errorDescription
{
char buffer[4096] = {0};
mbedtls_strerror( _errNo, buffer, sizeof(buffer) );
return [OFString stringWithUTF8String:buffer];
}
- (OFString *)description
{
return [OFString stringWithFormat:@"An exception occurred in object %@: %@", self.sourceObject, [self errorDescription]];
}
@end