2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-02-02 20:38:51 quinn
10 * Revision 1.1 1995/02/02 16:21:54 quinn
18 * Top level octet string en/decoder.
19 * Returns 1 on success, 0 on error.
21 int odr_octetstring(ODR o, ODR_OCT **p, int opt)
27 o->t_class = ODR_UNIVERSAL;
28 o->t_tag = ODR_OCTETSTRING;
30 if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
37 if (o->direction == ODR_PRINT)
39 fprintf(o->print, "OCTETSTRING(len=%d)\n", (*p)->len);
42 if (o->direction == ODR_DECODE && !*p)
44 *p = nalloc(o, sizeof(ODR_OCT));
49 return ber_octetstring(o, *p, cons);
53 * Friendlier interface to octetstring.
55 int odr_visiblestring(ODR o, char **p, int opt)
62 o->t_class = ODR_UNIVERSAL;
63 o->t_tag = ODR_VISIBLESTRING;
65 if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
72 if (o->direction == ODR_PRINT)
74 fprintf(o->print, "'%s'\n", *p);
77 t = nalloc(o, sizeof(ODR_OCT)); /* wrapper for octstring */
78 if (o->direction == ODR_ENCODE)
80 t->buf = (unsigned char *) *p;
81 t->size = t->len = strlen(*p);
89 if (!ber_octetstring(o, t, cons))
91 if (o->direction == ODR_DECODE)
94 *(*p + t->len) = '\0'; /* ber_octs reserves space for this */