Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 2 | use strict; |
| 3 | use warnings; |
| 4 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame^] | 5 | if (!@ARGV || $ARGV[0] == '--help') { |
| 6 | print <<EOF; |
| 7 | Usage: $0 mbedtls_test_foo <file.pem |
| 8 | $0 TEST_FOO mbedtls_test_foo <file.pem |
| 9 | Print out a PEM file as C code defining a string constant. |
| 10 | |
| 11 | Used to include some of the test data in /library/certs.c for |
| 12 | self-tests and sample programs. |
| 13 | EOF |
| 14 | exit; |
| 15 | } |
| 16 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 17 | my $pp_name = @ARGV > 1 ? shift @ARGV : undef; |
| 18 | my $name = shift @ARGV; |
| 19 | |
| 20 | my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>; |
| 21 | |
| 22 | if (defined $pp_name) { |
| 23 | foreach ("#define $pp_name", @lines[0..@lines-2]) { |
| 24 | printf "%-72s\\\n", $_; |
| 25 | } |
| 26 | print "$lines[@lines-1]\n"; |
| 27 | print "const char $name\[\] = $pp_name;\n"; |
| 28 | } else { |
| 29 | print "const char $name\[\] ="; |
| 30 | foreach (@lines) { |
| 31 | print "\n$_"; |
| 32 | } |
| 33 | print ";\n"; |
| 34 | } |