From 82c1521f196b83c0ede4200b21eb25ed86bbf48e Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 3 Feb 1995 17:04:36 +0000 Subject: [PATCH] Initial revision --- odr/ber_oid.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ odr/odr_oid.c | 43 +++++++++++++++++++++++++++ odr/odr_use.c | 42 +++++++++++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 odr/ber_oid.c create mode 100644 odr/odr_oid.c create mode 100644 odr/odr_use.c diff --git a/odr/ber_oid.c b/odr/ber_oid.c new file mode 100644 index 0000000..07f2ae3 --- /dev/null +++ b/odr/ber_oid.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 1994, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: ber_oid.c,v $ + * Revision 1.1 1995-02-03 17:04:36 quinn + * Initial revision + * + */ + +#include + +int ber_oid(ODR o, Odr_oid *p) +{ + int len; + unsigned char *lenp; + int pos, n, res, id; + unsigned char octs[8]; + + switch (o->direction) + { + case ODR_DECODE: + if ((res = ber_declen(o->bp, &len)) < 1) + return 0; + if (len < 0) + return 0; + o->bp += res; + o->left -= res; + if (len == 0) + { + *p = -1; + return 1; + } + p[0] = *o->bp / 40; + if (p[0] > 2) + p[0] = 2; + p[1] = *o->bp - p[0] * 40; + o->bp++; + o->left--; + pos = 2; + len--; + while (len) + { + p[pos] = 0; + do + { + if (!len) + return 0; + p[pos] <<= 7; + p[pos] |= *o->bp & 0X7F; + len--; + o->left--; + } + while (*(o->bp++) & 0X80); + pos++; + } + p[pos] = -1; + return 1; + case ODR_ENCODE: + /* we'll allow ourselves the quiet luxury of only doing encodings + shorter than 127 */ + lenp = o->bp; + o->bp++; + o->left--; + if (p[0] < 0 && p[1] <= 0) + return 0; + p[1] = p[0] * 40 + p[1]; + for (pos = 1; p[pos] >= 0; pos++) + { + id = p[pos]; + n = 0; + do + { + octs[n++] = id &= 0X7F; + id >>= 7; + } + while (id); + if (n > o->left) + return 0; + o->left -= n; + while (n--) + *(o->bp++) = octs[n] | ((n > 0) << 7); + } + if (ber_enclen(lenp, (o->bp - lenp) - 1, 1, 1) != 1) + return 0; + return 1; + default: return 0; + } +} diff --git a/odr/odr_oid.c b/odr/odr_oid.c new file mode 100644 index 0000000..ed87f33 --- /dev/null +++ b/odr/odr_oid.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 1994, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: odr_oid.c,v $ + * Revision 1.1 1995-02-03 17:04:38 quinn + * Initial revision + * + * + */ + +#include + +/* + * Top level oid en/decoder. + * Returns 1 on success, 0 on error. + */ +int odr_oid(ODR o, Odr_oid **p, int opt) +{ + int res, cons = 0; + + if (o->t_class < 0) + { + o->t_class = ODR_UNIVERSAL; + o->t_tag = ODR_OID; + } + if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0) + return 0; + if (!res || cons) + { + *p = 0; + return opt; + } + if (o->direction == ODR_PRINT) + { + fprintf(o->print, "OID\n"); + return 1; + } + if (o->direction == ODR_DECODE && !*p) + *p = nalloc(o, ODR_OID_SIZE); + return ber_oid(o, *p); +} diff --git a/odr/odr_use.c b/odr/odr_use.c new file mode 100644 index 0000000..4d69073 --- /dev/null +++ b/odr/odr_use.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 1994, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: odr_use.c,v $ + * Revision 1.1 1995-02-03 17:04:39 quinn + * Initial revision + * + */ + +#include +#include + +int odr_external(ODR o, Odr_external **p, int opt) +{ + Odr_external *pp; + + odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL); + if (!odr_sequence_begin(o, p, sizeof(Odr_external))) + return opt; + pp = *p; + return + odr_oid(o, &pp->direct_reference, 1) && + odr_integer(o, &pp->indirect_reference, 1) && + odr_graphicstring(o, &pp->descriptor, 1) && + odr_implicit(o, odr_octetstring, &pp->octet_aligned, ODR_CONTEXT, + 1, 0) && + odr_sequence_end(o); +} + +int odr_visiblestring(ODR o, char **p, int opt) +{ + return odr_implicit(o, odr_cstring, p, ODR_UNIVERSAL, ODR_VISIBLESTRING, + opt); +} + +int odr_graphicstring(ODR o, char **p, int opt) +{ + return odr_implicit(o, odr_cstring, p, ODR_UNIVERSAL, ODR_GRAPHICSTRING, + opt); +} -- 1.7.10.4