]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/nessie_check.rb
d2ed46ad43c6d68fd258d487b0cd15bd494fdc03
[avr-crypto-lib.git] / host / nessie_check.rb
1 #!/usr/bin/ruby
2 # nessie_check.rb
3 =begin
4     This file is part of the AVR-Crypto-Lib.
5     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
6
7     This program is free software: you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation, either version 3 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 =end
20
21 def skip_header(file)
22   begin
23     l = file.gets().strip
24     l = '' if !l
25   end until /[*]{10,}.*/.match(l)
26   begin
27     l = file.gets().strip
28     l = '' if !l
29   end until /[*]{10,}.*/.match(l)
30   begin
31     l = file.gets().strip
32     l = '' if !l
33   end until /[=]{5,}.*/.match(l)
34   begin
35     l = file.gets().strip
36     l = '' if !l
37   end until /[=]{5,}.*/.match(l)
38 end
39
40 def get_next_assign(file, i)
41   key = String.new
42   value = String.new
43   if($last_assign[i]==nil)
44     begin
45           return nil if file.eof
46       l = file.gets().strip()
47     end until m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match(l)
48         value = m[2]
49         key = m[1]
50         begin
51           return nil if file.eof
52           l = file.gets().strip()
53           if not /[^=]+=[^=]+/.match(l)
54             value += l if /^[0-9A-Fa-f]{5}/.match(l)
55           end
56     end until /[^=]+=[^=]+/.match(l)
57         $last_assign[i] = l
58   else
59     m=/[\s]*([\w]*)[\s]*=[\s]*([0-9a-fA-F]*).*/.match($last_assign[i])
60         value = m[2]
61         key = m[1]
62         begin
63           return nil if file.eof
64           l = file.gets().strip()
65           if not /[^=]+=[^=]+/.match(l)
66             value += l if /^[0-9A-Fa-f]{5}/.match(l)
67           end
68     end until /[^=]+=[^=]+/.match(l)
69         $last_assign[i] = l
70   end
71   return [key, value]
72 end
73
74 def compare(fname1, fname2)
75   file1 = File.new(fname1, "r")
76   file2 = File.new(fname2, "r")
77   skip_header(file1)
78   skip_header(file2)
79   pos=0
80   begin
81 #       puts("checking set")
82     a = get_next_assign(file1, 0)
83     b = get_next_assign(file2, 1)
84         return if(a==nil or b==nil)
85         if not $quiet
86       puts("") if pos%$linewidth==0 and pos!=0
87           putc((a==b)?'*':'!')
88       pos +=1
89         end
90         if(a!=b and a!=nil and b!=nil)
91           $error += 1
92 #         puts("a key: "+a[0]+" value: "+a[1])
93 #         puts("b key: "+b[0]+" value: "+b[1])
94         end
95   end until a==nil or b==nil
96 end
97
98 $error = 0
99 $linewidth=64
100 $last_assign=[nil, nil]
101
102 if ARGV.size<2 or ARGV.size>3
103   STDERR.print <<EOF
104   Usage: ruby #{$0} [-q|-v] file1 file2
105 EOF
106   exit(1)
107 end
108 $quiet = false
109 if ARGV.size==3
110   f1 = ARGV[1]
111   f2 = ARGV[2]
112   if ARGV[0]=="-q"
113     $quiet=true
114   end
115 else
116   f1 = ARGV[0]
117   f2 = ARGV[1]
118 end
119
120 puts("compare("+f1+", "+f2+")")
121 compare(f1, f2)
122 if $error!=0
123   puts("[failed] ("+$error.to_s()+")")
124 else
125   puts("[ok]")
126 end
127
128 exit($error)