From 7db0c5b8973f17cd296e1cb326835c930f29bb10 Mon Sep 17 00:00:00 2001 From: Martin Nilsson <nilsson@opera.com> Date: Mon, 3 Nov 2014 15:25:02 +0100 Subject: [PATCH] Avoid using %O for 8-bit strings. --- .../Standards.pmod/ASN1.pmod/testsuite.in | 95 +++++++++++-------- 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/lib/modules/Standards.pmod/ASN1.pmod/testsuite.in b/lib/modules/Standards.pmod/ASN1.pmod/testsuite.in index 7ddd35edc8..115d6d20da 100644 --- a/lib/modules/Standards.pmod/ASN1.pmod/testsuite.in +++ b/lib/modules/Standards.pmod/ASN1.pmod/testsuite.in @@ -1,9 +1,25 @@ START_MARKER 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 + ")"; + } +}); ) define(test_decode,[[ - test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" ")))-"Standards.ASN1.",$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(), @@ -25,17 +41,17 @@ test_eq(Standards.ASN1.Decode.simple_der_decode(Types.OctetString("A"*127)->get_ test_eq(Standards.ASN1.Decode.simple_der_decode(Types.OctetString("A"*128)->get_der())->value, "A"*128) -test_decode("010100","Types.Boolean(FALSE)") -test_decode("0101ff","Types.Boolean(TRUE)") +test_decode("010100","Boolean(FALSE)") +test_decode("0101ff","Boolean(TRUE)") test_eval_error(Standards.ASN1.Decode.simple_der_decode("\1\0")) -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("090380fb05"-" "))),"Types.Real(0.15625)") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("090390fe0a"-" "))),"Types.Real(0.15625)") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("0903acfe05"-" "))),"Types.Real(0.15625)") +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", "Types.GeneralizedTime(\"19920521000000Z\")") -test_decode("180f31393932303632323132333432315a", "Types.GeneralizedTime(\"19920622123421Z\")") -test_decode("181131393932303732323133323130302e335a", "Types.GeneralizedTime(\"19920722132100.3Z\")") +test_decode("180f31393932303532313030303030305a", "GeneralizedTime(19920521000000Z)") +test_decode("180f31393932303632323132333432315a", "GeneralizedTime(19920622123421Z)") +test_decode("181131393932303732323133323130302e335a", "GeneralizedTime(19920722132100.3Z)") dnl dnl --- START tests from @@ -43,59 +59,59 @@ 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", "Types.BitString(18 011011100101110111)") -test_decode("03 04 06 6e 5d e0", "Types.BitString(18 011011100101110111)") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("03 81 04 06 6e 5d c0"-" "))), "Types.BitString(18 011011100101110111)") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("23 09 03 03 00 6e 5d 03 02 06 c0"-" "))), "Types.BitString(18 011011100101110111)") +test_decode("03 04 06 6e 5d c0", "BitString(18 011011100101110111)") +test_decode("03 04 06 6e 5d e0", "BitString(18 011011100101110111)") +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", - "Types.IA5String(\"test1@rsa.com\")") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("16 81 0d 74 65 73 74 31 40 72 73 61 2e 63 6f 6d"-" "))), "Types.IA5String(\"test1@rsa.com\")") -test_eq(sprintf("%O",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"-" "))), "Types.IA5String(\"test1@rsa.com\")") + "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 5.6 -test_decode("02 01 00", "Types.Integer(0)") -test_decode("02 01 7f", "Types.Integer(7 127)") -test_decode("02 02 00 80", "Types.Integer(8 128)") -test_decode("02 02 01 00", "Types.Integer(9 256)") -test_decode("02 01 80", "Types.Integer(8 -128)") -test_decode("02 02 ff 7f", "Types.Integer(8 -129)") +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", "Types.Null()") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("05 81 00"-" "))), "Types.Null()") +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", "Types.Identifier(1.2.840.113549)") +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", "Types.OctetString(\"\\1#Eg\\211\\253\\315\\357\")") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("04 81 08 01 23 45 67 89 ab cd ef"-" "))), "Types.OctetString(\"\\1#Eg\\211\\253\\315\\357\")") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("24 0c 04 04 01 23 45 67 04 04 89 ab cd ef"-" "))), "Types.OctetString(\"\\1#Eg\\211\\253\\315\\357\")") +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", "Types.PrintableString(\"Test User 1\")") -test_eq(sprintf("%O",Standards.ASN1.Decode.simple_der_decode(String.hex2string("13 81 0b 54 65 73 74 20 55 73 65 72 20 31"-" "))), "Types.PrintableString(\"Test User 1\")") -test_eq(sprintf("%O",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"-" "))), "Types.PrintableString(\"Test User 1\")") +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", "Types.TeletexString(\"cl\\351s publiques\")") -dnl test_eq(sprintf("%O",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"-" "))), "Types.TeletexString(\"cl\\351s publiques\")") -dnl test_eq(sprintf("%O",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"-" "))), "Types.TeletexString(\"cl\\351s publiques\")") +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", "Types.BrokenTeletexString(\"cl\\351s publiques\")") -test_eq(sprintf("%O",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"-" "))), "Types.BrokenTeletexString(\"cl\\351s publiques\")") -test_eq(sprintf("%O",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"-" "))), "Types.BrokenTeletexString(\"cl\\351s publiques\")") +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", "Types.UTC(\"910506234540Z\")") +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(sprintf("%O",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"-" "))), "Types.UTC(\"910506234540Z\")") +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 @@ -198,6 +214,7 @@ 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_do( add_constant("P"); ) test_do( add_constant("Types"); ) END_MARKER -- GitLab