Comment: | OFASN1*: Clean up the API a little |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ca9b843d3711c1c0317b72f2e0cc55fe |
User & Date: | js on 2021-03-16 21:16:17 |
Other Links: | manifest | tags |
2021-03-16
| ||
22:55 | Fix lookup-asm-x86_64-win64.S check-in: 4750a54072 user: js tags: trunk | |
21:16 | OFASN1*: Clean up the API a little check-in: ca9b843d37 user: js tags: trunk | |
2021-03-14
| ||
23:54 | Convert lookup-asm-x86_64-win64.S to AT&T syntax check-in: 2fb21576da user: js tags: trunk | |
Modified src/OFASN1BitString.h from [c2be33e12e] to [0fbb50d9aa].
︙ | ︙ | |||
41 42 43 44 45 46 47 | */ @property (readonly, nonatomic) size_t bitStringLength; /** * @brief Creates an ASN.1 BitString with the specified BitString value and * length. * | | | | | | | | < | | 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 | */ @property (readonly, nonatomic) size_t bitStringLength; /** * @brief Creates an ASN.1 BitString with the specified BitString value and * length. * * @param bitString The value of the BitString * @param length The length of the BitString in bits * @return A new, autoreleased OFASN1BitString */ + (instancetype)bitStringWithBitString: (OFData *)bitString length: (size_t)length; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated ASN.1 BitString with the specified * BitString value and length. * * @param bitString The value of the BitString * @param length The length of the BitString in bits * @return An initialized OFASN1BitString */ - (instancetype)initWithBitString: (OFData *)bitString length: (size_t)length OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 BitString with the specified * arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1BitString.m from [843d69d324] to [d3bbe5638b].
︙ | ︙ | |||
23 24 25 26 27 28 29 | #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @implementation OFASN1BitString @synthesize bitStringValue = _bitStringValue; @synthesize bitStringLength = _bitStringLength; | | | | < | | < | | | | | | | 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 | #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @implementation OFASN1BitString @synthesize bitStringValue = _bitStringValue; @synthesize bitStringLength = _bitStringLength; + (instancetype)bitStringWithBitString: (OFData *)bitString length: (size_t)length { return [[[self alloc] initWithBitString: bitString length: length] autorelease]; } - (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) |
︙ | ︙ | |||
87 88 89 90 91 92 93 | */ if (count == 1 && unusedBits != 0) @throw [OFInvalidFormatException exception]; if (SIZE_MAX / 8 < count - 1) @throw [OFOutOfRangeException exception]; | | | | | < | | | 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 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 138 139 140 141 142 143 144 145 146 147 148 | */ if (count == 1 && unusedBits != 0) @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; } self = [self initWithBitString: bitString length: length]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_bitStringValue release]; [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]; return data; } - (bool)isEqual: (id)object |
︙ | ︙ |
Modified src/OFASN1Boolean.h from [4ac9986bdd] to [db11e25404].
︙ | ︙ | |||
21 22 23 24 25 26 27 | /** * @brief An ASN.1 Boolean. */ OF_SUBCLASSING_RESTRICTED @interface OFASN1Boolean: OFObject <OFASN1DERRepresentation> { | | | | | | | < | | 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 | /** * @brief An ASN.1 Boolean. */ OF_SUBCLASSING_RESTRICTED @interface OFASN1Boolean: OFObject <OFASN1DERRepresentation> { bool _boolValue; } /** * @brief The value of the Boolean. */ @property (readonly, nonatomic) bool boolValue; /** * @brief Creates an ASN.1 Boolean with the specified Boolean value. * * @param bool_ The value of the Boolean * @return A new, autoreleased OFASN1Boolean */ + (instancetype)booleanWithBool: (bool)bool_; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated ASN.1 Boolean with the specified * Boolean value. * * @param bool_ The value of the Boolean * @return An initialized OFASN1Boolean */ - (instancetype)initWithBool: (bool)bool_ OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 Boolean with the specified * arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1Boolean.m from [ae373739b8] to [57247a8096].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @implementation OFASN1Boolean | | | | | | | 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 | #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @implementation OFASN1Boolean @synthesize boolValue = _boolValue; + (instancetype)booleanWithBool: (bool)bool_ { return [[[self alloc] initWithBool: bool_] autorelease]; } - (instancetype)initWithBool: (bool)bool_ { self = [super init]; _boolValue = bool_; return self; } - (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass tagNumber: (of_asn1_tag_number_t)tagNumber constructed: (bool)constructed |
︙ | ︙ | |||
60 61 62 63 64 65 66 | if (value != 0 && value != 0xFF) @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } | | | | | | | 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | if (value != 0 && value != 0xFF) @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } return [self initWithBool: !!value]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (OFData *)ASN1DERRepresentation { char buffer[] = { OF_ASN1_TAG_NUMBER_BOOLEAN, 1, (_boolValue ? 0xFF : 0x00) }; return [OFData dataWithItems: buffer count: sizeof(buffer)]; } - (bool)isEqual: (id)object { OFASN1Boolean *boolean; if (object == self) return true; if (![object isKindOfClass: [OFASN1Boolean class]]) return false; boolean = object; if (boolean->_boolValue != _boolValue) return false; return true; } - (unsigned long)hash { return _boolValue; } - (OFString *)description { return (_boolValue ? @"<OFASN1Boolean: true>" : @"<OFASN1Boolean: false>"); } @end |
Modified src/OFASN1IA5String.h from [c74a3606bd] to [699db44549].
︙ | ︙ | |||
38 39 40 41 42 43 44 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates an IA5String with the specified string value. * | | | | < | | 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 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates an IA5String with the specified string value. * * @param string The string value of the IA5String * @return A new, autoreleased OFASN1IA5String */ + (instancetype)stringWithString: (OFString *)string; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated IA5String with the specified string * value. * * @param string The string value of the IA5String * @return An initialized OFASN1IA5String */ - (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 IA5String with the specified * arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1IA5String.m from [494960fd54] to [5ec7f22291].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1IA5String @synthesize IA5StringValue = _IA5StringValue; | | | | | | | | | 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 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1IA5String @synthesize IA5StringValue = _IA5StringValue; + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { _IA5StringValue = [string copy]; } @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(); OFString *IA5String; @try { if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || tagNumber != OF_ASN1_TAG_NUMBER_IA5_STRING || constructed) @throw [OFInvalidArgumentException exception]; if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; IA5String= [OFString stringWithCString: DEREncodedContents.items encoding: OF_STRING_ENCODING_ASCII length: DEREncodedContents.count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithString: IA5String]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)init |
︙ | ︙ |
Modified src/OFASN1NumericString.h from [e0198cfd1a] to [2bcc77fb41].
︙ | ︙ | |||
38 39 40 41 42 43 44 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates an NumericString with the specified string value. * | | | | < | | 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 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates an NumericString with the specified string value. * * @param string The string value of the NumericString * @return A new, autoreleased OFASN1NumericString */ + (instancetype)stringWithString: (OFString *)string; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated NumericString with the specified * string value. * * @param string The string value of the NumericString * @return An initialized OFASN1NumericString */ - (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 NumericString with the * specified arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1NumericString.m from [50fd063fbe] to [24e3b7cea6].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1NumericString @synthesize numericStringValue = _numericStringValue; | | | | | | | | | | | 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 | #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1NumericString @synthesize numericStringValue = _numericStringValue; + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *cString = string.UTF8String; size_t length = string.UTF8StringLength; for (size_t i = 0; i < length; i++) if (!of_ascii_isdigit(cString[i]) && cString[i] != ' ') @throw [OFInvalidEncodingException exception]; _numericStringValue = [string copy]; objc_autoreleasePoolPop(pool); } @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(); OFString *numericString; @try { if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || tagNumber != OF_ASN1_TAG_NUMBER_NUMERIC_STRING || constructed) @throw [OFInvalidArgumentException exception]; if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; numericString = [OFString stringWithCString: DEREncodedContents.items encoding: OF_STRING_ENCODING_ASCII length: DEREncodedContents.count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithString: numericString]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)init |
︙ | ︙ |
Modified src/OFASN1OctetString.h from [547dec0827] to [d7f4e338c8].
︙ | ︙ | |||
33 34 35 36 37 38 39 | * @brief The OctetString value. */ @property (readonly, nonatomic) OFData *octetStringValue; /** * @brief Creates an OctetString with the specified value. * | | | | | | 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 | * @brief The OctetString value. */ @property (readonly, nonatomic) OFData *octetStringValue; /** * @brief Creates an OctetString with the specified value. * * @param octetString The OctetString value * @return A new, autoreleased OFASN1OctetString */ + (instancetype)octetStringWithOctetString: (OFData *)octetString; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OctetString with the specified * value. * * @param octetString The OctetString value * @return An initialized OFASN1OctetString */ - (instancetype)initWithOctetString: (OFData *)octetString OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 OctetString with the specified * arguments. * * @param tagClass The tag class of the value's type |
︙ | ︙ |
Modified src/OFASN1OctetString.m from [42b0c8635d] to [dbf5bc7d07].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1OctetString @synthesize octetStringValue = _octetStringValue; | | | < | | | 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 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1OctetString @synthesize octetStringValue = _octetStringValue; + (instancetype)octetStringWithOctetString: (OFData *)octetString { return [[[self alloc] initWithOctetString: octetString] autorelease]; } - (instancetype)initWithOctetString: (OFData *)octetString { self = [super init]; @try { _octetStringValue = [octetString copy]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
58 59 60 61 62 63 64 | if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; } return [self initWithOctetString: DEREncodedContents]; } - (instancetype)init { OF_INVALID_INIT_METHOD } |
︙ | ︙ |
Modified src/OFASN1PrintableString.h from [0506eb78c3] to [15b004b863].
︙ | ︙ | |||
38 39 40 41 42 43 44 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates a PrintableString with the specified string value. * | | | | < | | 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 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates a PrintableString with the specified string value. * * @param string The string value of the PrintableString * @return A new, autoreleased OFASN1PrintableString */ + (instancetype)stringWithString: (OFString *)string; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated PrintableString with the specified * string value. * * @param string The string value of the PrintableString * @return An initialized OFASN1PrintableString */ - (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 PrintableString with the * specified arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1PrintableString.m from [d6f8fd877c] to [633e478a84].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1PrintableString @synthesize printableStringValue = _printableStringValue; | | | | | | | 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 | #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1PrintableString @synthesize printableStringValue = _printableStringValue; + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *cString = string.UTF8String; size_t length = string.UTF8StringLength; for (size_t i = 0; i < length; i++) { if (of_ascii_isalnum(cString[i])) continue; switch (cString[i]) { case ' ': |
︙ | ︙ | |||
58 59 60 61 62 63 64 | case '?': continue; default: @throw [OFInvalidEncodingException exception]; } } | | | | | | 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 102 103 104 105 106 107 108 109 | case '?': continue; default: @throw [OFInvalidEncodingException exception]; } } _printableStringValue = [string copy]; objc_autoreleasePoolPop(pool); } @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(); OFString *printableString; @try { if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || tagNumber != OF_ASN1_TAG_NUMBER_PRINTABLE_STRING || constructed) @throw [OFInvalidArgumentException exception]; if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; printableString = [OFString stringWithCString: DEREncodedContents.items encoding: OF_STRING_ENCODING_ASCII length: DEREncodedContents.count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithString: printableString]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)init |
︙ | ︙ |
Modified src/OFASN1UTF8String.h from [338855ca89] to [a4b45c5c6e].
︙ | ︙ | |||
38 39 40 41 42 43 44 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates a UTF8String with the specified string value. * | | | | < | | 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 | * @brief The string value. */ @property (readonly, nonatomic) OFString *stringValue; /** * @brief Creates a UTF8String with the specified string value. * * @param string The string value of the UTF8String * @return A new, autoreleased OFASN1UTF8String */ + (instancetype)stringWithString: (OFString *)string; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated UTF8String with the specified * string value. * * @param string The string value of the UTF8String * @return An initialized OFASN1UTF8String */ - (instancetype)initWithString: (OFString *)string OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated ASN.1 UTF8String with the specified * arguments. * * @param tagClass The tag class of the value's type * @param tagNumber The tag number of the value's type |
︙ | ︙ |
Modified src/OFASN1UTF8String.m from [92cd83c978] to [53a8c373a7].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1UTF8String @synthesize UTF8StringValue = _UTF8StringValue; | | | | | | | | | 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 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1UTF8String @synthesize UTF8StringValue = _UTF8StringValue; + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { _UTF8StringValue = [string copy]; } @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(); OFString *UTF8String; @try { if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || tagNumber != OF_ASN1_TAG_NUMBER_UTF8_STRING || constructed) @throw [OFInvalidArgumentException exception]; if (DEREncodedContents.itemSize != 1) @throw [OFInvalidArgumentException exception]; UTF8String = [OFString stringWithUTF8String: DEREncodedContents.items length: DEREncodedContents.count]; } @catch (id e) { [self release]; @throw e; } self = [self initWithString: UTF8String]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)init |
︙ | ︙ |
Modified tests/OFASN1DERParsingTests.m from [70f5ebfaac] to [6d6dab178a].
︙ | ︙ | |||
27 28 29 30 31 32 33 | OFArray *array; OFSet *set; OFEnumerator *enumerator; /* Boolean */ TEST(@"Parsing of boolean", ![[[OFData dataWithItems: "\x01\x01\x00" | | < | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | OFArray *array; OFSet *set; OFEnumerator *enumerator; /* Boolean */ TEST(@"Parsing of boolean", ![[[OFData dataWithItems: "\x01\x01\x00" count: 3] objectByParsingASN1DER] boolValue] && [[[OFData dataWithItems: "\x01\x01\xFF" count: 3] objectByParsingASN1DER] boolValue]) EXPECT_EXCEPTION(@"Detection of invalid boolean #1", OFInvalidFormatException, [[OFData dataWithItems: "\x01\x01\x01" count: 3] objectByParsingASN1DER]) EXPECT_EXCEPTION(@"Detection of invalid boolean #2", |
︙ | ︙ |
Modified tests/OFASN1DERRepresentationTests.m from [dadc73d11b] to [c3751ee953].
︙ | ︙ | |||
24 25 26 27 28 29 30 | { void *pool = objc_autoreleasePoolPush(); OFData *data; module = @"OFASN1BitString"; TEST(@"-[ASN1DERRepresentation]", (data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3]) && | | < | < | < | < | | < | | 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 | { void *pool = objc_autoreleasePoolPush(); OFData *data; module = @"OFASN1BitString"; TEST(@"-[ASN1DERRepresentation]", (data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3]) && [[[OFASN1BitString bitStringWithBitString: data length: 21] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" count: 6]] && (data = [OFData dataWithItems: "abcdefäöü" count: 12]) && [[[OFASN1BitString bitStringWithBitString: data length: 12 * 8] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]] && (data = [OFData dataWithItems: "" count: 0]) && [[[OFASN1BitString bitStringWithBitString: data length: 0] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x03\x01\x00" count: 3]]) module = @"OFASN1Boolean"; TEST(@"-[ASN1DERRepresentation]", [[[OFASN1Boolean booleanWithBool: false] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x01\x01\x00" count: 3]] && [[[OFASN1Boolean booleanWithBool: true] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x01\x01\xFF" count: 3]]) module = @"OFNull"; TEST(@"-[OFASN1DERRepresentation]", [[[OFNull null] ASN1DERRepresentation] isEqual: [OFData dataWithItems: "\x05\x00" count: 2]]) objc_autoreleasePoolPop(pool); |
︙ | ︙ |