From: Andreas Steffen Date: Fri, 1 Feb 2008 22:24:51 +0000 (-0000) Subject: added set_messageDigest() and get_messageDigest() methods X-Git-Tag: 4.1.11~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7734c01677514fbcb48a5d88f142ff351ece8dc9;p=thirdparty%2Fstrongswan.git added set_messageDigest() and get_messageDigest() methods --- diff --git a/src/libstrongswan/crypto/pkcs9.c b/src/libstrongswan/crypto/pkcs9.c index d7aecf3298..1003c90115 100644 --- a/src/libstrongswan/crypto/pkcs9.c +++ b/src/libstrongswan/crypto/pkcs9.c @@ -297,7 +297,20 @@ static chunk_t get_encoding(private_pkcs9_t *this) */ static chunk_t get_attribute(private_pkcs9_t *this, int oid) { - return chunk_empty; + iterator_t *iterator = this->attributes->create_iterator(this->attributes, TRUE); + chunk_t value = chunk_empty; + attribute_t *attribute; + + while (iterator->iterate(iterator, (void**)&attribute)) + { + if (attribute->oid == oid) + { + value = attribute->value; + break; + } + } + iterator->destroy(iterator); + return value; } /** @@ -310,6 +323,37 @@ static void set_attribute(private_pkcs9_t *this, int oid, chunk_t value) this->attributes->insert_last(this->attributes, (void*)attribute); } +/** + * Implements pkcs9_t.get_messageDigest + */ +static chunk_t get_messageDigest(private_pkcs9_t *this) +{ + const int oid = OID_PKCS9_MESSAGE_DIGEST; + chunk_t value = get_attribute(this, oid); + + if (value.ptr == NULL) + { + return chunk_empty; + } + if (!parse_asn1_simple_object(&value, asn1_attributeType(oid), 0, oid_names[oid].name)) + { + return chunk_empty; + } + return chunk_clone(value); +} + +/** + * Implements pkcs9_t.set_attribute + */ +static void set_messageDigest(private_pkcs9_t *this, chunk_t value) +{ + const int oid = OID_PKCS9_MESSAGE_DIGEST; + chunk_t messageDigest = asn1_simple_object(asn1_attributeType(oid), value); + + set_attribute(this, oid, messageDigest); + free(messageDigest.ptr); +} + /** * Implements pkcs9_t.destroy */ @@ -336,6 +380,8 @@ static private_pkcs9_t *pkcs9_create_empty(void) this->public.get_encoding = (chunk_t (*) (pkcs9_t*))get_encoding; this->public.get_attribute = (chunk_t (*) (pkcs9_t*,int))get_attribute; this->public.set_attribute = (void (*) (pkcs9_t*,int,chunk_t))set_attribute; + this->public.get_messageDigest = (chunk_t (*) (pkcs9_t*))get_messageDigest; + this->public.set_messageDigest = (void (*) (pkcs9_t*,chunk_t))set_messageDigest; this->public.destroy = (void (*) (pkcs9_t*))destroy; return this; diff --git a/src/libstrongswan/crypto/pkcs9.h b/src/libstrongswan/crypto/pkcs9.h index 8dbdb7c450..44915720cc 100644 --- a/src/libstrongswan/crypto/pkcs9.h +++ b/src/libstrongswan/crypto/pkcs9.h @@ -73,6 +73,22 @@ struct pkcs9_t { */ void (*set_attribute) (pkcs9_t *this, int oid, chunk_t value); + /** + * @brief gets a PKCS#9 messageDigest attribute + * + * @param this calling object + * @return messageDigest + */ + chunk_t (*get_messageDigest) (pkcs9_t *this); + + /** + * @brief add a PKCS#9 messageDigest attribute + * + * @param this calling object + * @param value messageDigest + */ + void (*set_messageDigest) (pkcs9_t *this, chunk_t value); + /** * @brief Destroys the PKCS#9 attribute list. *