diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2008-02-01 22:24:51 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2008-02-01 22:24:51 +0000 |
commit | 7734c01677514fbcb48a5d88f142ff351ece8dc9 (patch) | |
tree | b39023a52b4301d294f4d0f0359cc65dbef5bdae /src | |
parent | e8bfe74289ab319cf6b4ef94f271990bd63d9375 (diff) | |
download | strongswan-7734c01677514fbcb48a5d88f142ff351ece8dc9.tar.bz2 strongswan-7734c01677514fbcb48a5d88f142ff351ece8dc9.tar.xz |
added set_messageDigest() and get_messageDigest() methods
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/crypto/pkcs9.c | 48 | ||||
-rw-r--r-- | src/libstrongswan/crypto/pkcs9.h | 16 |
2 files changed, 63 insertions, 1 deletions
diff --git a/src/libstrongswan/crypto/pkcs9.c b/src/libstrongswan/crypto/pkcs9.c index d7aecf329..1003c9011 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; } /** @@ -311,6 +324,37 @@ static void set_attribute(private_pkcs9_t *this, int oid, chunk_t value) } /** + * 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 */ static void destroy(private_pkcs9_t *this) @@ -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 8dbdb7c45..44915720c 100644 --- a/src/libstrongswan/crypto/pkcs9.h +++ b/src/libstrongswan/crypto/pkcs9.h @@ -74,6 +74,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. * * @param this PKCS#9 attribute list to destroy |