Add GS2 mech code
[cyrus-sasl.git] / plugins / gs2_token.c
index a44dde4..9a97243 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <string.h>
 #include <gssapi/gssapi.h>
+#include "gs2_token.h"
 
 /*
  * $Id: util_token.c 23457 2009-12-08 00:04:48Z tlyu $
    the interfaces, so the code can be fixed if the OSI namespace
    balloons unexpectedly. */
 
-#define g_OID_equal(o1, o2)                                             \
-        (((o1)->length == (o2)->length) &&                              \
-        (memcmp((o1)->elements, (o2)->elements, (o1)->length) == 0))
-
 /*
  * Each token looks like this:
  * 0x60                 tag for APPLICATION 0, SEQUENCE
@@ -135,7 +132,7 @@ size_t
 gs2_token_size(const gss_OID_desc *mech, size_t body_size)
 {
     /* set body_size to sequence contents size */
-    body_size += 4 + (size_t) mech->length;         /* NEED overflow check */
+    body_size += 2 + (size_t) mech->length;         /* NEED overflow check */
     return 1 + der_length_size(body_size) + body_size;
 }
 
@@ -167,7 +164,7 @@ gs2_make_token_header(
 
 OM_uint32
 gs2_verify_token_header(OM_uint32 *minor,
-                        gss_OID mech,
+                        gss_const_OID mech,
                         size_t *body_size,
                         unsigned char **buf_in,
                         size_t toksize_in)
@@ -209,13 +206,8 @@ gs2_verify_token_header(OM_uint32 *minor,
     toid.elements = buf;
     buf += toid.length;
 
-    if (mech->elements == NULL) {
-        *mech = toid;
-        if (toid.length == 0)
-            return GSS_S_BAD_MECH;
-    } else if (!g_OID_equal(&toid, mech)) {
+    if (!g_OID_equal(&toid, mech))
         return GSS_S_BAD_MECH;
-    }
 
     *buf_in = buf;
     *body_size = toksize;