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
|
- (instancetype)initWithBitString: (OFData *)bitString length: (size_t)length
{
self = [super init];
@try {
if (bitString.count * bitString.itemSize !=
OF_ROUND_UP_POW2(8, length) / 8)
@throw [OFInvalidFormatException exception];
_bitStringValue = [bitString copy];
_bitStringLength = length;
} @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
{
void *pool = objc_autoreleasePoolPush();
OFData *bitString;
size_t length;
@try {
unsigned char unusedBits;
size_t count = DEREncodedContents.count;
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
tagNumber != OF_ASN1_TAG_NUMBER_BIT_STRING || constructed)
@throw [OFInvalidArgumentException exception];
if (DEREncodedContents.itemSize != 1 || count == 0)
@throw [OFInvalidFormatException exception];
unusedBits =
*(unsigned char *)[DEREncodedContents itemAtIndex: 0];
|
|
|
|
|
|
|
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
|
- (instancetype)initWithBitString: (OFData *)bitString length: (size_t)length
{
self = [super init];
@try {
if (bitString.count * bitString.itemSize !=
OFRoundUpToPowerOf2(8, length) / 8)
@throw [OFInvalidFormatException exception];
_bitStringValue = [bitString copy];
_bitStringLength = length;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithTagClass: (OFASN1TagClass)tagClass
tagNumber: (OFASN1TagNumber)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
void *pool = objc_autoreleasePoolPush();
OFData *bitString;
size_t length;
@try {
unsigned char unusedBits;
size_t count = DEREncodedContents.count;
if (tagClass != OFASN1TagClassUniversal ||
tagNumber != OFASN1TagNumberBitString || constructed)
@throw [OFInvalidArgumentException exception];
if (DEREncodedContents.itemSize != 1 || count == 0)
@throw [OFInvalidFormatException exception];
unusedBits =
*(unsigned char *)[DEREncodedContents itemAtIndex: 0];
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
@throw [OFInvalidFormatException exception];
if (SIZE_MAX / 8 < count - 1)
@throw [OFOutOfRangeException exception];
length = (count - 1) * 8;
bitString = [DEREncodedContents subdataWithRange:
of_range(1, count - 1)];
if (unusedBits != 0)
length -= unusedBits;
} @catch (id e) {
[self release];
@throw e;
}
|
|
|
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
@throw [OFInvalidFormatException exception];
if (SIZE_MAX / 8 < count - 1)
@throw [OFOutOfRangeException exception];
length = (count - 1) * 8;
bitString = [DEREncodedContents subdataWithRange:
OFRangeMake(1, count - 1)];
if (unusedBits != 0)
length -= unusedBits;
} @catch (id e) {
[self release];
@throw e;
}
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
[super dealloc];
}
- (OFData *)ASN1DERRepresentation
{
size_t bitStringValueCount = _bitStringValue.count;
size_t roundedUpLength = OF_ROUND_UP_POW2(8, _bitStringLength);
unsigned char unusedBits = roundedUpLength - _bitStringLength;
unsigned char header[] = {
OF_ASN1_TAG_NUMBER_BIT_STRING,
bitStringValueCount + 1,
unusedBits
};
OFMutableData *data;
if (bitStringValueCount + 1 > UINT8_MAX ||
bitStringValueCount != roundedUpLength / 8)
|
|
|
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
[super dealloc];
}
- (OFData *)ASN1DERRepresentation
{
size_t bitStringValueCount = _bitStringValue.count;
size_t roundedUpLength = OFRoundUpToPowerOf2(8, _bitStringLength);
unsigned char unusedBits = roundedUpLength - _bitStringLength;
unsigned char header[] = {
OFASN1TagNumberBitString,
bitStringValueCount + 1,
unusedBits
};
OFMutableData *data;
if (bitStringValueCount + 1 > UINT8_MAX ||
bitStringValueCount != roundedUpLength / 8)
|