Migrated pubkey_cert to INIT/METHOD macros

This commit is contained in:
Andreas Steffen
2011-09-28 03:28:43 +02:00
parent de13eab0e6
commit 7c1a28d939
+48 -69
View File
@@ -50,35 +50,26 @@ struct private_pubkey_cert_t {
refcount_t ref; refcount_t ref;
}; };
/** METHOD(certificate_t, get_type, certificate_type_t,
* Implementation of certificate_t.get_type private_pubkey_cert_t *this)
*/
static certificate_type_t get_type(private_pubkey_cert_t *this)
{ {
return CERT_TRUSTED_PUBKEY; return CERT_TRUSTED_PUBKEY;
} }
/** METHOD(certificate_t, get_subject, identification_t*,
* Implementation of certificate_t.get_subject private_pubkey_cert_t *this)
*/
static identification_t* get_subject(private_pubkey_cert_t *this)
{ {
return this->subject; return this->subject;
} }
/** METHOD(certificate_t, get_issuer, identification_t*,
* Implementation of certificate_t.get_issuer private_pubkey_cert_t *this)
*/
static identification_t* get_issuer(private_pubkey_cert_t *this)
{ {
return this->issuer; return this->issuer;
} }
/** METHOD(certificate_t, has_subject, id_match_t,
* Implementation of certificate_t.has_subject. private_pubkey_cert_t *this, identification_t *subject)
*/
static id_match_t has_subject(private_pubkey_cert_t *this,
identification_t *subject)
{ {
if (subject->get_type(subject) == ID_KEY_ID) if (subject->get_type(subject) == ID_KEY_ID)
{ {
@@ -97,19 +88,14 @@ static id_match_t has_subject(private_pubkey_cert_t *this,
return ID_MATCH_NONE; return ID_MATCH_NONE;
} }
/** METHOD(certificate_t, has_issuer, id_match_t,
* Implementation of certificate_t.has_subject. private_pubkey_cert_t *this, identification_t *issuer)
*/
static id_match_t has_issuer(private_pubkey_cert_t *this,
identification_t *issuer)
{ {
return ID_MATCH_NONE; return ID_MATCH_NONE;
} }
/** METHOD(certificate_t, equals, bool,
* Implementation of certificate_t.equals. private_pubkey_cert_t *this, certificate_t *other)
*/
static bool equals(private_pubkey_cert_t *this, certificate_t *other)
{ {
public_key_t *other_key; public_key_t *other_key;
@@ -126,28 +112,22 @@ static bool equals(private_pubkey_cert_t *this, certificate_t *other)
return FALSE; return FALSE;
} }
/** METHOD(certificate_t, issued_by, bool,
* Implementation of certificate_t.issued_by private_pubkey_cert_t *this, certificate_t *issuer)
*/
static bool issued_by(private_pubkey_cert_t *this, certificate_t *issuer)
{ {
return equals(this, issuer); return equals(this, issuer);
} }
/** METHOD(certificate_t, get_public_key, public_key_t*,
* Implementation of certificate_t.get_public_key private_pubkey_cert_t *this)
*/
static public_key_t* get_public_key(private_pubkey_cert_t *this)
{ {
this->key->get_ref(this->key); this->key->get_ref(this->key);
return this->key; return this->key;
} }
/** METHOD(certificate_t, get_validity, bool,
* Implementation of certificate_t.get_validity. private_pubkey_cert_t *this, time_t *when, time_t *not_before,
*/ time_t *not_after)
static bool get_validity(private_pubkey_cert_t *this, time_t *when,
time_t *not_before, time_t *not_after)
{ {
if (not_before) if (not_before)
{ {
@@ -160,28 +140,21 @@ static bool get_validity(private_pubkey_cert_t *this, time_t *when,
return TRUE; return TRUE;
} }
/** METHOD(certificate_t, get_encoding, bool,
* Implementation of certificate_t.get_encoding. private_pubkey_cert_t *this, cred_encoding_type_t type, chunk_t *encoding)
*/
static bool get_encoding(private_pubkey_cert_t *this, cred_encoding_type_t type,
chunk_t *encoding)
{ {
return this->key->get_encoding(this->key, type, encoding); return this->key->get_encoding(this->key, type, encoding);
} }
/** METHOD(certificate_t, get_ref, certificate_t*,
* Implementation of certificate_t.get_ref private_pubkey_cert_t *this)
*/
static private_pubkey_cert_t* get_ref(private_pubkey_cert_t *this)
{ {
ref_get(&this->ref); ref_get(&this->ref);
return this; return &this->public.interface;
} }
/** METHOD(certificate_t, destroy, void,
* Implementation of pubkey_cert_t.destroy private_pubkey_cert_t *this)
*/
static void destroy(private_pubkey_cert_t *this)
{ {
if (ref_put(&this->ref)) if (ref_put(&this->ref))
{ {
@@ -197,25 +170,31 @@ static void destroy(private_pubkey_cert_t *this)
*/ */
static pubkey_cert_t *pubkey_cert_create(public_key_t *key) static pubkey_cert_t *pubkey_cert_create(public_key_t *key)
{ {
private_pubkey_cert_t *this = malloc_thing(private_pubkey_cert_t); private_pubkey_cert_t *this;
chunk_t fingerprint; chunk_t fingerprint;
this->public.interface.get_type = (certificate_type_t (*)(certificate_t *this))get_type; INIT(this,
this->public.interface.get_subject = (identification_t* (*)(certificate_t *this))get_subject; .public = {
this->public.interface.get_issuer = (identification_t* (*)(certificate_t *this))get_issuer; .interface = {
this->public.interface.has_subject = (id_match_t (*)(certificate_t*, identification_t *subject))has_subject; .get_type = _get_type,
this->public.interface.has_issuer = (id_match_t (*)(certificate_t*, identification_t *issuer))has_issuer; .get_subject = _get_subject,
this->public.interface.issued_by = (bool (*)(certificate_t *this, certificate_t *issuer))issued_by; .get_issuer = _get_issuer,
this->public.interface.get_public_key = (public_key_t* (*)(certificate_t *this))get_public_key; .has_subject = _has_subject,
this->public.interface.get_validity = (bool (*)(certificate_t*, time_t *when, time_t *, time_t*))get_validity; .has_issuer = _has_issuer,
this->public.interface.get_encoding = (bool (*)(certificate_t*,cred_encoding_type_t,chunk_t*))get_encoding; .issued_by = _issued_by,
this->public.interface.equals = (bool (*)(certificate_t*, certificate_t *other))equals; .get_public_key = _get_public_key,
this->public.interface.get_ref = (certificate_t* (*)(certificate_t *this))get_ref; .get_validity = _get_validity,
this->public.interface.destroy = (void (*)(certificate_t *this))destroy; .get_encoding = _get_encoding,
.equals = _equals,
.get_ref = _get_ref,
.destroy = _destroy,
},
},
.ref = 1,
.key = key,
.issuer = identification_create_from_encoding(ID_ANY, chunk_empty),
);
this->ref = 1;
this->key = key;
this->issuer = identification_create_from_encoding(ID_ANY, chunk_empty);
if (key->get_fingerprint(key, KEYID_PUBKEY_INFO_SHA1, &fingerprint)) if (key->get_fingerprint(key, KEYID_PUBKEY_INFO_SHA1, &fingerprint))
{ {
this->subject = identification_create_from_encoding(ID_KEY_ID, fingerprint); this->subject = identification_create_from_encoding(ID_KEY_ID, fingerprint);