Index: src/X509Certificate.h ================================================================== --- src/X509Certificate.h +++ src/X509Certificate.h @@ -39,14 +39,17 @@ #define OID_SRVName @"1.3.6.1.5.5.7.8.7" @interface X509Certificate: OFObject { X509 *crt; + OFDictionary *issuer; + OFDictionary *subject; + OFDictionary *subjectAlternativeName; } #ifdef OF_HAVE_PROPERTIES -// @property (opts) Type *name; +@property (readonly) OFDictionary *issuer, *subject, *subjectAlternativeName; #endif - initWithFile: (OFString*)file; - initWithX509Struct: (X509*)cert; - (OFDictionary*)issuer; Index: src/X509Certificate.m ================================================================== --- src/X509Certificate.m +++ src/X509Certificate.m @@ -24,10 +24,11 @@ #include #import "X509Certificate.h" #import +#import #import #import #import #import #import @@ -77,30 +78,45 @@ return self; } - (void)dealloc { + [issuer release]; + [subject release]; + [subjectAlternativeName release]; + if (crt != NULL) X509_free(crt); [super dealloc]; } - (OFDictionary*)issuer { - X509_NAME *name = X509_get_issuer_name(crt); - return [self X509_dictionaryFromX509Name: name]; + if (issuer == nil) { + X509_NAME *name = X509_get_issuer_name(crt); + issuer = [[self X509_dictionaryFromX509Name: name] retain]; + } + + return issuer; } - (OFDictionary*)subject { - X509_NAME *name = X509_get_subject_name(crt); - return [self X509_dictionaryFromX509Name: name]; + if (subject == nil) { + X509_NAME *name = X509_get_subject_name(crt); + subject = [[self X509_dictionaryFromX509Name: name] retain]; + } + + return subject; } - (OFDictionary*)subjectAlternativeName { + if (subjectAlternativeName != nil) + return subjectAlternativeName; + int i = -1, j; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFMutableDictionary *ret = [OFMutableDictionary dictionary]; while ((i = X509_get_ext_by_NID(crt, NID_subject_alt_name, i)) != -1) { @@ -220,11 +236,11 @@ [ret makeImmutable]; [ret retain]; [pool release]; - return [ret autorelease]; + return (subjectAlternativeName = ret); } - (OFDictionary*)X509_dictionaryFromX509Name: (X509_NAME*)name { int i;