Overview
Comment: | Add ASN.1 set type |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
d8f78ac6eb11c1fa6da5015b15131b09 |
User & Date: | js on 2018-10-14 11:56:57 |
Other Links: | manifest | tags |
Context
2018-10-14
| ||
15:39 | Add ASN.1 enumerated type check-in: 37a8ddc12a user: js tags: trunk | |
11:56 | Add ASN.1 set type check-in: d8f78ac6eb user: js tags: trunk | |
05:09 | Add ASN.1 NumericString and PrintableString types check-in: a4e479b8de user: js tags: trunk | |
Changes
Modified src/OFASN1Value.h from [a431296f32] to [11c7c25b7e].
︙ | ︙ | |||
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | OF_ASN1_TAG_NUMBER_OCTET_STRING = 0x04, /*! Null */ OF_ASN1_TAG_NUMBER_NULL = 0x05, /*! UTF-8 string */ OF_ASN1_TAG_NUMBER_UTF8_STRING = 0x0C, /*! Sequence */ OF_ASN1_TAG_NUMBER_SEQUENCE = 0x10, /*! NumericString */ OF_ASN1_TAG_NUMBER_NUMERIC_STRING = 0x12, /*! PrintableString */ OF_ASN1_TAG_NUMBER_PRINTABLE_STRING = 0x13, /*! IA5String */ OF_ASN1_TAG_NUMBER_IA5_STRING = 0x16 } of_asn1_tag_number_t; | > > | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | OF_ASN1_TAG_NUMBER_OCTET_STRING = 0x04, /*! Null */ OF_ASN1_TAG_NUMBER_NULL = 0x05, /*! UTF-8 string */ OF_ASN1_TAG_NUMBER_UTF8_STRING = 0x0C, /*! Sequence */ OF_ASN1_TAG_NUMBER_SEQUENCE = 0x10, /*! Set */ OF_ASN1_TAG_NUMBER_SET = 0x11, /*! NumericString */ OF_ASN1_TAG_NUMBER_NUMERIC_STRING = 0x12, /*! PrintableString */ OF_ASN1_TAG_NUMBER_PRINTABLE_STRING = 0x13, /*! IA5String */ OF_ASN1_TAG_NUMBER_IA5_STRING = 0x16 } of_asn1_tag_number_t; |
︙ | ︙ |
Modified src/OFData+ASN1DERValue.m from [e26a5f00d5] to [5d1aa1b15d].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFASN1Null.h" #import "OFASN1NumericString.h" #import "OFASN1OctetString.h" #import "OFASN1PrintableString.h" #import "OFASN1UTF8String.h" #import "OFASN1Value.h" #import "OFArray.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" enum { | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #import "OFASN1Null.h" #import "OFASN1NumericString.h" #import "OFASN1OctetString.h" #import "OFASN1PrintableString.h" #import "OFASN1UTF8String.h" #import "OFASN1Value.h" #import "OFArray.h" #import "OFSet.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" enum { |
︙ | ︙ | |||
60 61 62 63 64 65 66 67 68 69 70 71 72 73 | count -= objectLength; contents = [contents subdataWithRange: of_range(objectLength, count)]; [ret addObject: object]; } [ret makeImmutable]; return ret; } static size_t | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | count -= objectLength; contents = [contents subdataWithRange: of_range(objectLength, count)]; [ret addObject: object]; } [ret makeImmutable]; return ret; } static OFSet * parseSet(OFData *contents, size_t depthLimit) { OFMutableSet *ret = [OFMutableSet set]; size_t count = [contents count]; OFData *previousObjectData = nil; if (depthLimit == 0) @throw [OFOutOfRangeException exception]; while (count > 0) { id object; size_t objectLength; OFData *objectData; objectLength = parseObject(contents, &object, depthLimit); objectData = [contents subdataWithRange: of_range(0, objectLength)]; if (previousObjectData != nil && [objectData compare: previousObjectData] != OF_ORDERED_DESCENDING) @throw [OFInvalidFormatException exception]; count -= objectLength; contents = [contents subdataWithRange: of_range(objectLength, count)]; [ret addObject: object]; previousObjectData = objectData; } [ret makeImmutable]; return ret; } static size_t |
︙ | ︙ | |||
140 141 142 143 144 145 146 147 148 149 150 151 152 153 | break; case OF_ASN1_TAG_NUMBER_SEQUENCE: if (!(tag & ASN1_TAG_CONSTRUCTED_MASK)) @throw [OFInvalidFormatException exception]; *object = parseSequence(contents, depthLimit - 1); return bytesConsumed; case OF_ASN1_TAG_NUMBER_NUMERIC_STRING: valueClass = [OFASN1NumericString class]; break; case OF_ASN1_TAG_NUMBER_PRINTABLE_STRING: valueClass = [OFASN1PrintableString class]; break; case OF_ASN1_TAG_NUMBER_IA5_STRING: | > > > > > > | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | break; case OF_ASN1_TAG_NUMBER_SEQUENCE: if (!(tag & ASN1_TAG_CONSTRUCTED_MASK)) @throw [OFInvalidFormatException exception]; *object = parseSequence(contents, depthLimit - 1); return bytesConsumed; case OF_ASN1_TAG_NUMBER_SET: if (!(tag & ASN1_TAG_CONSTRUCTED_MASK)) @throw [OFInvalidFormatException exception]; *object = parseSet(contents, depthLimit - 1); return bytesConsumed; case OF_ASN1_TAG_NUMBER_NUMERIC_STRING: valueClass = [OFASN1NumericString class]; break; case OF_ASN1_TAG_NUMBER_PRINTABLE_STRING: valueClass = [OFASN1PrintableString class]; break; case OF_ASN1_TAG_NUMBER_IA5_STRING: |
︙ | ︙ |
Modified tests/OFASN1DERValueTests.m from [37d93a7b04] to [d8fb1ed7f2].
︙ | ︙ | |||
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 | #import "OFASN1Integer.h" #import "OFASN1Null.h" #import "OFASN1NumericString.h" #import "OFASN1OctetString.h" #import "OFASN1PrintableString.h" #import "OFASN1UTF8String.h" #import "OFArray.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" static OFString *module = @"OFData+ASN1DERValue"; @implementation TestsAppDelegate (OFASN1DERValueTests) - (void)ASN1DERValueTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFASN1BitString *bitString; OFArray *array; /* Boolean */ TEST(@"Parsing of boolean", ![[[OFData dataWithItems: "\x01\x01\x00" count: 3] ASN1DERValue] booleanValue] && [[[OFData dataWithItems: "\x01\x01\xFF" count: 3] ASN1DERValue] booleanValue]) | > > > | 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 | #import "OFASN1Integer.h" #import "OFASN1Null.h" #import "OFASN1NumericString.h" #import "OFASN1OctetString.h" #import "OFASN1PrintableString.h" #import "OFASN1UTF8String.h" #import "OFArray.h" #import "OFSet.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" static OFString *module = @"OFData+ASN1DERValue"; @implementation TestsAppDelegate (OFASN1DERValueTests) - (void)ASN1DERValueTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFASN1BitString *bitString; OFArray *array; OFSet *set; OFEnumerator *enumerator; /* Boolean */ TEST(@"Parsing of boolean", ![[[OFData dataWithItems: "\x01\x01\x00" count: 3] ASN1DERValue] booleanValue] && [[[OFData dataWithItems: "\x01\x01\xFF" count: 3] ASN1DERValue] booleanValue]) |
︙ | ︙ | |||
238 239 240 241 242 243 244 | [array isKindOfClass: [OFArray class]] && [array count] == 0 && (array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test" count: 11] ASN1DERValue]) && [array isKindOfClass: [OFArray class]] && [array count] == 2 && [[array objectAtIndex: 0] integerValue] == 123 && [[[array objectAtIndex: 1] stringValue] isEqual: @"Test"]) | | | > > > > > > > > > > > > > > > > > > > > > > > > > > | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | [array isKindOfClass: [OFArray class]] && [array count] == 0 && (array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test" count: 11] ASN1DERValue]) && [array isKindOfClass: [OFArray class]] && [array count] == 2 && [[array objectAtIndex: 0] integerValue] == 123 && [[[array objectAtIndex: 1] stringValue] isEqual: @"Test"]) EXPECT_EXCEPTION(@"Detection of truncated sequence #1", OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated sequence #2", OFTruncatedDataException, [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00" count: 7] ASN1DERValue]) /* Set */ TEST(@"Parsing of set", (set = [[OFData dataWithItems: "\x31\x00" count: 2] ASN1DERValue]) && [set isKindOfClass: [OFSet class]] && [set count] == 0 && (set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test" count: 11] ASN1DERValue]) && [set isKindOfClass: [OFSet class]] && [set count] == 2 && (enumerator = [set objectEnumerator]) && [[enumerator nextObject] integerValue] == 123 && [[[enumerator nextObject] stringValue] isEqual: @"Test"]) EXPECT_EXCEPTION(@"Detection of invalid set", OFInvalidFormatException, [[OFData dataWithItems: "\x31\x06\x02\x01\x02\x02\x01\x01" count: 8] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated set #1", OFTruncatedDataException, [[OFData dataWithItems: "\x31\x01" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated set #2", OFTruncatedDataException, [[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00" count: 7] ASN1DERValue]) /* NumericString */ TEST(@"Parsing of NumericString", [[[[OFData dataWithItems: "\x12\x0B" "12345 67890" count: 13] ASN1DERValue] numericStringValue] isEqual: @"12345 67890"] && [[[[OFData dataWithItems: "\x12\x81\x80" "0000000000000000000000000" "0000000000000000000000000000000000000000" |
︙ | ︙ |