pike.git / lib / modules / Standards.pmod / ASN1.pmod / testsuite.in

version» Context lines:

pike.git/lib/modules/Standards.pmod/ASN1.pmod/testsuite.in:1:   START_MARKER    - dnl Tests from ITU-T Rec.X690 (07/2002) - dnl (originally from A Layman's Guide to a Subset of ASN.1, BER, and - dnl DER) + test_do( add_constant("Types", Standards.ASN1.Types); ) + test_do( add_constant("P", lambda(object o) + { +  switch(o->type_name) +  { +  case "OBJECT IDENTIFIER": +  case "INTEGER": +  case "BIT STRING": +  case "BOOLEAN": +  case "REAL": +  case "NULL": +  case "": +  return sprintf("%O",o)-"Standards.ASN1."-"Types."; +  default: +  return o->type_name + "(" + o->value + ")"; +  } + }); )    -  + test_eval_error(Standards.ASN1.Decode.simple_der_decode("")) +    define(test_decode,[[ -  test_eq(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" "))->debug_string(),$2) +  test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1))),$2) +  test_eq(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1))->get_der(), +  String.hex2string($1)) +  test_eq(decode_value(encode_value(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" "))))->get_der(), +  String.hex2string($1))   ]])    - test_decode("0500","NULL") + test_decode("1f 7f 00", "Decode.Primitive(508)") + test_decode("5f 7f 00", "Decode.Primitive(509)") + test_decode("9f 7f 00", "Decode.Primitive(510)") + test_decode("df 7f 00", "Decode.Primitive(511)") + test_decode("9f ff 00 00", "Decode.Primitive(65026)")    -  + test_eval_error(Standards.ASN1.Decode.simple_der_decode("\0\xff")) + test_eval_error(Standards.ASN1.Decode.simple_der_decode("\0\x80")) + test_eval_error(Standards.ASN1.Decode.simple_der_decode("\0\0")) +  + test_eq(Standards.ASN1.Decode.simple_der_decode(Types.OctetString("A"*127)->get_der())->value, +  "A"*127) + test_eq(Standards.ASN1.Decode.simple_der_decode(Types.OctetString("A"*128)->get_der())->value, +  "A"*128) +  + test_decode("010100","Boolean(FALSE)") + test_decode("0101ff","Boolean(TRUE)") + test_eval_error(Standards.ASN1.Decode.simple_der_decode("\1\0")) +  + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("090380fb05"))),"Real(0.15625)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("090390fe0a"))),"Real(0.15625)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("0903acfe05"))),"Real(0.15625)") +  + test_decode("180f31393932303532313030303030305a", "GeneralizedTime(19920521000000Z)") + test_decode("180f31393932303632323132333432315a", "GeneralizedTime(19920622123421Z)") + test_decode("181131393932303732323133323130302e335a", "GeneralizedTime(19920722132100.3Z)") +  + dnl + dnl --- START tests from + dnl A Layman's Guide to a Subset of ASN.1, BER, and DER + dnl +    dnl 5.4 - test_decode("03 04 06 6e 5d c0", "BIT STRING (18) 11011100101110111") - test_decode("03 04 06 6e 5d e0", "BIT STRING (18) 11011100101110111") - test_decode("03 81 04 06 6e 5d c0", "BIT STRING (18) 11011100101110111") + test_decode("03 04 06 6e 5d c0", "BitString(18 011011100101110111)") + test_false(Standards.ASN1.Decode.simple_der_decode(String.hex2string("03 04 06 6e 5d e0"))) + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("03 81 04 06 6e 5d c0"))), "BitString(18 011011100101110111)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("23 09 03 03 00 6e 5d 03 02 06 c0"))), "BitString(18 011011100101110111)")    -  + dnl 5.6 + test_decode("16 0d 74 65 73 74 31 40 72 73 61 2e 63 6f 6d", +  "IA5STRING(test1@rsa.com)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("16 81 0d 74 65 73 74 31 40 72 73 61 2e 63 6f 6d"))), "IA5STRING(test1@rsa.com)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("36 13 16 05 74 65 73 74 31 16 01 40 16 07 72 73 61 2e 63 6f 6d"))), "IA5STRING(test1@rsa.com)")    - dnl §8.8 - test_eq( Standards.ASN1.Types.Null()->get_der(), "\5\0" ) + dnl 5.6 + test_decode("02 01 00", "Integer(0)") + test_decode("02 01 7f", "Integer(7 127)") + test_decode("02 02 00 80", "Integer(8 128)") + test_decode("02 02 01 00", "Integer(9 256)") + test_decode("02 01 80", "Integer(8 -128)") + test_decode("02 02 ff 7f", "Integer(8 -129)")    -  + dnl 5.8 + test_decode("05 00", "Null()") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("05 81 00"))), "Null()") + test_eq( Types.Null()->get_der(), "\5\0" ) +  + dnl 5.9 + test_decode("06 06 2a 86 48 86 f7 0d", "Identifier(1.2.840.113549)") + test_eq(Types.Identifier(1,2,840,113549)->get_der(), +  String.hex2string("06062a864886f70d")) +  + dnl 5.10 + test_decode("04 08 01 23 45 67 89 ab cd ef", "OCTET STRING(\1#Eg\211\253\315\357)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("04 81 08 01 23 45 67 89 ab cd ef"))), "OCTET STRING(\1#Eg\211\253\315\357)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("24 0c 04 04 01 23 45 67 04 04 89 ab cd ef"))), "OCTET STRING(\1#Eg\211\253\315\357)") +  + dnl 5.11 + test_decode("13 0b 54 65 73 74 20 55 73 65 72 20 31", "PrintableString(Test User 1)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("13 81 0b 54 65 73 74 20 55 73 65 72 20 31"))), "PrintableString(Test User 1)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("33 0f 13 05 54 65 73 74 20 13 06 55 73 65 72 20 31"))), "PrintableString(Test User 1)") +  + dnl 5.16 + dnl dnl FIXME: T61 is not encoded + dnl dnl test_decode("14 0f 63 6c c2 65 73 20 70 75 62 6c 69 71 75 65 73", "TeletexString(cl\351s publiques)") + dnl test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("14 81 0f 63 6c c2 65 73 20 70 75 62 6c 69 71 75 65 73"))), "TeletexString(cl\351s publiques)") + dnl test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("34 15 14 05 63 6c c2 65 73 14 01 20 14 09 70 75 62 6c 69 71 75 65 73"))), "TeletexString(cl\351s publiques)") + dnl + test_decode("14 0e 63 6c e9 73 20 70 75 62 6c 69 71 75 65 73", "TeletexString(cl\351s publiques)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("14 81 0e 63 6c e9 73 20 70 75 62 6c 69 71 75 65 73"))), "TeletexString(cl\351s publiques)") + test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("34 14 14 04 63 6c e9 73 14 01 20 14 09 70 75 62 6c 69 71 75 65 73"))), "TeletexString(cl\351s publiques)") +  + dnl 5.17 + test_decode("17 0d 39 31 30 35 30 36 32 33 34 35 34 30 5a", "UTCTime(910506234540Z)") + dnl FIXME: Should time be normalized? + dnl test_eq(P(Standards.ASN1.Decode.simple_der_decode(String.hex2string("17 11 39 31 30 35 30 36 31 36 34 35 34 30 2D 30 37 30 30"))), "UTCTime(910506234540Z)") +  + dnl + dnl --- END tests from + dnl A Layman's Guide to a Subset of ASN.1, BER, and DER) + dnl +    dnl §8.9   test_any([[ -  import Standards.ASN1.Types; +  import Types;    return Sequence( ({ IA5String("Smith"), Boolean(17) }) )->get_der();   ]], "0\n\26\5Smith\1\1\xff")      dnl §8.19 - test_eq(Standards.ASN1.Types.Identifier(2,100,3)->get_der(), -  String.hex2string("0603813403")) + test_eq(Types.Identifier(2,100,3)->get_der(), String.hex2string("0603813403"))      dnl §8.21 - test_eq( Standards.ASN1.Types.VisibleString("Jones")->get_der(), -  "\32\5Jones" ) + test_eq( Types.VisibleString("Jones")->get_der(), "\32\5Jones" )    - test_eq( Standards.ASN1.Types.BitString()-> -  set_from_ascii("011011100101110111")->get_der(), + test_eq( Types.BitString()->set_from_ascii("011011100101110111")->get_der(),    String.hex2string("0304066e5dc0") )    - test_eq( Standards.ASN1.Types.IA5String("test1@rsa.com")->get_der(), -  String.hex2string("160d7465737431407273612e636f6d") ) +     - test_eq( Standards.ASN1.Types.Integer(0)->get_der(), -  String.hex2string("020100") ) - test_eq( Standards.ASN1.Types.Integer(127)->get_der(), -  String.hex2string("02017f") ) - test_eq( Standards.ASN1.Types.Integer(128)->get_der(), -  String.hex2string("02020080") ) - test_eq( Standards.ASN1.Types.Integer(256)->get_der(), -  String.hex2string("02020100") ) - test_eq( Standards.ASN1.Types.Integer(-128)->get_der(), -  String.hex2string("020180") ) - test_eq( Standards.ASN1.Types.Integer(-129)->get_der(), -  String.hex2string("0202ff7f") ) -  - test_eq(Standards.ASN1.Types.Identifier(1,2,840,113549)->get_der(), -  String.hex2string("06062a864886f70d")) -  - test_eq(Standards.ASN1.Types.OctetString(String.hex2string("0123456789abcdef")) -  ->get_der(), + test_eq(Types.OctetString(String.hex2string("0123456789abcdef"))->get_der(),    String.hex2string("04080123456789abcdef") )    - test_eq(Standards.ASN1.Types.PrintableString("Test User 1")->get_der(), + test_eq(Types.PrintableString("Test User 1")->get_der(),    String.hex2string("130b5465737420557365722031"))    - test_eq(Standards.ASN1.Types.UTC("910506234540Z")->get_der(), -  String.hex2string("170d3931303530363233343534305a")) + test_eq(Types.UTC()->set_posix(42)->get_posix(), 42)    - test_eq(Standards.ASN1.Types.UTC()->set_posix(673566340)->get_der(), -  String.hex2string("170d3931303530363233343534305a")) + test_eq(Types.UTC("910506214540Z")->get_der(), +  String.hex2string("170d3931303530363231343534305a"))    - test_eq(Standards.ASN1.Types.UTC("910506234540Z")->get_posix(), -  673566340) + test_eq(Types.UTC()->set_posix(673566340)->get_der(), +  String.hex2string("170d3931303530363231343534305a"))    - test_eq(Standards.ASN1.Types.TeletexString("clés publiques")->get_der(), -  String.hex2string("140f636cc26573207075626c6971756573")) + test_eq(Types.UTC("910506214540Z")->get_posix(), 673566340)    -  + dnl test_eq(Types.TeletexString("clés publiques")->get_der(), + dnl String.hex2string("140f636cc26573207075626c6971756573")) +  + test_eq(Types.BrokenTeletexString("clés publiques")->get_der(), +  String.hex2string("140e636ce973207075626c6971756573")) +    test_any([[ -  import Standards.ASN1.Types; +  import Types;    Sequence countryName = Sequence( ({ Identifier(2,5,4,6),    PrintableString("US") }) );    Sequence organizationName = Sequence( ({ Identifier(2,5,4,10),    PrintableString("Example Organization") }) );    Sequence commonName = Sequence( ({ Identifier(2,5,4,11),    PrintableString("Test User 1") }) );    return Sequence( ({    Set( ({ countryName }) ),    Set( ({ organizationName }) ),    Set( ({ commonName }) ),    }) )->get_der();   ]], String.hex2string(    "3042"    "310b" "3009""0603550406""13025553"    "311d" "301b""060355040a""13144578616d706c65204f7267616e697a6174696f6e"    "3114" "3012""060355040b""130b5465737420557365722031"   )) -  +  + test_any([[ +  object o = Types.BitString("\xbf"); +  return o->get_der() + ]], "\3\2\0\277") + test_any([[ +  object o = Types.BitString("\xbf")->set_length(3); +  return o->get_der() + ]], "\3\2\5\240") +  + test_eq([[ Types.Identifier(1,2,3) ]], [[ Types.Identifier(1,2,3) ]]) + test_equal([[ Types.Identifier(1,2,3) ]], [[ Types.Identifier(1,2,3) ]]) + test_eq([[ ([ Types.Identifier(1,2,3) : "x" ])[ Types.Identifier(1,2,3) ] ]], "x") + test_eq([[ ({ Types.Identifier(1,2,3) }) - ({ Types.Identifier(1,2,3) }) ]], ({})) + test_any([[ +  multiset m = (< Types.Identifier(1,2,3) >); +  m[Types.Identifier(1,2,3)] = 0; +  return sizeof(m); + ]], 0) + test_equal([[ sort( ({ +  Types.Identifier(1,3), +  Types.Identifier(1,2), +  Types.Identifier(1,1), +  Types.Identifier(1,2,1,1), +  Types.Identifier(1,2,1), +  Types.Identifier(1,2,2), + })) ]], [[ ({ +  Types.Identifier(1,1), +  Types.Identifier(1,2), +  Types.Identifier(1,2,1), +  Types.Identifier(1,2,1,1), +  Types.Identifier(1,2,2), +  Types.Identifier(1,3), + }) ]]) +  + test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0")->get_der(), + "\1\1\0") + test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0\0"), 0) +  + test_any([[ +  // Sequence(Integer(4),Integer(7)) +  Types.Sequence s = Standards.ASN1.Decode.simple_der_decode("0\6\2\1\4\2\1\a"); +  s->elements[0] = Types.Integer(8); +  return s->get_der(); + ]], "0\6\2\1\b\2\1\a") +  + test_decode("170d3338303131393033313430385a", "UTCTime(380119031408Z)") + test_eq(Types.UTC()->set_posix(1<<31)->get_der(), "\27\r380119031408Z") + test_eval_error(Types.UTC()->set_posix(1<<32)) +  + test_decode("180f32303338303131393033313430385a", "GeneralizedTime(20380119031408Z)") + test_eq(Types.GeneralizedTime()->set_posix(1<<31)->get_der(), "\30\17""20380119031408Z") + test_decode("180f32313036303230373036323831365a", "GeneralizedTime(21060207062816Z)") + test_eq(Types.GeneralizedTime()->set_posix(1<<32)->get_der(), "\30\17""21060207062816Z") + test_decode("180f32323432303331363132353633325a", "GeneralizedTime(22420316125632Z)") + test_eq(Types.GeneralizedTime()->set_posix(1<<33)->get_der(), "\30\17""22420316125632Z") +  + test_do( add_constant("P"); ) + test_do( add_constant("Types"); ) +    END_MARKER