Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
7db0c5b8
Commit
7db0c5b8
authored
10 years ago
by
Martin Nilsson
Browse files
Options
Downloads
Patches
Plain Diff
Avoid using %O for 8-bit strings.
parent
9b0c3bb4
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Standards.pmod/ASN1.pmod/testsuite.in
+56
-39
56 additions, 39 deletions
lib/modules/Standards.pmod/ASN1.pmod/testsuite.in
with
56 additions
and
39 deletions
lib/modules/Standards.pmod/ASN1.pmod/testsuite.in
+
56
−
39
View file @
7db0c5b8
START_MARKER
START_MARKER
test_do( add_constant("Types", Standards.ASN1.Types); )
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,[[
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(),
test_eq(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" "))->get_der(),
String.hex2string($1-" "))
String.hex2string($1-" "))
test_eq(decode_value(encode_value(Standards.ASN1.Decode.simple_der_decode(String.hex2string($1-" "))))->get_der(),
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_
...
@@ -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,
test_eq(Standards.ASN1.Decode.simple_der_decode(Types.OctetString("A"*128)->get_der())->value,
"A"*128)
"A"*128)
test_decode("010100","
Types.
Boolean(FALSE)")
test_decode("010100","Boolean(FALSE)")
test_decode("0101ff","
Types.
Boolean(TRUE)")
test_decode("0101ff","Boolean(TRUE)")
test_eval_error(Standards.ASN1.Decode.simple_der_decode("\1\0"))
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(
P(
Standards.ASN1.Decode.simple_der_decode(String.hex2string("090380fb05"-" "))),"Real(0.15625)")
test_eq(
sprintf("%O",
Standards.ASN1.Decode.simple_der_decode(String.hex2string("090390fe0a"-" "))),"
Types.
Real(0.15625)")
test_eq(
P(
Standards.ASN1.Decode.simple_der_decode(String.hex2string("090390fe0a"-" "))),"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("0903acfe05"-" "))),"Real(0.15625)")
test_decode("180f31393932303532313030303030305a", "
Types.
GeneralizedTime(
\"
19920521000000Z
\"
)")
test_decode("180f31393932303532313030303030305a", "GeneralizedTime(19920521000000Z)")
test_decode("180f31393932303632323132333432315a", "
Types.
GeneralizedTime(
\"
19920622123421Z
\"
)")
test_decode("180f31393932303632323132333432315a", "GeneralizedTime(19920622123421Z)")
test_decode("181131393932303732323133323130302e335a", "
Types.
GeneralizedTime(
\"
19920722132100.3Z
\"
)")
test_decode("181131393932303732323133323130302e335a", "GeneralizedTime(19920722132100.3Z)")
dnl
dnl
dnl --- START tests from
dnl --- START tests from
...
@@ -43,59 +59,59 @@ dnl A Layman's Guide to a Subset of ASN.1, BER, and DER)
...
@@ -43,59 +59,59 @@ dnl A Layman's Guide to a Subset of ASN.1, BER, and DER)
dnl
dnl
dnl 5.4
dnl 5.4
test_decode("03 04 06 6e 5d c0", "
Types.
BitString(18 011011100101110111)")
test_decode("03 04 06 6e 5d c0", "BitString(18 011011100101110111)")
test_decode("03 04 06 6e 5d e0", "
Types.
BitString(18 011011100101110111)")
test_decode("03 04 06 6e 5d e0", "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(
P(
Standards.ASN1.Decode.simple_der_decode(String.hex2string("03 81 04 06 6e 5d c0"-" "))), "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_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
dnl 5.6
test_decode("16 0d 74 65 73 74 31 40 72 73 61 2e 63 6f 6d",
test_decode("16 0d 74 65 73 74 31 40 72 73 61 2e 63 6f 6d",
"
Types.IA5String(\"
test1@rsa.com
\"
)")
"
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(
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(
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
\"
)")
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
dnl 5.6
test_decode("02 01 00", "
Types.
Integer(0)")
test_decode("02 01 00", "Integer(0)")
test_decode("02 01 7f", "
Types.
Integer(7 127)")
test_decode("02 01 7f", "Integer(7 127)")
test_decode("02 02 00 80", "
Types.
Integer(8 128)")
test_decode("02 02 00 80", "Integer(8 128)")
test_decode("02 02 01 00", "
Types.
Integer(9 256)")
test_decode("02 02 01 00", "Integer(9 256)")
test_decode("02 01 80", "
Types.
Integer(8 -128)")
test_decode("02 01 80", "Integer(8 -128)")
test_decode("02 02 ff 7f", "
Types.
Integer(8 -129)")
test_decode("02 02 ff 7f", "Integer(8 -129)")
dnl 5.8
dnl 5.8
test_decode("05 00", "
Types.
Null()")
test_decode("05 00", "Null()")
test_eq(
sprintf("%O",
Standards.ASN1.Decode.simple_der_decode(String.hex2string("05 81 00"-" "))), "
Types.
Null()")
test_eq(
P(
Standards.ASN1.Decode.simple_der_decode(String.hex2string("05 81 00"-" "))), "Null()")
test_eq( Types.Null()->get_der(), "\5\0" )
test_eq( Types.Null()->get_der(), "\5\0" )
dnl 5.9
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(),
test_eq(Types.Identifier(1,2,840,113549)->get_der(),
String.hex2string("06062a864886f70d"))
String.hex2string("06062a864886f70d"))
dnl 5.10
dnl 5.10
test_decode("04 08 01 23 45 67 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(
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(
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(
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_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
dnl 5.11
test_decode("13 0b 54 65 73 74 20 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(
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(
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(
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_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 5.16
dnl dnl FIXME: T61 is not encoded
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 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(
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(
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(
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 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
dnl
test_decode("14 0e 63 6c e9 73 20 70 75 62 6c 69 71 75 65 73", "
Types.Broken
TeletexString(
\"
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(
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.Broken
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(
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.Broken
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
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 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
dnl --- END tests from
dnl --- END tests from
...
@@ -198,6 +214,7 @@ test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0")->get_der(),
...
@@ -198,6 +214,7 @@ test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0")->get_der(),
"\1\1\0")
"\1\1\0")
test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0\0"), 0)
test_eq(Standards.ASN1.Decode.secure_der_decode("\1\1\0\0"), 0)
test_do( add_constant("P"); )
test_do( add_constant("Types"); )
test_do( add_constant("Types"); )
END_MARKER
END_MARKER
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment