blob: af8a2c1b4a57b1848bac6b437e59d5785c994b20 [file] [log] [blame]
Gilles Peskinef040a172017-05-05 18:56:12 +02001#!/usr/bin/env perl
Bence Szépkúti700ee442020-05-26 00:33:31 +02002#
3# Copyright (C) 2017, Arm Limited, All Rights Reserved
4#
5# This file is part of Mbed TLS (https://tls.mbed.org)
6
Gilles Peskinef040a172017-05-05 18:56:12 +02007use strict;
8use warnings;
9
Gilles Peskinefd14bca2017-05-11 17:57:22 +020010if (!@ARGV || $ARGV[0] == '--help') {
11 print <<EOF;
12Usage: $0 mbedtls_test_foo <file.pem
13 $0 TEST_FOO mbedtls_test_foo <file.pem
14Print out a PEM file as C code defining a string constant.
15
16Used to include some of the test data in /library/certs.c for
17self-tests and sample programs.
18EOF
19 exit;
20}
21
Gilles Peskinef040a172017-05-05 18:56:12 +020022my $pp_name = @ARGV > 1 ? shift @ARGV : undef;
23my $name = shift @ARGV;
24
25my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>;
26
27if (defined $pp_name) {
28 foreach ("#define $pp_name", @lines[0..@lines-2]) {
29 printf "%-72s\\\n", $_;
30 }
31 print "$lines[@lines-1]\n";
32 print "const char $name\[\] = $pp_name;\n";
33} else {
34 print "const char $name\[\] =";
35 foreach (@lines) {
36 print "\n$_";
37 }
38 print ";\n";
39}