krb5_decode_test.c (main): Add tests for decode_krb5_{etype_info,alt_method}
authorTheodore Tso <tytso@mit.edu>
Mon, 28 Aug 1995 21:03:13 +0000 (21:03 +0000)
committerTheodore Tso <tytso@mit.edu>
Mon, 28 Aug 1995 21:03:13 +0000 (21:03 +0000)
krb5_encode_test.c (main): Add tests for encode_krb5_{etype_info,alt_method}

ktest_equal.c (ktest_equal_krb5_alt_method,
ktest_equal_krb5_etype_info_entry,
ktest_equal_krb5_etype_info) New functions to test
{encode,decode}_krb5_{etype_info,alt_method}.

ktest.c (ktest_make_sample_etype_info_entry,
ktest_make_sample_etype_info,
ktest_make_sample_alt_method,
ktest_destroy_etype_info_entry, ktest_destroy_etype_info):
New functions to test {encode,decode}_krb5_{etype_info,alt_method}.

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

src/tests/asn.1/ChangeLog
src/tests/asn.1/krb5_decode_test.c
src/tests/asn.1/krb5_encode_test.c
src/tests/asn.1/ktest.c
src/tests/asn.1/ktest.h
src/tests/asn.1/ktest_equal.c
src/tests/asn.1/ktest_equal.h
src/tests/asn.1/reference_encode.out
src/tests/asn.1/trval_reference.out

index 4dca4c1b84902bb3faf19460bce170341af05880..7fcf5509edd808195bd9c9de06c45b56f6ca5b7b 100644 (file)
@@ -1,12 +1,28 @@
+Mon Aug 28 16:35:22 1995    <tytso@rsts-11.mit.edu>
+
+       * krb5_decode_test.c (main): Add tests for
+               decode_krb5_{etype_info,alt_method}.
+
+       * krb5_encode_test.c (main): Add tests for
+               encode_krb5_{etype_info,alt_method}.
+
+       * ktest_equal.c (ktest_equal_krb5_alt_method,
+               ktest_equal_krb5_etype_info_entry,
+               ktest_equal_krb5_etype_info) New functions to test
+               {encode,decode}_krb5_{etype_info,alt_method}.
+
+       * ktest.c (ktest_make_sample_etype_info_entry,
+               ktest_make_sample_etype_info,
+               ktest_make_sample_alt_method,
+               ktest_destroy_etype_info_entry, ktest_destroy_etype_info):
+               New functions to test
+               {encode,decode}_krb5_{etype_info,alt_method}.
+
 Sat Aug 26 12:40:57 1995  Ezra Peisach  <epeisach@kangaroo.mit.edu>
 
        * krb5_encode_test.c (encoder_print_results): If trval2 returns
                non zero, indicate with error before exiting.
 
-       * trval.c (do_cons): Initialize return value to zero in case of
-               zero length data. (instead of random stack value).
-
-
 Fri Aug 25 21:50:37 1995  Theodore Y. Ts'o  <tytso@dcl>
 
        * krb5_encode_test.c (main): Add tests for
index 266683bc6ca30e3a2f2604481a8b538091adb5b9..3120b04b2a22f9290f7a175cbce98a32e828d351 100644 (file)
@@ -390,5 +390,78 @@ void main()
     assert(ktest_equal_sequence_of_pa_data(ref,var),"pa_data (empty)\n")
   }
   
+  /****************************************************************/
+  /* decode_pwd_sequence */
+  {
+    setup(krb5_alt_method,"krb5_alt_method",ktest_make_sample_alt_method);
+    decode_run("alt_method","","30 0F A0 03 02 01 2A A1 08 04 06 73 65
+63 72 65 74",decode_krb5_alt_method,ktest_equal_krb5_alt_method);
+    ref.length = 0;
+    decode_run("alt_method (no data)","","30 05 A0 03 02 01 2A",decode_krb5_alt_method,ktest_equal_krb5_alt_method);
+    
+  }
+
+  /****************************************************************/
+  /* decode_etype_info */
+  {
+      krb5_etype_info ref, var;
+
+      retval = ktest_make_sample_etype_info(&ref);
+      if (retval) {
+         com_err("krb5_decode_test", retval,
+                 "while making sample etype info");
+         exit(1);
+      }
+      retval = krb5_data_hex_parse(&code,"30 33 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 30 05 A0 03 02 01 01 30 14 A0 03 02 01 02 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 32");
+      if(retval){
+         com_err("krb5_decode_test", retval, "while parsing etype_info");
+         exit(1);
+      }
+      retval = decode_krb5_etype_info(&code,&var);
+      if(retval){
+         com_err("krb5_decode_test", retval, "while decoding etype_info");
+      }
+      assert(ktest_equal_etype_info(ref,var),"etype_info\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;
+      
+      retval = krb5_data_hex_parse(&code,"30 16 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30");
+      if(retval){
+         com_err("krb5_decode_test", retval,
+                 "while parsing etype_info (only one)");
+         exit(1);
+      }
+      retval = decode_krb5_etype_info(&code,&var);
+      if(retval){
+         com_err("krb5_decode_test", retval,
+                 "while decoding etype_info (only one)");
+      }
+      assert(ktest_equal_etype_info(ref,var),"etype_info (only one)\n");
+      
+      ktest_destroy_etype_info(var);
+      ktest_destroy_etype_info_entry(ref[0]);      ref[0] = 0;
+      
+      retval = krb5_data_hex_parse(&code,"30 00");
+      if(retval){
+         com_err("krb5_decode_test", retval,
+                 "while parsing etype_info (no info)");
+         exit(1);
+      }
+      retval = decode_krb5_etype_info(&code,&var);
+      if(retval){
+         com_err("krb5_decode_test", retval,
+                 "while decoding etype_info (no info)");
+      }
+      assert(ktest_equal_etype_info(ref,var),"etype_info (no info)\n");
+
+      ktest_destroy_etype_info(var);
+      ktest_destroy_etype_info(ref);
+  }
+
+  
   exit(error_count);
 }
+
+
index 6adebbd8285838c84bd2ec41efa621e4666c82aa..9262a5742ac38d275e952bfe57423dd1ffb93470 100644 (file)
@@ -459,5 +459,44 @@ void main(argc, argv)
     encoder_print_results(code, "padata_sequence(empty)", "");
   }
 
+  /****************************************************************/
+  /* encode_alt_method */
+  {
+    krb5_alt_method am;
+    setup(am,krb5_alt_method,"AltMethod",ktest_make_sample_alt_method);
+    encode_run(am,krb5_alt_method,"alt_method","",encode_krb5_alt_method);
+    am.length = 0;
+    am.data = 0;
+    encode_run(am,krb5_alt_method,"alt_method (no data)","",
+              encode_krb5_alt_method);
+  }
+
+  /****************************************************************/
+  /* encode_etype_info */
+  {
+    krb5_etype_info_entry **info;
+    
+    setup(info,krb5_etype_info_entry **,"etype_info",
+         ktest_make_sample_etype_info);
+    retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code));
+    if(retval) com_err("encoding etype_info",retval,"");
+    encoder_print_results(code, "etype_info", "");
+    ktest_destroy_etype_info_entry(info[2]);      info[2] = 0;
+    ktest_destroy_etype_info_entry(info[1]);      info[1] = 0;
+
+    retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code));
+    if(retval) com_err("encoding etype_info (only 1)",retval,"");
+    encoder_print_results(code, "etype_info (only 1)", "");
+
+    ktest_destroy_etype_info_entry(info[0]);      info[0] = 0;
+    
+    retval = encode_krb5_etype_info((const krb5_etype_info_entry **)info,&(code));
+    if(retval) com_err("encoding etype_info (no info)",retval,"");
+    encoder_print_results(code, "etype_info (no info)", "");
+
+    free(info);
+  }
   exit(error_count);
 }
+
+
index 4951e15d3e68b0588357fa861fc89117ecab42d8..2a01cb353ac07997184841caf726fbdf4f40487f 100644 (file)
@@ -637,6 +637,58 @@ krb5_error_code ktest_make_sample_krb5_pwd_data(pd)
   return 0;
 }
 
+krb5_error_code ktest_make_sample_alt_method(p)
+     krb5_alt_method * p;
+{
+    p->method = 42;
+    p->data = "secret";
+    p->length = strlen(p->data);
+    return 0;
+}
+
+krb5_error_code ktest_make_sample_etype_info_entry(p)
+     krb5_etype_info_entry * p;
+{
+    p->etype = 1;
+    p->salt = "Morton";
+    p->length = strlen(p->salt);
+    return 0;
+}
+
+krb5_error_code ktest_make_sample_etype_info(p)
+     krb5_etype_info_entry *** p;
+{
+    krb5_etype_info_entry **info;
+    int        i;
+    char buf[80];
+
+    info = malloc(sizeof(krb5_etype_info_entry *) * 4);
+    if (!info)
+       return ENOMEM;
+    memset(info, 0, sizeof(krb5_etype_info_entry *) * 4);
+
+    for (i=0; i < 3; i++) {
+       info[i] = malloc(sizeof(krb5_etype_info_entry));
+       if (info[i] == 0)
+           goto memfail;
+       info[i]->etype = i;
+       sprintf(buf, "Morton's #%d", i);
+       info[i]->length = strlen(buf);
+       info[i]->salt = malloc(info[i]->length+1);
+       if (info[i]->salt == 0)
+           goto memfail;
+       strcpy(info[i]->salt, buf);
+       info[i]->magic = KV5M_ETYPE_INFO_ENTRY;
+    }
+    free(info[1]->salt);
+    info[1]->length = 0;
+    info[1]->salt = 0;
+    *p = info;
+    return 0;
+memfail:
+    ktest_destroy_etype_info(info);
+    return ENOMEM;
+}
 
 /****************************************************************/
 /* destructors */
@@ -814,3 +866,23 @@ void ktest_destroy_enc_data(ed)
   ktest_empty_data(&(ed->ciphertext));
   ed->kvno = 0;
 }
+
+void ktest_destroy_etype_info_entry(i)
+    krb5_etype_info_entry *i;
+{
+    if (i->salt)
+       free(i->salt);
+    free(i);
+}
+
+void ktest_destroy_etype_info(info)
+    krb5_etype_info_entry **info;
+{
+  int i;
+
+  for(i=0; info[i] != NULL; i++)
+      ktest_destroy_etype_info_entry(info[i]);
+  free(info);
+}
+    
+
index 752a5f83426cab3ad511512df0d60bb6b2aec825..6d087b2d55d605c39ca7ee969b0adc82e8a56157 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __KTEST_H__
 #define __KTEST_H__
 
-#include "krb5.h"
+#include "k5-int.h"
 
 #define SAMPLE_USEC 123456
 #define SAMPLE_TIME 771228197  /* Fri Jun 10  6:03:17 GMT 1994 */
@@ -84,6 +84,11 @@ krb5_error_code ktest_make_sample_passwd_phrase_element
        KRB5_PROTOTYPE((passwd_phrase_element *ppe));
 krb5_error_code ktest_make_sample_krb5_pwd_data
        KRB5_PROTOTYPE((krb5_pwd_data *pd));
+krb5_error_code ktest_make_sample_alt_method
+       KRB5_PROTOTYPE((krb5_alt_method *am));
+
+krb5_error_code ktest_make_sample_etype_info
+    KRB5_PROTOTYPE((krb5_etype_info_entry *** p));
 
 /*----------------------------------------------------------------------*/
 
@@ -129,4 +134,9 @@ void ktest_destroy_sequence_of_ticket
 void ktest_destroy_enc_data
        KRB5_PROTOTYPE((krb5_enc_data *ed));
 
+void ktest_destroy_etype_info_entry
+       KRB5_PROTOTYPE((krb5_etype_info_entry *i));
+void ktest_destroy_etype_info
+       KRB5_PROTOTYPE((krb5_etype_info_entry **info));
+
 #endif
index cfa6eb07d1f5a20b3adea64fb6c96af6ed9c2e35..c9cf3294166548c93d8fa79f11d68f922f714591 100644 (file)
@@ -465,6 +465,32 @@ int ktest_equal_krb5_pwd_data(ref, var)
   return p;
 }
 
+int ktest_equal_krb5_alt_method(ref, var)
+    krb5_alt_method *ref;
+    krb5_alt_method *var;
+{
+    if (ref->method != var->method)
+       return FALSE;
+    if (ref->length != var->length)
+       return FALSE;
+    if (memcmp(ref->data, var->data, ref->length) != 0)
+       return FALSE;
+    return TRUE;
+}
+
+int ktest_equal_krb5_etype_info_entry(ref, var)
+    krb5_etype_info_entry *ref;
+    krb5_etype_info_entry *var;
+{
+    if (ref->etype != var->etype)
+       return FALSE;
+    if (ref->length != var->length)
+       return FALSE;
+    if (memcmp(ref->salt, var->salt, ref->length) != 0)
+       return FALSE;
+    return TRUE;
+}
+
 /**** arrays ****************************************************************/
 
 int ktest_equal_array_of_data(length, ref, var)
@@ -583,3 +609,10 @@ int ktest_equal_array_of_passwd_phrase_element(ref, var)
 {
   array_compare(ktest_equal_passwd_phrase_element);
 }
+
+int ktest_equal_etype_info(ref, var)
+     krb5_etype_info_entry ** ref;
+     krb5_etype_info_entry ** var;
+{
+  array_compare(ktest_equal_krb5_etype_info_entry);
+}
index a88d56555023280b02378d0381fc3853eb4c92f6..375cc546df896abefcdceea9ca5d46dfe04fb943 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __KTEST_EQUAL_H__
 #define __KTEST_EQUAL_H__
 
-#include "krb5.h"
+#include "k5-int.h"
 
 /* int ktest_equal_structure(krb5_structure *ref, *var) */
 /* effects  Returns true (non-zero) if ref and var are
@@ -52,6 +52,7 @@ generic(ktest_equal_encryption_key,krb5_keyblock);
 
 generic(ktest_equal_passwd_phrase_element,passwd_phrase_element);
 generic(ktest_equal_krb5_pwd_data,krb5_pwd_data);
+generic(ktest_equal_krb5_alt_method,krb5_alt_method);
 
 int ktest_equal_last_req
        KRB5_PROTOTYPE((krb5_last_req_entry **ref, krb5_last_req_entry **var));
@@ -75,4 +76,12 @@ int ktest_equal_addresses
 int ktest_equal_array_of_char
        KRB5_PROTOTYPE((const int length, char *ref, char *var));
 
+int ktest_equal_etype_info
+    KRB5_PROTOTYPE((krb5_etype_info_entry ** ref,
+                   krb5_etype_info_entry ** var));
+
+int ktest_equal_etype_info_entry
+    KRB5_PROTOTYPE((krb5_etype_info_entry * ref,
+                   krb5_etype_info_entry * var));
+
 #endif
index 8022948fd603ba61a6ad06b79c36e4b5640b8be4..5778aeef16d4b992971bd605e1774e4ff71591ad 100644 (file)
@@ -39,3 +39,8 @@ encode_krb5_pwd_sequence: 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08
 encode_krb5_pwd_data: 30 3D A0 03 02 01 02 A1 36 30 34 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08 6B 72 62 35 64 61 74 61 30 18 A0 0A 04 08 6B 72 62 35 64 61 74 61 A1 0A 04 08 6B 72 62 35 64 61 74 61
 encode_krb5_padata_sequence: 30 24 30 10 A1 03 02 01 0D A2 09 04 07 70 61 2D 64 61 74 61 30 10 A1 03 02 01 0D A2 09 04 07 70 61 2D 64 61 74 61
 encode_krb5_padata_sequence(empty): 30 00
+encode_krb5_alt_method: 30 0F A0 03 02 01 2A A1 08 04 06 73 65 63 72 65 74
+encode_krb5_alt_method (no data): 30 05 A0 03 02 01 2A
+encode_krb5_etype_info: 30 33 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30 30 05 A0 03 02 01 01 30 14 A0 03 02 01 02 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 32
+encode_krb5_etype_info (only 1): 30 16 30 14 A0 03 02 01 00 A1 0D 04 0B 4D 6F 72 74 6F 6E 27 73 20 23 30
+encode_krb5_etype_info (no info): 30 00
index 8fa2b7e7ecd9d9d70e1d50deacb8ec3074d34e4c..85dcd61f87ac923b980fe1ac98213857f7ccb105 100644 (file)
@@ -1837,3 +1837,50 @@ encode_krb5_padata_sequence(empty):
 
 [Sequence/Sequence Of] 
 
+encode_krb5_alt_method:
+
+[Sequence/Sequence Of] 
+.  [0] [Integer] <1>
+      2a                          *
+.  [1] [Octet String] <6>
+      73 65 63 72 65 74           secret
+
+encode_krb5_alt_method (no data):
+
+[Sequence/Sequence Of] 
+.  [0] [Integer] <1>
+      2a                          *
+
+encode_krb5_etype_info:
+
+[Sequence/Sequence Of] 
+.  [Sequence/Sequence Of] 
+.  .  [0] [Integer] <1>
+         00                          .
+.  .  [1] [Octet String] <11>
+         4d 6f 72 74 6f 6e 27 73     Morton's
+         20 23 30                     #0
+.  [Sequence/Sequence Of] 
+.  .  [0] [Integer] <1>
+         01                          .
+.  [Sequence/Sequence Of] 
+.  .  [0] [Integer] <1>
+         02                          .
+.  .  [1] [Octet String] <11>
+         4d 6f 72 74 6f 6e 27 73     Morton's
+         20 23 32                     #2
+
+encode_krb5_etype_info (only 1):
+
+[Sequence/Sequence Of] 
+.  [Sequence/Sequence Of] 
+.  .  [0] [Integer] <1>
+         00                          .
+.  .  [1] [Octet String] <11>
+         4d 6f 72 74 6f 6e 27 73     Morton's
+         20 23 30                     #0
+
+encode_krb5_etype_info (no info):
+
+[Sequence/Sequence Of] 
+