40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
- (instancetype)initWithBitStringValue: (OFData *)bitStringValue
bitStringLength: (size_t)bitStringLength
{
self = [super init];
@try {
if (bitStringValue.count * bitStringValue.itemSize !=
bitStringLength / 8)
@throw [OFInvalidFormatException exception];
_bitStringValue = [bitStringValue copy];
_bitStringLength = bitStringLength;
} @catch (id e) {
[self release];
@throw e;
|
|
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
- (instancetype)initWithBitStringValue: (OFData *)bitStringValue
bitStringLength: (size_t)bitStringLength
{
self = [super init];
@try {
if (bitStringValue.count * bitStringValue.itemSize !=
OF_ROUND_UP_POW2(8, bitStringLength) / 8)
@throw [OFInvalidFormatException exception];
_bitStringValue = [bitStringValue copy];
_bitStringLength = bitStringLength;
} @catch (id e) {
[self release];
@throw e;
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
if (DEREncodedContents.itemSize != 1 || count == 0)
@throw [OFInvalidFormatException exception];
lastByteBits =
*(unsigned char *)[DEREncodedContents itemAtIndex: 0];
if (count == 1 && lastByteBits != 0)
@throw [OFInvalidFormatException exception];
if (SIZE_MAX / 8 < count - 1 ||
SIZE_MAX - (count - 1) * 8 < lastByteBits)
@throw [OFOutOfRangeException exception];
bitStringLength = (count - 1) * 8 + lastByteBits;
bitStringValue = [[DEREncodedContents
subdataWithRange: of_range(1, count - 1)] copy];
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithBitStringValue: bitStringValue
bitStringLength: bitStringLength];
|
>
>
>
>
>
>
|
>
>
>
|
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
if (DEREncodedContents.itemSize != 1 || count == 0)
@throw [OFInvalidFormatException exception];
lastByteBits =
*(unsigned char *)[DEREncodedContents itemAtIndex: 0];
if (lastByteBits > 7)
@throw [OFInvalidFormatException exception];
/*
* Can't have any bits of the last byte used if we have no byte.
*/
if (count == 1 && lastByteBits != 0)
@throw [OFInvalidFormatException exception];
if (SIZE_MAX / 8 < count - 1 ||
SIZE_MAX - (count - 1) * 8 < lastByteBits)
@throw [OFOutOfRangeException exception];
bitStringLength = (count - 1) * 8;
bitStringValue = [[DEREncodedContents
subdataWithRange: of_range(1, count - 1)] copy];
if (lastByteBits != 0)
bitStringLength -= (8 - lastByteBits);
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithBitStringValue: bitStringValue
bitStringLength: bitStringLength];
|
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
- (void)dealloc
{
[_bitStringValue release];
[super dealloc];
}
- (bool)isEqual: (id)object
{
OFASN1BitString *bitString;
if (![object isKindOfClass: [OFASN1BitString class]])
return false;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
150
151
152
153
154
|
- (void)dealloc
{
[_bitStringValue release];
[super dealloc];
}
- (OFData *)DEREncodedValue
{
size_t bitStringValueCount = [_bitStringValue count];
unsigned char lastByteBits = _bitStringLength % 8;
unsigned char header[] = { 3, bitStringValueCount + 1, lastByteBits };
OFMutableData *data;
if (bitStringValueCount + 1 > UINT8_MAX ||
bitStringValueCount != OF_ROUND_UP_POW2(8, _bitStringLength) / 8)
@throw [OFInvalidFormatException exception];
data = [OFMutableData dataWithCapacity: 3 + bitStringValueCount];
[data addItems: header
count: 3];
[data addItems: [_bitStringValue items]
count: bitStringValueCount];
[data makeImmutable];
return data;
}
- (bool)isEqual: (id)object
{
OFASN1BitString *bitString;
if (![object isKindOfClass: [OFASN1BitString class]])
return false;
|