Overview
Comment: | Add ASN.1 NumericString and PrintableString types |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a4e479b8de615971767860bcbe2cab53 |
User & Date: | js on 2018-10-14 05:09:23 |
Other Links: | manifest | tags |
Context
2018-10-14
| ||
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 | |
2018-10-13
| ||
23:51 | Add ASN.1 bit string type check-in: 0d746a1aac user: js tags: trunk | |
Changes
Modified src/Makefile from [683f8a0c9a] to [f0e8ff964e].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFASN1BitString.m \ OFASN1Boolean.m \ OFASN1IA5String.m \ OFASN1Integer.m \ OFASN1Null.m \ OFASN1OctetString.m \ OFASN1UTF8String.m \ OFASN1Value.m \ OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFCharacterSet.m \ | > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFASN1BitString.m \ OFASN1Boolean.m \ OFASN1IA5String.m \ OFASN1Integer.m \ OFASN1Null.m \ OFASN1NumericString.m \ OFASN1OctetString.m \ OFASN1PrintableString.m \ OFASN1UTF8String.m \ OFASN1Value.m \ OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFCharacterSet.m \ |
︙ | ︙ |
Added src/OFASN1NumericString.h version [ff4261a7f5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFASN1Value.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /*! * @brief An ASN.1 NumericString. */ @interface OFASN1NumericString: OFASN1Value { OFString *_numericStringValue; } /*! * @brief The NumericString value. */ @property (readonly, nonatomic) OFString *numericStringValue; /*! * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; @end OF_ASSUME_NONNULL_END |
Added src/OFASN1NumericString.m version [0dfe0413cd].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFASN1NumericString.h" #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1NumericString @synthesize numericStringValue = _numericStringValue; - (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass tagNumber: (of_asn1_tag_number_t)tagNumber constructed: (bool)constructed DEREncodedContents: (OFData *)DEREncodedContents { self = [super initWithTagClass: tagClass tagNumber: tagNumber constructed: constructed DEREncodedContents: DEREncodedContents]; @try { const unsigned char *items = [_DEREncodedContents items]; size_t count = [_DEREncodedContents count]; if (_tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || _tagNumber != OF_ASN1_TAG_NUMBER_NUMERIC_STRING || _constructed) @throw [OFInvalidArgumentException exception]; for (size_t i = 0; i < count; i++) if (!of_ascii_isdigit(items[i]) && items[i] != ' ') @throw [OFInvalidEncodingException exception]; _numericStringValue = [[OFString alloc] initWithCString: [_DEREncodedContents items] encoding: OF_STRING_ENCODING_ASCII length: [_DEREncodedContents count]]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_numericStringValue release]; [super dealloc]; } - (OFString *)stringValue { return [self numericStringValue]; } - (OFString *)description { return [OFString stringWithFormat: @"<OFASN1NumericString: %@>", _numericStringValue]; } @end |
Added src/OFASN1PrintableString.h version [29166468df].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFASN1Value.h" OF_ASSUME_NONNULL_BEGIN @class OFString; /*! * @brief An ASN.1 PrintableString. */ @interface OFASN1PrintableString: OFASN1Value { OFString *_printableStringValue; } /*! * @brief The PrintableString value. */ @property (readonly, nonatomic) OFString *printableStringValue; /*! * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; @end OF_ASSUME_NONNULL_END |
Added src/OFASN1PrintableString.m version [c4ad6140d5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 59 60 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 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFASN1PrintableString.h" #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1PrintableString @synthesize printableStringValue = _printableStringValue; - (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass tagNumber: (of_asn1_tag_number_t)tagNumber constructed: (bool)constructed DEREncodedContents: (OFData *)DEREncodedContents { self = [super initWithTagClass: tagClass tagNumber: tagNumber constructed: constructed DEREncodedContents: DEREncodedContents]; @try { const unsigned char *items = [_DEREncodedContents items]; size_t count = [_DEREncodedContents count]; if (_tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || _tagNumber != OF_ASN1_TAG_NUMBER_PRINTABLE_STRING || _constructed) @throw [OFInvalidArgumentException exception]; for (size_t i = 0; i < count; i++) { if (of_ascii_isalnum(items[i])) continue; switch (items[i]) { case ' ': case '\'': case '(': case ')': case '+': case ',': case '-': case '.': case '/': case ':': case '=': case '?': continue; default: @throw [OFInvalidEncodingException exception]; } } _printableStringValue = [[OFString alloc] initWithCString: [_DEREncodedContents items] encoding: OF_STRING_ENCODING_ASCII length: [_DEREncodedContents count]]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_printableStringValue release]; [super dealloc]; } - (OFString *)stringValue { return [self printableStringValue]; } - (OFString *)description { return [OFString stringWithFormat: @"<OFASN1PrintableString: %@>", _printableStringValue]; } @end |
Modified src/OFASN1Value.h from [c97d7a86f0] to [a431296f32].
︙ | ︙ | |||
38 39 40 41 42 43 44 | } of_asn1_tag_class_t; /*! * @brief ASN.1 tag number. */ typedef enum { /*! Boolean */ | | | | | | | | > > > > | | 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 | } of_asn1_tag_class_t; /*! * @brief ASN.1 tag number. */ typedef enum { /*! Boolean */ OF_ASN1_TAG_NUMBER_BOOLEAN = 0x01, /*! Integer */ OF_ASN1_TAG_NUMBER_INTEGER = 0x02, /*! Bit string */ OF_ASN1_TAG_NUMBER_BIT_STRING = 0x03, /*! Octet string */ 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; /*! * @brief A class representing an ASN.1 value. */ @interface OFASN1Value: OFObject <OFCopying> { |
︙ | ︙ |
Modified src/OFData+ASN1DERValue.m from [431b6dfad4] to [e26a5f00d5].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFData+ASN1DERValue.h" #import "OFASN1BitString.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" | > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "OFData+ASN1DERValue.h" #import "OFASN1BitString.h" #import "OFASN1Boolean.h" #import "OFASN1IA5String.h" #import "OFASN1Integer.h" #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" |
︙ | ︙ | |||
113 114 115 116 117 118 119 | if (count - bytesConsumed < contentsLength) @throw [OFTruncatedDataException exception]; contents = [self subdataWithRange: of_range(bytesConsumed, contentsLength)]; bytesConsumed += contentsLength; | | > | | > > > > > > | 115 116 117 118 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 155 156 157 158 159 | if (count - bytesConsumed < contentsLength) @throw [OFTruncatedDataException exception]; contents = [self subdataWithRange: of_range(bytesConsumed, contentsLength)]; bytesConsumed += contentsLength; switch (tag & ~ASN1_TAG_CONSTRUCTED_MASK) { 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_BIT_STRING: valueClass = [OFASN1BitString 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: 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: valueClass = [OFASN1IA5String class]; break; default: valueClass = [OFASN1Value class]; break; } |
︙ | ︙ |
Modified tests/OFASN1DERValueTests.m from [9bdacd32af] to [37d93a7b04].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFData.h" #import "OFASN1BitString.h" #import "OFASN1Boolean.h" #import "OFASN1IA5String.h" #import "OFASN1Integer.h" #import "OFASN1Null.h" #import "OFASN1OctetString.h" #import "OFASN1UTF8String.h" #import "OFArray.h" #import "OFString.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" | > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "OFData.h" #import "OFASN1BitString.h" #import "OFASN1Boolean.h" #import "OFASN1IA5String.h" #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" |
︙ | ︙ | |||
41 42 43 44 45 46 47 48 49 50 51 52 53 54 | @implementation TestsAppDelegate (OFASN1DERValueTests) - (void)ASN1DERValueTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFASN1BitString *bitString; OFArray *array; TEST(@"Parsing of boolean", ![[[OFData dataWithItems: "\x01\x01\x00" count: 3] ASN1DERValue] booleanValue] && [[[OFData dataWithItems: "\x01\x01\xFF" count: 3] ASN1DERValue] booleanValue]) EXPECT_EXCEPTION(@"Detection of invalid boolean #1", | > | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | @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]) EXPECT_EXCEPTION(@"Detection of invalid boolean #1", |
︙ | ︙ | |||
63 64 65 66 67 68 69 70 71 72 73 74 75 76 | OFInvalidFormatException, [[OFData dataWithItems: "\x01\x00" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated boolean", OFTruncatedDataException, [[OFData dataWithItems: "\x01\x01" count: 2] ASN1DERValue]) TEST(@"Parsing of integer", [[[OFData dataWithItems: "\x02\x00" count: 2] ASN1DERValue] integerValue] == 0 && [[[OFData dataWithItems: "\x02\x01\x01" count: 3] ASN1DERValue] integerValue] == 1 && [[[OFData dataWithItems: "\x02\x02\x01\x04" count: 4] ASN1DERValue] integerValue] == 260 && | > | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | OFInvalidFormatException, [[OFData dataWithItems: "\x01\x00" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated boolean", OFTruncatedDataException, [[OFData dataWithItems: "\x01\x01" count: 2] ASN1DERValue]) /* Integer */ TEST(@"Parsing of integer", [[[OFData dataWithItems: "\x02\x00" count: 2] ASN1DERValue] integerValue] == 0 && [[[OFData dataWithItems: "\x02\x01\x01" count: 3] ASN1DERValue] integerValue] == 1 && [[[OFData dataWithItems: "\x02\x02\x01\x04" count: 4] ASN1DERValue] integerValue] == 260 && |
︙ | ︙ | |||
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated integer", OFTruncatedDataException, [[OFData dataWithItems: "\x02\x02\x00" count: 3] ASN1DERValue]) TEST(@"Parsing of bit string", (bitString = [[OFData dataWithItems: "\x03\x01\x00" count: 3] ASN1DERValue]) && [[bitString bitStringValue] isEqual: [OFData dataWithItems: "" count: 0]] && [bitString bitStringLength] == 0 && (bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80" count: 15] ASN1DERValue]) && [[bitString bitStringValue] isEqual: [OFData dataWithItems: "Hello World\x80" count: 12]] && [bitString bitStringLength] == 97 && (bitString = [[OFData dataWithItems: "\x03\x81\x80\x00xxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxx" | > | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated integer", OFTruncatedDataException, [[OFData dataWithItems: "\x02\x02\x00" count: 3] ASN1DERValue]) /* Bit string */ TEST(@"Parsing of bit string", (bitString = [[OFData dataWithItems: "\x03\x01\x00" count: 3] ASN1DERValue]) && [[bitString bitStringValue] isEqual: [OFData dataWithItems: "" count: 0]] && [bitString bitStringLength] == 0 && (bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80" count: 15] ASN1DERValue]) && [[bitString bitStringValue] isEqual: [OFData dataWithItems: "Hello World\x80" count: 12]] && [bitString bitStringLength] == 97 && (bitString = [[OFData dataWithItems: "\x03\x81\x80\x00xxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxx" count: 131] ASN1DERValue]) && [[bitString bitStringValue] isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxx" count: 127]] && [bitString bitStringLength] == 127 * 8) |
︙ | ︙ | |||
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | "\x01\x01\x01\x01\x01\x01\x01\x01\x01" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated bit string", OFTruncatedDataException, [[OFData dataWithItems: "\x03\x01" count: 2] ASN1DERValue]) TEST(@"Parsing of octet string", [[[[OFData dataWithItems: "\x04\x0CHello World!" count: 14] ASN1DERValue] octetStringValue] isEqual: [OFData dataWithItems: "Hello World!" count: 12]] && [[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxx" | > | > | > | | | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | "\x01\x01\x01\x01\x01\x01\x01\x01\x01" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated bit string", OFTruncatedDataException, [[OFData dataWithItems: "\x03\x01" count: 2] ASN1DERValue]) /* Octet string */ TEST(@"Parsing of octet string", [[[[OFData dataWithItems: "\x04\x0CHello World!" count: 14] ASN1DERValue] octetStringValue] isEqual: [OFData dataWithItems: "Hello World!" count: 12]] && [[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxx" count: 131] ASN1DERValue] octetStringValue] isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxx" count: 128]]) EXPECT_EXCEPTION(@"Detection of out of range octet string", OFOutOfRangeException, [[OFData dataWithItems: "\x04\x89" "\x01\x01\x01\x01\x01\x01\x01\x01\x01" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated octet string", OFTruncatedDataException, [[OFData dataWithItems: "\x04\x01" count: 2] ASN1DERValue]) /* Null */ TEST(@"Parsing of null", [[[OFData dataWithItems: "\x05\x00" count: 2] ASN1DERValue] isKindOfClass: [OFASN1Null class]]) EXPECT_EXCEPTION(@"Detection of invalid NULL", OFInvalidFormatException, [[OFData dataWithItems: "\x05\x01\x00" count: 3] ASN1DERValue]) /* UTF-8 string */ TEST(@"Parsing of UTF-8 string", [[[[OFData dataWithItems: "\x0C\x0EHällo Wörld!" count: 16] ASN1DERValue] UTF8StringValue] isEqual: @"Hällo Wörld!"] && [[[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxx" count: 131] ASN1DERValue] UTF8StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @"xxxxxxxxxxxxxxxx"]) EXPECT_EXCEPTION(@"Detection of out of range UTF-8 string", OFOutOfRangeException, [[OFData dataWithItems: "\x0C\x89" |
︙ | ︙ | |||
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | OFInvalidFormatException, [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxx" count: 132] ASN1DERValue]) TEST(@"Parsing of sequence", (array = [[OFData dataWithItems: "\x30\x00" count: 2] ASN1DERValue]) && [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(@"Parsing of truncated sequence #1", OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Parsing of truncated sequence #2", OFTruncatedDataException, [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00" count: 7] ASN1DERValue]) TEST(@"Parsing of IA5String", [[[[OFData dataWithItems: "\x16\x0CHello World!" | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 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 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | OFInvalidFormatException, [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxx" count: 132] ASN1DERValue]) /* Sequence */ TEST(@"Parsing of sequence", (array = [[OFData dataWithItems: "\x30\x00" count: 2] ASN1DERValue]) && [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(@"Parsing of truncated sequence #1", OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" count: 2] ASN1DERValue]) EXPECT_EXCEPTION(@"Parsing of truncated sequence #2", OFTruncatedDataException, [[OFData dataWithItems: "\x30\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" "0000000000000000000000000000000000000000" "00000000000000000000000" count: 131] ASN1DERValue] numericStringValue] isEqual: @"00000000000000000000000000000000000000000000000000000000" @"00000000000000000000000000000000000000000000000000000000" @"0000000000000000"]) EXPECT_EXCEPTION(@"Detection of invalid NumericString", OFInvalidEncodingException, [[OFData dataWithItems: "\x12\x02." count: 4] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of out of range NumericString", OFOutOfRangeException, [[OFData dataWithItems: "\x12\x89" "\x01\x01\x01\x01\x01\x01\x01\x01\x01" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated NumericString", OFTruncatedDataException, [[OFData dataWithItems: "\x12\x01" count: 2] ASN1DERValue]) /* PrintableString */ TEST(@"Parsing of PrintableString", [[[[OFData dataWithItems: "\x13\x0CHello World." count: 14] ASN1DERValue] printableStringValue] isEqual: @"Hello World."] && [[[[OFData dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnop" "qrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()" "+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEF" "GHIJKLMNOPQRSTUVWXYZ" count: 131] ASN1DERValue] printableStringValue] isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR" @"STUVWXYZ '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJ" @"KLMNOPQRSTUVWXYZ"]) EXPECT_EXCEPTION(@"Detection of invalid PrintableString", OFInvalidEncodingException, [[OFData dataWithItems: "\x13\x02;" count: 4] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of out of range PrintableString", OFOutOfRangeException, [[OFData dataWithItems: "\x13\x89" "\x01\x01\x01\x01\x01\x01\x01\x01\x01" count: 11] ASN1DERValue]) EXPECT_EXCEPTION(@"Detection of truncated PrintableString", OFTruncatedDataException, [[OFData dataWithItems: "\x13\x01" count: 2] ASN1DERValue]) /* IA5String */ TEST(@"Parsing of IA5String", [[[[OFData dataWithItems: "\x16\x0CHello World!" count: 14] ASN1DERValue] IA5StringValue] isEqual: @"Hello World!"] && [[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" "xxxxxxxxxxxxxxxxxxxx" count: 131] ASN1DERValue] IA5StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" @"xxxxxxxxxxxxxxxx"]) EXPECT_EXCEPTION(@"Detection of invalid IA5String", OFInvalidEncodingException, [[OFData dataWithItems: "\x16\x02ä" |
︙ | ︙ |