]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
runtests: allow generating a binary sequence from hex
authorDaniel Stenberg <daniel@haxx.se>
Thu, 1 Oct 2020 22:11:13 +0000 (00:11 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 2 Oct 2020 07:35:38 +0000 (09:35 +0200)
tests/FILEFORMAT.md
tests/runtests.pl

index 09600d016a89238a94952bbae6a290e0196dc599..7748b6706131d18510a56489ead9a62ce68973a0 100644 (file)
@@ -40,6 +40,19 @@ server's port number (in ASCII) followed by a space and the hexadecimal byte
 
     %b64[%HTTPPORT %9a]b64%
 
+## Hexadecimal decoding
+
+In the preprocess stage, a special instruction can be used to have runtests.pl
+generate a sequence of binary bytes.
+
+To insert a sequence of bytes from a hex encoded string, use this syntax:
+
+    %hex[ %XX-encoded data to decode ]hex%
+
+For example, to insert the binary octets 0, 1 and 255 into the test file:
+
+    %hex[ %00%01%FF ]hex%
+
 # Variables
 
 When the test is preprocessed, a range of "variables" in the test file will be
index 49b318dc7e131a2d6a45983292739bc3c80fac9c..3255221827dd5c157a734f0421fab1aec8f68115 100755 (executable)
@@ -3304,6 +3304,13 @@ sub subBase64 {
         # put the result into there
         $$thing =~ s/%%B64%%/$enc/;
     }
+    # hex decode
+    if($$thing =~ s/%hex\[(.*)\]hex%/%%HEX%%/i) {
+        # decode %NN characters
+        my $d = $1;
+        $d =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+        $$thing =~ s/%%HEX%%/$d/;
+    }
 }
 
 sub fixarray {