ObjFW  Diff

Differences From Artifact [a444610f3e]:

To Artifact [53e3bd957f]:


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
 * file.
 */

#include "config.h"

#import "OFData+ASN1DERValue.h"
#import "OFASN1Boolean.h"

#import "OFASN1Integer.h"
#import "OFASN1Null.h"

#import "OFASN1UTF8String.h"
#import "OFASN1Value.h"
#import "OFArray.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"

enum {
	ASN1_TAG_CONSTRUCTED_MASK = 0x20
};

int _OFData_ASN1DERValue_reference;

static size_t parseObject(OFData *self, id *object, size_t depthLimit);

static OFArray *
parseSequence(OFData *contents, size_t depthLimit)
{

	size_t count = [contents count];
	OFMutableArray *ret;

	if (depthLimit == 0)
		@throw [OFOutOfRangeException exception];

	ret = [OFMutableArray array];

	while (count > 0) {
		id object;
		size_t objectLength;

		objectLength = parseObject(contents, &object, depthLimit);

		count -= objectLength;







>


>




















>

<




<
<







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
 * file.
 */

#include "config.h"

#import "OFData+ASN1DERValue.h"
#import "OFASN1Boolean.h"
#import "OFASN1IA5String.h"
#import "OFASN1Integer.h"
#import "OFASN1Null.h"
#import "OFASN1OctetString.h"
#import "OFASN1UTF8String.h"
#import "OFASN1Value.h"
#import "OFArray.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"

enum {
	ASN1_TAG_CONSTRUCTED_MASK = 0x20
};

int _OFData_ASN1DERValue_reference;

static size_t parseObject(OFData *self, id *object, size_t depthLimit);

static OFArray *
parseSequence(OFData *contents, size_t depthLimit)
{
	OFMutableArray *ret = [OFMutableArray array];
	size_t count = [contents count];


	if (depthLimit == 0)
		@throw [OFOutOfRangeException exception];



	while (count > 0) {
		id object;
		size_t objectLength;

		objectLength = parseObject(contents, &object, depthLimit);

		count -= objectLength;
119
120
121
122
123
124
125



126
127
128
129
130
131


132
133
134



135
136
137
138
139
140
141
	switch (tag) {
	case OF_ASN1_TAG_NUMBER_BOOLEAN:
		valueClass = [OFASN1Boolean class];
		break;
	case OF_ASN1_TAG_NUMBER_INTEGER:
		valueClass = [OFASN1Integer class];
		break;



	case OF_ASN1_TAG_NUMBER_NULL:
		valueClass = [OFASN1Null class];
		break;
	case OF_ASN1_TAG_NUMBER_UTF8_STRING:
		valueClass = [OFASN1UTF8String class];
		break;


	case OF_ASN1_TAG_NUMBER_SEQUENCE | ASN1_TAG_CONSTRUCTED_MASK:
		*object = parseSequence(contents, depthLimit - 1);
		return bytesConsumed;



	default:
		valueClass = [OFASN1Value class];
		break;
	}

	*object = [valueClass valueWithTagClass: tag >> 6
				      tagNumber: tag & 0x1F







>
>
>






>
>



>
>
>







119
120
121
122
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
	switch (tag) {
	case OF_ASN1_TAG_NUMBER_BOOLEAN:
		valueClass = [OFASN1Boolean class];
		break;
	case OF_ASN1_TAG_NUMBER_INTEGER:
		valueClass = [OFASN1Integer class];
		break;
	case OF_ASN1_TAG_NUMBER_OCTET_STRING:
		valueClass = [OFASN1OctetString class];
		break;
	case OF_ASN1_TAG_NUMBER_NULL:
		valueClass = [OFASN1Null class];
		break;
	case OF_ASN1_TAG_NUMBER_UTF8_STRING:
		valueClass = [OFASN1UTF8String class];
		break;
	case OF_ASN1_TAG_NUMBER_SEQUENCE:
		@throw [OFInvalidFormatException exception];
	case OF_ASN1_TAG_NUMBER_SEQUENCE | ASN1_TAG_CONSTRUCTED_MASK:
		*object = parseSequence(contents, depthLimit - 1);
		return bytesConsumed;
	case OF_ASN1_TAG_NUMBER_IA5_STRING:
		valueClass = [OFASN1IA5String class];
		break;
	default:
		valueClass = [OFASN1Value class];
		break;
	}

	*object = [valueClass valueWithTagClass: tag >> 6
				      tagNumber: tag & 0x1F