diff options
author | Stef Walter <stefw@gnome.org> | 2013-03-18 20:59:57 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-18 21:54:48 +0100 |
commit | 128239732a5b7e184d5d9c505402630ee9215080 (patch) | |
tree | 8432e2758971c4eecf56881cfe55803831985079 | |
parent | 1ad9f98b11f3f0d411bf9517f1dc8985ea3dbe2a (diff) | |
download | p11-kit-128239732a5b7e184d5d9c505402630ee9215080.tar.gz |
attrs: Change p11_attrs_to_string() to allow static templates
Allow passing the number of attributes to print, which lets us use
this directly on templates passed in by callers of the PKCS#11 API.
-rw-r--r-- | common/attrs.c | 13 | ||||
-rw-r--r-- | common/attrs.h | 3 | ||||
-rw-r--r-- | common/tests/test-attrs.c | 6 | ||||
-rw-r--r-- | trust/tests/frob-nss-trust.c | 2 |
4 files changed, 16 insertions, 8 deletions
diff --git a/common/attrs.c b/common/attrs.c index a438264..5539789 100644 --- a/common/attrs.c +++ b/common/attrs.c @@ -813,12 +813,14 @@ format_attribute (p11_buffer *buffer, static void format_attributes (p11_buffer *buffer, - const CK_ATTRIBUTE *attrs) + const CK_ATTRIBUTE *attrs, + int count) { CK_BBOOL first = CK_TRUE; - int count, i; + int i; - count = p11_attrs_count (attrs); + if (count < 0) + count = p11_attrs_count (attrs); buffer_append_printf (buffer, "(%d) [", count); for (i = 0; i < count; i++) { if (first) @@ -832,12 +834,13 @@ format_attributes (p11_buffer *buffer, } char * -p11_attrs_to_string (const CK_ATTRIBUTE *attrs) +p11_attrs_to_string (const CK_ATTRIBUTE *attrs, + int count) { p11_buffer buffer; if (!p11_buffer_init_null (&buffer, 128)) return_val_if_reached (NULL); - format_attributes (&buffer, attrs); + format_attributes (&buffer, attrs, count); return p11_buffer_steal (&buffer, NULL); } diff --git a/common/attrs.h b/common/attrs.h index f6eb950..87e0af1 100644 --- a/common/attrs.h +++ b/common/attrs.h @@ -104,7 +104,8 @@ bool p11_attrs_matchn (const CK_ATTRIBUTE *attrs, const CK_ATTRIBUTE *match, CK_ULONG count); -char * p11_attrs_to_string (const CK_ATTRIBUTE *attrs); +char * p11_attrs_to_string (const CK_ATTRIBUTE *attrs, + int count); char * p11_attr_to_string (const CK_ATTRIBUTE *attr); diff --git a/common/tests/test-attrs.c b/common/tests/test-attrs.c index f1e6d91..61fcef3 100644 --- a/common/tests/test-attrs.c +++ b/common/tests/test-attrs.c @@ -474,9 +474,13 @@ test_to_string (CuTest *tc) CuAssertStrEquals (tc, "{ CKA_LABEL = (3) \"yay\" }", string); free (string); - string = p11_attrs_to_string (attrs); + string = p11_attrs_to_string (attrs, -1); CuAssertStrEquals (tc, "(2) [ { CKA_LABEL = (3) \"yay\" }, { CKA_VALUE = (5) NOT-PRINTED } ]", string); free (string); + + string = p11_attrs_to_string (attrs, 1); + CuAssertStrEquals (tc, "(1) [ { CKA_LABEL = (3) \"yay\" } ]", string); + free (string); } static void diff --git a/trust/tests/frob-nss-trust.c b/trust/tests/frob-nss-trust.c index 790362f..da76795 100644 --- a/trust/tests/frob-nss-trust.c +++ b/trust/tests/frob-nss-trust.c @@ -68,7 +68,7 @@ dump_object (P11KitIter *iter, else name = strdup ("unknown"); - string = p11_attrs_to_string (attrs); + string = p11_attrs_to_string (attrs, -1); printf ("\"%s\" = %s\n", name, string); free (string); |