From 4d318c79b27925911f5822c5b8eaef2624bc9055 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Mon, 11 Feb 2008 17:52:38 +0000 Subject: [PATCH] Utility attribute function to retrieve attribute data from an expected type. Useful for many attributes which are single valued and can only have one type. --- crypto/x509/x509.h | 2 ++ crypto/x509/x509_att.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index 4f40712448..a3a7c441b3 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -1080,6 +1080,8 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x, STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, const char *attrname, int type, const unsigned char *bytes, int len); +void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, + ASN1_OBJECT *obj, int lastpos, int type); X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, int atrtype, const void *data, int len); X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, diff --git a/crypto/x509/x509_att.c b/crypto/x509/x509_att.c index 2a8cc0c4b0..9245bfd9f5 100644 --- a/crypto/x509/x509_att.c +++ b/crypto/x509/x509_att.c @@ -193,6 +193,22 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, return ret; } +void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x, + ASN1_OBJECT *obj, int lastpos, int type) +{ + int i; + X509_ATTRIBUTE *at; + i = X509at_get_attr_by_OBJ(x, obj, lastpos); + if (i == -1) + return NULL; + if ((lastpos <= -2) && (X509at_get_attr_by_OBJ(x, obj, i) != -1)) + return NULL; + at = X509at_get_attr(x, i); + if (lastpos <= -3 && (X509_ATTRIBUTE_count(at) != 1)) + return NULL; + return X509_ATTRIBUTE_get0_data(at, type, 0, NULL); +} + X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, int atrtype, const void *data, int len) {