Eliminate some unused ASN.1 encoding primitives
authorGreg Hudson <ghudson@mit.edu>
Sat, 11 Feb 2012 23:25:08 +0000 (23:25 +0000)
committerGreg Hudson <ghudson@mit.edu>
Sat, 11 Feb 2012 23:25:08 +0000 (23:25 +0000)
asn1_make.c contained a variety of utility functions, most of which we
no longer needed.  Fold make_tag into asn1_encode.c and get rid of
asn1_make.c and asn1_make.h.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25688 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/Makefile.in
src/lib/krb5/asn.1/asn1_encode.c
src/lib/krb5/asn.1/asn1_k_encode.c
src/lib/krb5/asn.1/asn1_make.c [deleted file]
src/lib/krb5/asn.1/asn1_make.h [deleted file]
src/lib/krb5/asn.1/deps
src/lib/krb5/asn.1/ldap_key_seq.c

index 38bcf6a45a62e7b431abe354adc781d3c237dbba..223a00f649c0232881b1036835538bc6e04eb20c 100644 (file)
@@ -16,7 +16,6 @@ STLIBOBJS= \
        asn1_k_decode_sam.o\
        asn1_encode.o\
        asn1_get.o\
-       asn1_make.o\
        asn1buf.o\
        krb5_decode.o\
        krb5_decode_kdc.o\
@@ -32,7 +31,6 @@ SRCS= \
        $(srcdir)/asn1_k_decode_sam.c\
        $(srcdir)/asn1_encode.c\
        $(srcdir)/asn1_get.c\
-       $(srcdir)/asn1_make.c\
        $(srcdir)/asn1buf.c\
        $(srcdir)/krb5_decode.c\
        $(srcdir)/krb5_decode_kdc.c\
@@ -48,7 +46,6 @@ OBJS= \
        $(OUTPRE)asn1_k_decode_sam.$(OBJEXT)\
        $(OUTPRE)asn1_encode.$(OBJEXT)\
        $(OUTPRE)asn1_get.$(OBJEXT)\
-       $(OUTPRE)asn1_make.$(OBJEXT)\
        $(OUTPRE)asn1buf.$(OBJEXT)\
        $(OUTPRE)krb5_decode.$(OBJEXT)\
        $(OUTPRE)krb5_decode_kdc.$(OBJEXT)\
index e53feea7e84754db8d7dfed1bd73102ec89b0973..f5a4cac82a2cfc7fcd5df1d1128a57addd6b1d6e 100644 (file)
@@ -27,7 +27,6 @@
 /* ASN.1 primitive encoders */
 
 #include "asn1_encode.h"
-#include "asn1_make.h"
 
 asn1_error_code
 asn1_encode_boolean(asn1buf *buf, asn1_intmax val, unsigned int *retlen)
@@ -172,6 +171,71 @@ asn1_encode_bitstring(asn1buf *buf, unsigned char *const *val,
     return asn1buf_insert_octet(buf, '\0');
 }
 
+static asn1_error_code
+make_tag(asn1buf *buf, const taginfo *t, unsigned int *retlen)
+{
+    asn1_error_code ret;
+    asn1_tagnum tag_copy;
+    unsigned int sum = 0, length, len_copy;
+
+    if (t->tagnum > ASN1_TAGNUM_MAX)
+        return ASN1_OVERFLOW;
+
+    /* Encode the length of the content within the tag. */
+    if (t->length < 128) {
+        ret = asn1buf_insert_octet(buf, t->length & 0x7F);
+        if (ret)
+            return ret;
+        length = 1;
+    } else {
+        length = 0;
+        for (len_copy = t->length; len_copy != 0; len_copy >>= 8) {
+            ret = asn1buf_insert_octet(buf, len_copy & 0xFF);
+            if (ret)
+                return ret;
+            length++;
+        }
+        ret = asn1buf_insert_octet(buf, 0x80 | (length & 0x7F));
+        if (ret)
+            return ret;
+        length++;
+    }
+    sum += length;
+
+    /* Encode the tag and construction bit. */
+    if (t->tagnum < 31) {
+        ret = asn1buf_insert_octet(buf,
+                                   t->asn1class | t->construction | t->tagnum);
+        if (ret)
+            return ret;
+        length = 1;
+    } else {
+        tag_copy = t->tagnum;
+        length = 0;
+        ret = asn1buf_insert_octet(buf, tag_copy & 0x7F);
+        if (ret)
+            return ret;
+        tag_copy >>= 7;
+        length++;
+
+        for (; tag_copy != 0; tag_copy >>= 7) {
+            ret = asn1buf_insert_octet(buf, 0x80 | (tag_copy & 0x7F));
+            if (ret)
+                return ret;
+            length++;
+        }
+
+        ret = asn1buf_insert_octet(buf, t->asn1class | t->construction | 0x1F);
+        if (ret)
+            return ret;
+        length++;
+    }
+    sum += length;
+
+    *retlen = sum;
+    return 0;
+}
+
 /*
  * ASN.1 constructed type encoder engine
  *
@@ -381,9 +445,7 @@ krb5int_asn1_encode_type(asn1buf *buf, const void *val,
             return retval;
         if (!tag->implicit) {
             unsigned int tlen;
-            retval = asn1_make_tag(buf, rettag->asn1class,
-                                   rettag->construction, rettag->tagnum,
-                                   rettag->length, &tlen);
+            retval = make_tag(buf, rettag, &tlen);
             if (retval)
                 return retval;
             rettag->length += tlen;
@@ -441,8 +503,7 @@ encode_type_and_tag(asn1buf *buf, const void *val, const struct atype_info *a,
     retval = krb5int_asn1_encode_type(buf, val, a, &t);
     if (retval)
         return retval;
-    retval = asn1_make_tag(buf, t.asn1class, t.construction, t.tagnum,
-                           t.length, &tlen);
+    retval = make_tag(buf, &t, &tlen);
     if (retval)
         return retval;
     *retlen = t.length + tlen;
index 1db2f574856ce77793f66eb6a4cf766a086ef8a8..fdaf097caedf6adf087a6963675e16f5748fd4da 100644 (file)
@@ -24,7 +24,6 @@
  * or implied warranty.
  */
 
-#include "asn1_make.h"
 #include "asn1_encode.h"
 #include <assert.h>
 
diff --git a/src/lib/krb5/asn.1/asn1_make.c b/src/lib/krb5/asn.1/asn1_make.c
deleted file mode 100644 (file)
index 310282d..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* lib/krb5/asn.1/asn1_make.c */
-/*
- * Copyright 1994 by the Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- *   require a specific license from the United States Government.
- *   It is the responsibility of any person or organization contemplating
- *   export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission.  Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose.  It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "asn1_make.h"
-
-asn1_error_code
-asn1_make_etag(asn1buf *buf, asn1_class asn1class, asn1_tagnum tagnum,
-               unsigned int in_len, unsigned int *retlen)
-{
-    return asn1_make_tag(buf,asn1class,CONSTRUCTED,tagnum,in_len,retlen);
-}
-
-asn1_error_code
-asn1_make_tag(asn1buf *buf, asn1_class asn1class,
-              asn1_construction construction, asn1_tagnum tagnum,
-              unsigned int in_len, unsigned int *retlen)
-{
-    asn1_error_code retval;
-    unsigned int sumlen=0, length;
-
-    if (tagnum > ASN1_TAGNUM_MAX) return ASN1_OVERFLOW;
-
-    retval = asn1_make_length(buf,in_len, &length);
-    if (retval) return retval;
-    sumlen += length;
-    retval = asn1_make_id(buf,asn1class,construction,tagnum,&length);
-    if (retval) return retval;
-    sumlen += length;
-
-    *retlen = sumlen;
-    return 0;
-}
-
-asn1_error_code
-asn1_make_length(asn1buf *buf, const unsigned int in_len, unsigned int *retlen)
-{
-    asn1_error_code retval;
-
-    if (in_len < 128) {
-        retval = asn1buf_insert_octet(buf, (asn1_octet)(in_len&0x7F));
-        if (retval) return retval;
-        *retlen = 1;
-    } else {
-        int in_copy=in_len, length=0;
-
-        while (in_copy != 0) {
-            retval = asn1buf_insert_octet(buf, (asn1_octet)(in_copy&0xFF));
-            if (retval) return retval;
-            in_copy = in_copy >> 8;
-            length++;
-        }
-        retval = asn1buf_insert_octet(buf, (asn1_octet) (0x80 | (asn1_octet)(length&0x7F)));
-        if (retval) return retval;
-        length++;
-        *retlen = length;
-    }
-
-    return 0;
-}
-
-asn1_error_code
-asn1_make_id(asn1buf *buf, asn1_class asn1class,
-             asn1_construction construction, asn1_tagnum tagnum,
-             unsigned int *retlen)
-{
-    asn1_error_code retval;
-
-    if (tagnum < 31) {
-        retval = asn1buf_insert_octet(buf, (asn1_octet) (asn1class | construction |
-                                                         (asn1_octet)tagnum));
-        if (retval) return retval;
-        *retlen = 1;
-    } else {
-        asn1_tagnum tagcopy = tagnum;
-        int length = 0;
-
-        retval = asn1buf_insert_octet(buf, (asn1_octet)(tagcopy&0x7F));
-        if (retval) return retval;
-        tagcopy >>= 7;
-        length++;
-
-        for (; tagcopy != 0; tagcopy >>= 7) {
-            retval = asn1buf_insert_octet(buf, (asn1_octet) (0x80 | (asn1_octet)(tagcopy&0x7F)));
-            if (retval) return retval;
-            length++;
-        }
-
-        retval = asn1buf_insert_octet(buf, (asn1_octet) (asn1class | construction | 0x1F));
-        if (retval) return retval;
-        length++;
-        *retlen = length;
-    }
-
-    return 0;
-}
-
-asn1_error_code
-asn1_make_sequence(asn1buf *buf, const unsigned int seq_len,
-                   unsigned int *retlen)
-{
-    asn1_error_code retval;
-    unsigned int len, sum=0;
-
-    retval = asn1_make_length(buf,seq_len,&len);
-    if (retval) return retval;
-    sum += len;
-    retval = asn1_make_id(buf,UNIVERSAL,CONSTRUCTED,ASN1_SEQUENCE,&len);
-    if (retval) return retval;
-    sum += len;
-
-    *retlen = sum;
-    return 0;
-}
-
-asn1_error_code
-asn1_make_set(asn1buf *buf, const unsigned int set_len, unsigned int *retlen)
-{
-    asn1_error_code retval;
-    unsigned int len, sum=0;
-
-    retval = asn1_make_length(buf,set_len,&len);
-    if (retval) return retval;
-    sum += len;
-    retval = asn1_make_id(buf,UNIVERSAL,CONSTRUCTED,ASN1_SET,&len);
-    if (retval) return retval;
-    sum += len;
-
-    *retlen = sum;
-    return 0;
-}
-
-asn1_error_code
-asn1_make_string(asn1buf *buf, const unsigned int length, const char *string,
-                 int *retlen)
-{
-    asn1_error_code retval;
-
-    retval = asn1buf_insert_charstring(buf,length,string);
-    if (retval) return retval;
-
-    *retlen = length;
-    return 0;
-}
diff --git a/src/lib/krb5/asn.1/asn1_make.h b/src/lib/krb5/asn.1/asn1_make.h
deleted file mode 100644 (file)
index c07bf8c..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* lib/krb5/asn.1/asn1_make.h */
-/*
- * Copyright 1994 by the Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- *   require a specific license from the United States Government.
- *   It is the responsibility of any person or organization contemplating
- *   export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission.  Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose.  It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __ASN1_MAKE_H__
-#define __ASN1_MAKE_H__
-
-#include "k5-int.h"
-#include "krbasn1.h"
-#include "asn1buf.h"
-
-/*
- * Overview
- *
- *   Each of these procedures constructs a subpart of an ASN.1
- *   primitive in a coding buffer.
- *
- *  Operations
- *
- *    asn1_make_etag
- *    asn1_make_sequence
- *    asn1_make_set
- *    asn1_make_tag
- *    asn1_make_string
- */
-
-asn1_error_code asn1_make_etag(asn1buf *buf, asn1_class asn1class,
-                               asn1_tagnum tagnum, unsigned int in_len,
-                               unsigned int *retlen);
-/*
- * requires  *buf is allocated, in_len is the length of an ASN.1 encoding
- *           which has just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   Inserts an explicit tag with class = asn1class, id# = tag
- *            length = in_len into *buf.
- *           Returns the length of this encoding in *retlen.
- *           Returns ENOMEM if memory runs out.
- */
-
-asn1_error_code asn1_make_tag(asn1buf *buf, asn1_class asn1class,
-                              asn1_construction construction,
-                              asn1_tagnum tagnum, unsigned int in_len,
-                              unsigned int *retlen);
-/*
- * requires  *buf is allocated, in_len is the length of an ASN.1 encoding
- *           which has just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   Inserts the encoding of a tag with class = asn1class,
- *            primitive/constructed staus = construction,
- *            id# = tag and length = in_len into *buf.
- *           Returns the length of this encoding in *retlen.
- *           Returns ENOMEM if memory runs out.
- *           Returns ASN1_OVERFLOW if tagnum exceeds the limits of
- *            the implementation.
- */
-
-asn1_error_code asn1_make_sequence(asn1buf *buf, const unsigned int seq_len,
-                                   unsigned int *len);
-/*
- * requires  *buf is allocated, seq_len is the length of a series of
- *           sequence components which have just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   Inserts the sequence header for a sequence of length seq_len
- *            in *buf.  Returns the length of this encoding in *retlen.
- *           Returns ENOMEM if memory runs out.
- */
-
-asn1_error_code asn1_make_set(asn1buf *buf, const unsigned int set_len,
-                              unsigned int *retlen);
-/*
- * requires  *buf is allocated, seq_len is the length of a series of
- *           sequence components which have just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   Inserts the set header for a set of length set_len in *buf.
- *           Returns the length of this encoding in *retlen.
- *           Returns ENOMEM if memory runs out.
- */
-
-asn1_error_code asn1_make_string(asn1buf *buf, const unsigned int len,
-                                 const char *string, int *retlen);
-/*
- * requires  *buf is allocated, len is the length of *string
- * effects   Inserts the encoding of *string (a series of octets) in *buf.
- *           Returns the length of this encoding in *retlen.
- *           Returns ENOMEM if memory runs out.
- */
-
-
-/****************************************************************/
-/* Private procedures */
-
-/* "helper" procedure for asn1_make_tag */
-asn1_error_code asn1_make_length(asn1buf *buf, const unsigned int in_len,
-                                 unsigned int *retlen);
-/*
- * requires  *buf is allocated, in_len is the length of an ASN.1 encoding
- *           which has just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   inserts length octet(s) for in_len into *buf
- */
-
-/* "helper" procedure for asn1_make_tag */
-asn1_error_code asn1_make_id(asn1buf *buf, asn1_class asn1class,
-                             asn1_construction construction,
-                             asn1_tagnum tagnum, unsigned int *retlen);
-/*
- * requires  *buf is allocated, asn1class and tagnum are appropriate for
- *           the ASN.1 encoding which has just been inserted in *buf
- * modifies  *buf, *retlen
- * effects   Inserts id octet(s) of class asn1class and tag number tagnum
- *           into *buf
- */
-
-#endif
index cfbeb30175a00e54133ed5297adffaa7283a69ed..300af80b550e5f0908c301a4a828940924186819 100644 (file)
@@ -76,7 +76,7 @@ asn1_encode.so asn1_encode.po $(OUTPRE)asn1_encode.$(OBJEXT): \
   $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/plugin.h \
   $(top_srcdir)/include/krb5/preauth_plugin.h $(top_srcdir)/include/port-sockets.h \
   $(top_srcdir)/include/socket-utils.h asn1_encode.c \
-  asn1_encode.h asn1_make.h asn1buf.h krbasn1.h
+  asn1_encode.h asn1_get.h asn1buf.h krbasn1.h
 asn1_get.so asn1_get.po $(OUTPRE)asn1_get.$(OBJEXT): \
   $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
   $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
@@ -89,18 +89,6 @@ asn1_get.so asn1_get.po $(OUTPRE)asn1_get.$(OBJEXT): \
   $(top_srcdir)/include/krb5/preauth_plugin.h $(top_srcdir)/include/port-sockets.h \
   $(top_srcdir)/include/socket-utils.h asn1_get.c asn1_get.h \
   asn1buf.h krbasn1.h
-asn1_make.so asn1_make.po $(OUTPRE)asn1_make.$(OBJEXT): \
-  $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
-  $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
-  $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h $(top_srcdir)/include/k5-err.h \
-  $(top_srcdir)/include/k5-gmt_mktime.h $(top_srcdir)/include/k5-int-pkinit.h \
-  $(top_srcdir)/include/k5-int.h $(top_srcdir)/include/k5-platform.h \
-  $(top_srcdir)/include/k5-plugin.h $(top_srcdir)/include/k5-thread.h \
-  $(top_srcdir)/include/k5-trace.h $(top_srcdir)/include/krb5.h \
-  $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/plugin.h \
-  $(top_srcdir)/include/krb5/preauth_plugin.h $(top_srcdir)/include/port-sockets.h \
-  $(top_srcdir)/include/socket-utils.h asn1_make.c asn1_make.h \
-  asn1buf.h krbasn1.h
 asn1buf.so asn1buf.po $(OUTPRE)asn1buf.$(OBJEXT): $(BUILDTOP)/include/autoconf.h \
   $(BUILDTOP)/include/krb5/krb5.h $(BUILDTOP)/include/osconf.h \
   $(BUILDTOP)/include/profile.h $(COM_ERR_DEPS) $(top_srcdir)/include/k5-buf.h \
@@ -149,7 +137,7 @@ asn1_k_encode.so asn1_k_encode.po $(OUTPRE)asn1_k_encode.$(OBJEXT): \
   $(top_srcdir)/include/krb5/authdata_plugin.h $(top_srcdir)/include/krb5/plugin.h \
   $(top_srcdir)/include/krb5/preauth_plugin.h $(top_srcdir)/include/port-sockets.h \
   $(top_srcdir)/include/socket-utils.h asn1_encode.h \
-  asn1_k_encode.c asn1_make.h asn1buf.h krbasn1.h
+  asn1_get.h asn1_k_encode.c asn1buf.h krbasn1.h
 ldap_key_seq.so ldap_key_seq.po $(OUTPRE)ldap_key_seq.$(OBJEXT): \
   $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
   $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
@@ -161,8 +149,8 @@ ldap_key_seq.so ldap_key_seq.po $(OUTPRE)ldap_key_seq.$(OBJEXT): \
   $(top_srcdir)/include/krb5.h $(top_srcdir)/include/krb5/authdata_plugin.h \
   $(top_srcdir)/include/krb5/plugin.h $(top_srcdir)/include/krb5/preauth_plugin.h \
   $(top_srcdir)/include/port-sockets.h $(top_srcdir)/include/socket-utils.h \
-  asn1_decode.h asn1_encode.h asn1_get.h asn1_make.h \
-  asn1buf.h krbasn1.h ldap_key_seq.c
+  asn1_decode.h asn1_encode.h asn1_get.h asn1buf.h krbasn1.h \
+  ldap_key_seq.c
 asn1_misc.so asn1_misc.po $(OUTPRE)asn1_misc.$(OBJEXT): \
   $(BUILDTOP)/include/autoconf.h $(BUILDTOP)/include/krb5/krb5.h \
   $(BUILDTOP)/include/osconf.h $(BUILDTOP)/include/profile.h \
index 6c0de20cca1eb413fa03abe1af012bcfc205f2ae..cdcd4c7a18135af2517ee969c9a8e8ea2968a0b9 100644 (file)
@@ -38,7 +38,6 @@
 #include "krbasn1.h"
 #include "asn1_encode.h"
 #include "asn1_decode.h"
-#include "asn1_make.h"
 #include "asn1_get.h"
 
 #ifdef ENABLE_LDAP