Differences From Artifact [eada094776]:
- File src/OFASN1BitString.m — part of check-in [cbaae715ce] at 2019-06-25 20:53:23 on branch trunk — Add OFASN1DERRepresentation protocol (user: js, size: 4473) [annotate] [blame] [check-ins using]
To Artifact [060f7fe7bc]:
- File
src/OFASN1BitString.m
— part of check-in
[7361cac1f1]
at
2019-06-25 23:29:22
on branch trunk
— OFASN1BitString: Fix unused bits
This was misunderstood to be the number of used bits when it's the
number of unused bits. (user: js, size: 4482) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
63 64 65 66 67 68 69 | DEREncodedContents: (OFData *)DEREncodedContents { void *pool = objc_autoreleasePoolPush(); OFData *bitStringValue; size_t bitStringLength; @try { | | | | | > | | < | | | 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 97 98 99 100 101 102 103 104 105 106 107 108 | DEREncodedContents: (OFData *)DEREncodedContents { void *pool = objc_autoreleasePoolPush(); OFData *bitStringValue; size_t bitStringLength; @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]; if (unusedBits > 7) @throw [OFInvalidFormatException exception]; /* * Can't have any bits of the last byte unused if we have no * byte. */ if (count == 1 && unusedBits != 0) @throw [OFInvalidFormatException exception]; if (SIZE_MAX / 8 < count - 1) @throw [OFOutOfRangeException exception]; bitStringLength = (count - 1) * 8; bitStringValue = [[DEREncodedContents subdataWithRange: of_range(1, count - 1)] copy]; if (unusedBits != 0) bitStringLength -= unusedBits; } @catch (id e) { [self release]; @throw e; } self = [self initWithBitStringValue: bitStringValue bitStringLength: bitStringLength]; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | [super dealloc]; } - (OFData *)ASN1DERRepresentation { size_t bitStringValueCount = [_bitStringValue count]; | > | | | | > | 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 | [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) @throw [OFInvalidFormatException exception]; data = [OFMutableData dataWithCapacity: sizeof(header) + bitStringValueCount]; [data addItems: header count: sizeof(header)]; [data addItems: [_bitStringValue items] count: bitStringValueCount]; [data makeImmutable]; |
︙ | ︙ |