Break out some ASN.1 to OFString conversion functionality
This commit is contained in:
parent
c804feb98b
commit
cf45a92e0b
2 changed files with 32 additions and 16 deletions
|
@ -39,4 +39,6 @@
|
||||||
- (OFDictionary*)issuer;
|
- (OFDictionary*)issuer;
|
||||||
- (OFDictionary*)subject;
|
- (OFDictionary*)subject;
|
||||||
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name;
|
- (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name;
|
||||||
|
- (OFString*)X509_stringFromASN1Object: (ASN1_OBJECT*)obj;
|
||||||
|
- (OFString*) X509_stringFromASN1String: (ASN1_STRING*)str;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -104,30 +104,17 @@
|
||||||
OFMutableDictionary *dict = [OFMutableDictionary dictionary];
|
OFMutableDictionary *dict = [OFMutableDictionary dictionary];
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
int len, buf_len = 256;
|
|
||||||
OFString *key, *value;
|
OFString *key, *value;
|
||||||
char *buf = [self allocMemoryWithSize: buf_len];
|
|
||||||
X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
|
X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i);
|
||||||
ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);
|
ASN1_OBJECT *obj = X509_NAME_ENTRY_get_object(entry);
|
||||||
while ((len = OBJ_obj2txt(buf, buf_len, obj, 1)) > buf_len) {
|
ASN1_STRING *str = X509_NAME_ENTRY_get_data(entry);
|
||||||
buf_len = len;
|
key = [self X509_stringFromASN1Object: obj];
|
||||||
[self resizeMemory: buf
|
|
||||||
toSize: buf_len];
|
|
||||||
}
|
|
||||||
key = [OFString stringWithUTF8String: buf];
|
|
||||||
[self freeMemory: buf];
|
|
||||||
|
|
||||||
if ([dict objectForKey: key] == nil)
|
if ([dict objectForKey: key] == nil)
|
||||||
[dict setObject: [OFList list]
|
[dict setObject: [OFList list]
|
||||||
forKey: key];
|
forKey: key];
|
||||||
|
|
||||||
if (ASN1_STRING_to_UTF8((unsigned char**)&buf,
|
value = [self X509_stringFromASN1String: str];
|
||||||
X509_NAME_ENTRY_get_data(entry)) < 0)
|
|
||||||
@throw [OFInvalidEncodingException
|
|
||||||
exceptionWithClass: isa];
|
|
||||||
value = [OFString stringWithUTF8String: buf];
|
|
||||||
OPENSSL_free(buf);
|
|
||||||
|
|
||||||
[[dict objectForKey: key] appendObject: value];
|
[[dict objectForKey: key] appendObject: value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,4 +124,31 @@
|
||||||
|
|
||||||
return [dict autorelease];
|
return [dict autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (OFString*)X509_stringFromASN1Object: (ASN1_OBJECT*)obj
|
||||||
|
{
|
||||||
|
int len, buf_len = 256;
|
||||||
|
char *buf = [self allocMemoryWithSize: buf_len];
|
||||||
|
OFString *ret;
|
||||||
|
while ((len = OBJ_obj2txt(buf, buf_len, obj, 1)) > buf_len) {
|
||||||
|
buf_len = len;
|
||||||
|
[self resizeMemory: buf
|
||||||
|
toSize: buf_len];
|
||||||
|
}
|
||||||
|
ret = [OFString stringWithUTF8String: buf];
|
||||||
|
[self freeMemory: buf];
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (OFString*) X509_stringFromASN1String: (ASN1_STRING*)str
|
||||||
|
{
|
||||||
|
char *buf;
|
||||||
|
OFString *ret;
|
||||||
|
if (ASN1_STRING_to_UTF8((unsigned char**)&buf, str) < 0)
|
||||||
|
@throw [OFInvalidEncodingException exceptionWithClass: isa];
|
||||||
|
ret = [OFString stringWithUTF8String: buf];
|
||||||
|
OPENSSL_free(buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Reference in a new issue