Initial revision
authorSebastian Hammer <quinn@indexdata.com>
Fri, 3 Feb 1995 17:04:36 +0000 (17:04 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Fri, 3 Feb 1995 17:04:36 +0000 (17:04 +0000)
odr/ber_oid.c [new file with mode: 0644]
odr/odr_oid.c [new file with mode: 0644]
odr/odr_use.c [new file with mode: 0644]

diff --git a/odr/ber_oid.c b/odr/ber_oid.c
new file mode 100644 (file)
index 0000000..07f2ae3
--- /dev/null
@@ -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 <odr.h>
+
+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 (file)
index 0000000..ed87f33
--- /dev/null
@@ -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 <odr.h>
+
+/*
+ * 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 (file)
index 0000000..4d69073
--- /dev/null
@@ -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 <odr.h>
+#include <odr_use.h>
+
+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);
+}