Properly decode etype-info2 with no salt
authorGreg Hudson <ghudson@mit.edu>
Thu, 8 Mar 2012 00:37:47 +0000 (00:37 +0000)
committerGreg Hudson <ghudson@mit.edu>
Thu, 8 Mar 2012 00:37:47 +0000 (00:37 +0000)
The data-driven decoder for etype-info2 was neglecting to call
init_no_salt() when no salt is present in the encoding.  Add in the
missing call.  Also add decode test cases for etype-info2, which would
have caught this if they weren't missing.

ticket: 7100

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

src/lib/krb5/asn.1/asn1_k_encode.c
src/tests/asn.1/krb5_decode_test.c

index 35667ffa5524ad072aced0f0d3ea92e850c8148c..467e2de6db3ca28d24a9317e6b54ba8db07b9a6b 100644 (file)
@@ -602,7 +602,8 @@ DEFSEQTYPE(etype_info_entry, krb5_etype_info_entry, etype_info_entry_fields);
 /* First field is the same as etype-info. */
 DEFCNFIELD(etype_info2_1_def, krb5_etype_info_entry, salt, length, 1,
            u_generalstring);
-DEFOPTIONALTYPE(etype_info2_1, is_salt_present, NULL, etype_info2_1_def);
+DEFOPTIONALTYPE(etype_info2_1, is_salt_present, init_no_salt,
+                etype_info2_1_def);
 DEFFIELD(etype_info2_2, krb5_etype_info_entry, s2kparams, 2, opt_ostring_data);
 static const struct atype_info *etype_info2_entry_fields[] = {
     &k5_atype_etype_info_0, &k5_atype_etype_info2_1, &k5_atype_etype_info2_2
index 19313ee29d59588ecf20e02752a7be56efbccc81..87d3bc458327c89a9da7287c3c0ec86cb4d36f5b 100644 (file)
@@ -858,6 +858,46 @@ int main(argc, argv)
         ktest_destroy_etype_info(ref);
     }
 
+    /****************************************************************/
+    /* decode_etype_info2 */
+    {
+        krb5_etype_info ref, var;
+
+        ktest_make_sample_etype_info2(&ref);
+        retval = krb5_data_hex_parse(&code,"30 51 30 1E A0 03 02 01 00 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 A2 08 04 06 73 32 6B 3A 20 30 30 0F A0 03 02 01 01 A2 08 04 06 73 32 6B 3A 20 31 30 1E A0 03 02 01 02 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 32 A2 08 04 06 73 32 6B 3A 20 32");
+        if (retval) {
+            com_err("krb5_decode_test", retval, "while parsing etype_info2");
+            exit(1);
+        }
+        retval = decode_krb5_etype_info2(&code,&var);
+        if (retval) {
+            com_err("krb5_decode_test", retval, "while decoding etype_info2");
+        }
+        test(ktest_equal_etype_info(ref,var),"etype_info2\n");
+
+        ktest_destroy_etype_info(var);
+        ktest_destroy_etype_info_entry(ref[2]);      ref[2] = 0;
+        ktest_destroy_etype_info_entry(ref[1]);      ref[1] = 0;
+        krb5_free_data_contents(test_context, &code);
+
+        retval = krb5_data_hex_parse(&code,"30 20 30 1E A0 03 02 01 00 A1 0D 1B 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 A2 08 04 06 73 32 6B 3A 20 30");
+        if (retval) {
+            com_err("krb5_decode_test", retval,
+                    "while parsing etype_info2 (only one)");
+            exit(1);
+        }
+        retval = decode_krb5_etype_info2(&code,&var);
+        if (retval) {
+            com_err("krb5_decode_test", retval,
+                    "while decoding etype_info2 (only one)");
+        }
+        test(ktest_equal_etype_info(ref,var),"etype_info2 (only one)\n");
+
+        krb5_free_data_contents(test_context, &code);
+        ktest_destroy_etype_info(var);
+        ktest_destroy_etype_info(ref);
+    }
+
     /****************************************************************/
     /* decode_pa_enc_ts */
     {