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
63
64
65
66
|
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
+
+
+
+
+
+
+
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
+
+
|
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
@implementation OFASN1ObjectIdentifier
@synthesize subidentifiers = _subidentifiers;
+ (instancetype)objectIdentifierWithSubidentifiers:
(OFArray OF_GENERIC(OFNumber *) *)subidentifiers
{
return [[[self alloc]
initWithSubidentifiers: subidentifiers] autorelease];
}
- (instancetype)init
- (instancetype)initWithSubidentifiers:
(OFArray OF_GENERIC(OFNumber *) *)subidentifiers
{
self = [super init];
OF_INVALID_INIT_METHOD
@try {
if ([subidentifiers count] < 1)
@throw [OFInvalidFormatException exception];
switch ([[subidentifiers objectAtIndex: 0] intMaxValue]) {
case 0:
case 1:
case 2:
break;
default:
@throw [OFInvalidFormatException exception];
}
_subidentifiers = [subidentifiers copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass
tagNumber: (of_asn1_tag_number_t)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
self = [super init];
void *pool = objc_autoreleasePoolPush();
OFMutableArray OF_GENERIC(OFNumber *) *subidentifiers;
@try {
void *pool = objc_autoreleasePoolPush();
const unsigned char *items = [DEREncodedContents items];
size_t count = [DEREncodedContents count];
OFMutableArray *subidentifiers = [OFMutableArray array];
uintmax_t value = 0;
uint_fast8_t bits = 0;
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
tagNumber != OF_ASN1_TAG_NUMBER_OBJECT_IDENTIFIER ||
constructed)
@throw [OFInvalidArgumentException exception];
if ([DEREncodedContents itemSize] != 1 || count == 0)
@throw [OFInvalidArgumentException exception];
subidentifiers = [OFMutableArray array];
for (size_t i = 0; i < count; i++) {
if (bits == 0 && items[i] == 0x80)
@throw [OFInvalidFormatException exception];
value = (value << 7) | (items[i] & 0x7F);
bits += 7;
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
-
-
-
+
+
+
+
+
+
+
+
+
|
bits = 0;
}
if (items[count - 1] & 0x80)
@throw [OFInvalidFormatException exception];
[subidentifiers makeImmutable];
_subidentifiers = [subidentifiers copy];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithSubidentifiers: subidentifiers];
objc_autoreleasePoolPop(pool);
return self;
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (void)dealloc
{
[_subidentifiers release];
[super dealloc];
}
|