From cd3280ce17fd7053ea632955e04182015372e2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Sat, 14 Oct 2006 05:37:10 +0000 Subject: [PATCH] Add der_parse_heim_oid git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18444 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/asn1/der_format.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/asn1/der_format.c b/lib/asn1/der_format.c index 32bbc1e93..fc3593456 100644 --- a/lib/asn1/der_format.c +++ b/lib/asn1/der_format.c @@ -105,7 +105,7 @@ der_print_hex_heim_integer (const heim_integer *data, char **p) } int -der_print_heim_oid (const heim_oid *oid, char **str) +der_print_heim_oid (const heim_oid *oid, char delim, char **str) { struct rk_strpool *p = NULL; int i; @@ -125,3 +125,40 @@ der_print_heim_oid (const heim_oid *oid, char **str) return ENOMEM; return 0; } + +int +der_parse_heim_oid (const char *str, const char *sep, heim_oid *data) +{ + char *s, *w, *brkt, *endptr; + unsigned int *c; + long l; + + data->length = 0; + data->components = NULL; + + if (sep == NULL) + sep = "."; + + s = strdup(str); + + for (w = strtok_r(s, sep, &brkt); + w != NULL; + w = strtok_r(NULL, sep, &brkt)) { + + c = realloc(data->components, + (data->length + 1) * sizeof(data->components[0])); + if (c == NULL) { + der_free_oid(data); + return ENOMEM; + } + data->components = c; + + l = strtol(w, &endptr, 10); + if (*endptr != '\0' || l < 0 || l > INT_MAX) { + der_free_oid(data); + return EINVAL; + } + data->components[data->length++] = l; + } + return 0; +}