mbed TLS upgraded to 2.6.0
Fork of mbedtls by
scripts/rename.pl@2:bbdeda018a3c, 2017-09-29 (annotated)
- Committer:
- Jasper Wallace
- Date:
- Fri Sep 29 19:50:30 2017 +0100
- Revision:
- 2:bbdeda018a3c
- Parent:
- 1:9ebc941037d5
Update to mbedtls 2.6.0, many changes.
Changes to mbedtls sources made:
in include/mbedtls/config.h comment out:
#define MBEDTLS_FS_IO
#define MBEDTLS_NET_C
#define MBEDTLS_TIMING_C
uncomment:
#define MBEDTLS_NO_PLATFORM_ENTROPY
remove the following directorys:
programs
yotta
visualc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jasper Wallace |
1:9ebc941037d5 | 1 | #!/usr/bin/perl |
Jasper Wallace |
1:9ebc941037d5 | 2 | # |
Jasper Wallace |
1:9ebc941037d5 | 3 | # This file is part of mbed TLS (https://tls.mbed.org) |
Jasper Wallace |
1:9ebc941037d5 | 4 | # |
Jasper Wallace |
1:9ebc941037d5 | 5 | # Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
Jasper Wallace |
1:9ebc941037d5 | 6 | # |
Jasper Wallace |
1:9ebc941037d5 | 7 | # Purpose |
Jasper Wallace |
1:9ebc941037d5 | 8 | # |
Jasper Wallace |
1:9ebc941037d5 | 9 | # This script migrates application source code from the mbed TLS 1.3 API to the |
Jasper Wallace |
1:9ebc941037d5 | 10 | # mbed TLS 2.0 API. |
Jasper Wallace |
1:9ebc941037d5 | 11 | # |
Jasper Wallace |
1:9ebc941037d5 | 12 | # The script processes the given source code and renames identifiers - functions |
Jasper Wallace |
1:9ebc941037d5 | 13 | # types, enums etc, as |
Jasper Wallace |
1:9ebc941037d5 | 14 | # |
Jasper Wallace |
1:9ebc941037d5 | 15 | # Usage: rename.pl [-f datafile] [-s] [--] [filenames...] |
Jasper Wallace |
1:9ebc941037d5 | 16 | # |
Jasper Wallace |
1:9ebc941037d5 | 17 | |
Jasper Wallace |
1:9ebc941037d5 | 18 | use warnings; |
Jasper Wallace |
1:9ebc941037d5 | 19 | use strict; |
Jasper Wallace |
1:9ebc941037d5 | 20 | |
Jasper Wallace |
1:9ebc941037d5 | 21 | use utf8; |
Jasper Wallace |
1:9ebc941037d5 | 22 | use Path::Class; |
Jasper Wallace |
1:9ebc941037d5 | 23 | use open qw(:std utf8); |
Jasper Wallace |
1:9ebc941037d5 | 24 | |
Jasper Wallace |
1:9ebc941037d5 | 25 | my $usage = "Usage: $0 [-f datafile] [-s] [--] [filenames...]\n"; |
Jasper Wallace |
1:9ebc941037d5 | 26 | |
Jasper Wallace |
1:9ebc941037d5 | 27 | (my $datafile = $0) =~ s/rename.pl$/data_files\/rename-1.3-2.0.txt/; |
Jasper Wallace |
1:9ebc941037d5 | 28 | my $do_strings = 0; |
Jasper Wallace |
1:9ebc941037d5 | 29 | |
Jasper Wallace |
1:9ebc941037d5 | 30 | while( @ARGV && $ARGV[0] =~ /^-/ ) { |
Jasper Wallace |
1:9ebc941037d5 | 31 | my $opt = shift; |
Jasper Wallace |
1:9ebc941037d5 | 32 | if( $opt eq '--' ) { |
Jasper Wallace |
1:9ebc941037d5 | 33 | last; |
Jasper Wallace |
1:9ebc941037d5 | 34 | } elsif( $opt eq '-f' ) { |
Jasper Wallace |
1:9ebc941037d5 | 35 | $datafile = shift; |
Jasper Wallace |
1:9ebc941037d5 | 36 | } elsif( $opt eq '-s' ) { |
Jasper Wallace |
1:9ebc941037d5 | 37 | $do_strings = 1; shift; |
Jasper Wallace |
1:9ebc941037d5 | 38 | } else { |
Jasper Wallace |
1:9ebc941037d5 | 39 | die $usage; |
Jasper Wallace |
1:9ebc941037d5 | 40 | } |
Jasper Wallace |
1:9ebc941037d5 | 41 | } |
Jasper Wallace |
1:9ebc941037d5 | 42 | |
Jasper Wallace |
1:9ebc941037d5 | 43 | my %subst; |
Jasper Wallace |
1:9ebc941037d5 | 44 | open my $nfh, '<', $datafile or die "Could not read $datafile\n"; |
Jasper Wallace |
1:9ebc941037d5 | 45 | my $ident = qr/[_A-Za-z][_A-Za-z0-9]*/; |
Jasper Wallace |
1:9ebc941037d5 | 46 | while( my $line = <$nfh> ) { |
Jasper Wallace |
1:9ebc941037d5 | 47 | chomp $line; |
Jasper Wallace |
1:9ebc941037d5 | 48 | my ( $old, $new ) = ( $line =~ /^($ident)\s+($ident)$/ ); |
Jasper Wallace |
1:9ebc941037d5 | 49 | if( ! $old || ! $new ) { |
Jasper Wallace |
1:9ebc941037d5 | 50 | die "$0: $datafile:$.: bad input '$line'\n"; |
Jasper Wallace |
1:9ebc941037d5 | 51 | } |
Jasper Wallace |
1:9ebc941037d5 | 52 | $subst{$old} = $new; |
Jasper Wallace |
1:9ebc941037d5 | 53 | } |
Jasper Wallace |
1:9ebc941037d5 | 54 | close $nfh or die; |
Jasper Wallace |
1:9ebc941037d5 | 55 | |
Jasper Wallace |
1:9ebc941037d5 | 56 | my $string = qr/"(?:\\.|[^\\"])*"/; |
Jasper Wallace |
1:9ebc941037d5 | 57 | my $space = qr/\s+/; |
Jasper Wallace |
1:9ebc941037d5 | 58 | my $idnum = qr/[a-zA-Z0-9_]+/; |
Jasper Wallace |
1:9ebc941037d5 | 59 | my $symbols = qr/[-!#\$%&'()*+,.\/:;<=>?@[\\\]^_`{|}~]+|"/; |
Jasper Wallace |
1:9ebc941037d5 | 60 | |
Jasper Wallace |
1:9ebc941037d5 | 61 | my $lib_include_dir = dir($0)->parent->parent->subdir('include', 'mbedtls'); |
Jasper Wallace |
1:9ebc941037d5 | 62 | my $lib_source_dir = dir($0)->parent->parent->subdir('library'); |
Jasper Wallace |
1:9ebc941037d5 | 63 | |
Jasper Wallace |
1:9ebc941037d5 | 64 | # if we replace inside strings, we don't consider them a token |
Jasper Wallace |
1:9ebc941037d5 | 65 | my $token = $do_strings ? qr/$space|$idnum|$symbols/ |
Jasper Wallace |
1:9ebc941037d5 | 66 | : qr/$string|$space|$idnum|$symbols/; |
Jasper Wallace |
1:9ebc941037d5 | 67 | |
Jasper Wallace |
1:9ebc941037d5 | 68 | my %warnings; |
Jasper Wallace |
1:9ebc941037d5 | 69 | |
Jasper Wallace |
1:9ebc941037d5 | 70 | # If no files were passed, exit... |
Jasper Wallace |
1:9ebc941037d5 | 71 | if ( not defined($ARGV[0]) ){ die $usage; } |
Jasper Wallace |
1:9ebc941037d5 | 72 | |
Jasper Wallace |
1:9ebc941037d5 | 73 | while( my $filename = shift ) |
Jasper Wallace |
1:9ebc941037d5 | 74 | { |
Jasper Wallace |
1:9ebc941037d5 | 75 | print STDERR "$filename... "; |
Jasper Wallace |
1:9ebc941037d5 | 76 | |
Jasper Wallace |
1:9ebc941037d5 | 77 | if( dir($filename)->parent eq $lib_include_dir || |
Jasper Wallace |
1:9ebc941037d5 | 78 | dir($filename)->parent eq $lib_source_dir ) |
Jasper Wallace |
1:9ebc941037d5 | 79 | { |
Jasper Wallace |
1:9ebc941037d5 | 80 | die "Script cannot be executed on the mbed TLS library itself."; |
Jasper Wallace |
1:9ebc941037d5 | 81 | } |
Jasper Wallace |
1:9ebc941037d5 | 82 | |
Jasper Wallace |
1:9ebc941037d5 | 83 | if( -d $filename ) { print STDERR "skip (directory)\n"; next } |
Jasper Wallace |
1:9ebc941037d5 | 84 | |
Jasper Wallace |
1:9ebc941037d5 | 85 | open my $rfh, '<', $filename or die; |
Jasper Wallace |
1:9ebc941037d5 | 86 | my @lines = <$rfh>; |
Jasper Wallace |
1:9ebc941037d5 | 87 | close $rfh or die; |
Jasper Wallace |
1:9ebc941037d5 | 88 | |
Jasper Wallace |
1:9ebc941037d5 | 89 | my @out; |
Jasper Wallace |
1:9ebc941037d5 | 90 | for my $line (@lines) { |
Jasper Wallace |
1:9ebc941037d5 | 91 | if( $line =~ /#include/ ) { |
Jasper Wallace |
1:9ebc941037d5 | 92 | $line =~ s/polarssl/mbedtls/; |
Jasper Wallace |
1:9ebc941037d5 | 93 | $line =~ s/POLARSSL/MBEDTLS/; |
Jasper Wallace |
1:9ebc941037d5 | 94 | push( @out, $line ); |
Jasper Wallace |
1:9ebc941037d5 | 95 | next; |
Jasper Wallace |
1:9ebc941037d5 | 96 | } |
Jasper Wallace |
1:9ebc941037d5 | 97 | |
Jasper Wallace |
1:9ebc941037d5 | 98 | my @words = ($line =~ /$token/g); |
Jasper Wallace |
1:9ebc941037d5 | 99 | my $checkline = join '', @words; |
Jasper Wallace |
1:9ebc941037d5 | 100 | if( $checkline eq $line ) { |
Jasper Wallace |
1:9ebc941037d5 | 101 | my @new = map { exists $subst{$_} ? $subst{$_} : $_ } @words; |
Jasper Wallace |
1:9ebc941037d5 | 102 | push( @out, join '', @new ); |
Jasper Wallace |
1:9ebc941037d5 | 103 | } else { |
Jasper Wallace |
1:9ebc941037d5 | 104 | $warnings{$filename} = [] unless $warnings{$filename}; |
Jasper Wallace |
1:9ebc941037d5 | 105 | push @{ $warnings{$filename} }, $line; |
Jasper Wallace |
1:9ebc941037d5 | 106 | push( @out, $line ); |
Jasper Wallace |
1:9ebc941037d5 | 107 | } |
Jasper Wallace |
1:9ebc941037d5 | 108 | } |
Jasper Wallace |
1:9ebc941037d5 | 109 | |
Jasper Wallace |
1:9ebc941037d5 | 110 | open my $wfh, '>', $filename or die; |
Jasper Wallace |
1:9ebc941037d5 | 111 | print $wfh $_ for @out; |
Jasper Wallace |
1:9ebc941037d5 | 112 | close $wfh or die; |
Jasper Wallace |
1:9ebc941037d5 | 113 | print STDERR "done\n"; |
Jasper Wallace |
1:9ebc941037d5 | 114 | } |
Jasper Wallace |
1:9ebc941037d5 | 115 | |
Jasper Wallace |
1:9ebc941037d5 | 116 | if( %warnings ) { |
Jasper Wallace |
1:9ebc941037d5 | 117 | print "\nWarning: lines skipped due to unexpected characters:\n"; |
Jasper Wallace |
1:9ebc941037d5 | 118 | for my $filename (sort keys %warnings) { |
Jasper Wallace |
1:9ebc941037d5 | 119 | print "in $filename:\n"; |
Jasper Wallace |
1:9ebc941037d5 | 120 | print for @{ $warnings{$filename} }; |
Jasper Wallace |
1:9ebc941037d5 | 121 | } |
Jasper Wallace |
1:9ebc941037d5 | 122 | } |