blob: 4d0d0033a4bfff6e375c2a3e3a50179271a92c5e [file] [log] [blame]
Gilles Peskinef040a172017-05-05 18:56:12 +02001#!/usr/bin/env perl
Bence Szépkúti468a76f2020-05-26 00:33:31 +02002#
Bence Szépkútia2947ac2020-08-19 16:37:36 +02003# Copyright The Mbed TLS Contributors
Bence Szépkútif744bd72020-06-05 13:02:18 +02004# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5#
6# This file is provided under the Apache License 2.0, or the
7# GNU General Public License v2.0 or later.
8#
9# **********
10# Apache License 2.0:
Bence Szépkúti51b41d52020-05-26 01:54:15 +020011#
12# Licensed under the Apache License, Version 2.0 (the "License"); you may
13# not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
Bence Szépkúti468a76f2020-05-26 00:33:31 +020023#
Bence Szépkútif744bd72020-06-05 13:02:18 +020024# **********
25#
26# **********
27# GNU General Public License v2.0 or later:
28#
29# This program is free software; you can redistribute it and/or modify
30# it under the terms of the GNU General Public License as published by
31# the Free Software Foundation; either version 2 of the License, or
32# (at your option) any later version.
33#
34# This program is distributed in the hope that it will be useful,
35# but WITHOUT ANY WARRANTY; without even the implied warranty of
36# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37# GNU General Public License for more details.
38#
39# You should have received a copy of the GNU General Public License along
40# with this program; if not, write to the Free Software Foundation, Inc.,
41# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42#
43# **********
Bence Szépkúti468a76f2020-05-26 00:33:31 +020044
Gilles Peskinef040a172017-05-05 18:56:12 +020045use strict;
46use warnings;
47
Gilles Peskinefd14bca2017-05-11 17:57:22 +020048if (!@ARGV || $ARGV[0] == '--help') {
49 print <<EOF;
50Usage: $0 mbedtls_test_foo <file.pem
51 $0 TEST_FOO mbedtls_test_foo <file.pem
52Print out a PEM file as C code defining a string constant.
53
54Used to include some of the test data in /library/certs.c for
55self-tests and sample programs.
56EOF
57 exit;
58}
59
Gilles Peskinef040a172017-05-05 18:56:12 +020060my $pp_name = @ARGV > 1 ? shift @ARGV : undef;
61my $name = shift @ARGV;
62
63my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>;
64
65if (defined $pp_name) {
66 foreach ("#define $pp_name", @lines[0..@lines-2]) {
67 printf "%-72s\\\n", $_;
68 }
69 print "$lines[@lines-1]\n";
70 print "const char $name\[\] = $pp_name;\n";
71} else {
72 print "const char $name\[\] =";
73 foreach (@lines) {
74 print "\n$_";
75 }
76 print ";\n";
77}