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