Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 2 | # |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 3 | # Copyright The Mbed TLS Contributors |
Bence Szépkúti | c7da1fe | 2020-05-26 01:54:15 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
Bence Szépkúti | 700ee44 | 2020-05-26 00:33:31 +0200 | [diff] [blame] | 17 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 18 | use strict; |
| 19 | use warnings; |
| 20 | |
Gilles Peskine | fd14bca | 2017-05-11 17:57:22 +0200 | [diff] [blame] | 21 | if (!@ARGV || $ARGV[0] == '--help') { |
| 22 | print <<EOF; |
| 23 | Usage: $0 mbedtls_test_foo <file.pem |
| 24 | $0 TEST_FOO mbedtls_test_foo <file.pem |
| 25 | Print out a PEM file as C code defining a string constant. |
| 26 | |
| 27 | Used to include some of the test data in /library/certs.c for |
| 28 | self-tests and sample programs. |
| 29 | EOF |
| 30 | exit; |
| 31 | } |
| 32 | |
Gilles Peskine | f040a17 | 2017-05-05 18:56:12 +0200 | [diff] [blame] | 33 | my $pp_name = @ARGV > 1 ? shift @ARGV : undef; |
| 34 | my $name = shift @ARGV; |
| 35 | |
| 36 | my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>; |
| 37 | |
| 38 | if (defined $pp_name) { |
| 39 | foreach ("#define $pp_name", @lines[0..@lines-2]) { |
| 40 | printf "%-72s\\\n", $_; |
| 41 | } |
| 42 | print "$lines[@lines-1]\n"; |
| 43 | print "const char $name\[\] = $pp_name;\n"; |
| 44 | } else { |
| 45 | print "const char $name\[\] ="; |
| 46 | foreach (@lines) { |
| 47 | print "\n$_"; |
| 48 | } |
| 49 | print ";\n"; |
| 50 | } |