]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - host/nessie_check.rb
adjusting make-system for AEAD-Ciphers
[avr-crypto-lib.git] / host / nessie_check.rb
index 9ec83b2560539ba1f11f0bd62a633a21f0cd15e0..cea8925e31438c8295f1b01ab5c89279d0677d13 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby 
+#!/usr/bin/ruby
 # nessie_check.rb
 =begin
     This file is part of the AVR-Crypto-Lib.
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 =end
 
+$debug = true
+
 def skip_header(file)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[*]{10,}.*/.match(l)
-  puts("DBG 0.0: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[*]{10,}.*/.match(l)
-  puts("DBG 0.1: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[=]{5,}.*/.match(l)
-  puts("DBG 0.2: "+l)
   begin
     l = file.gets().strip
+    l = '' if !l
   end until /[=]{5,}.*/.match(l)
-  puts("DBG 0.3: "+l)  
 end
 
 def get_next_assign(file, i)
@@ -51,7 +53,7 @@ def get_next_assign(file, i)
          return nil if file.eof
          l = file.gets().strip()
          if not /[^=]+=[^=]+/.match(l)
-           value += l if /[0-9A-Fa-f]{5}/.match(l)
+           value += l if /^[0-9A-Fa-f]{5}/.match(l)
          end
     end until /[^=]+=[^=]+/.match(l)
        $last_assign[i] = l
@@ -63,7 +65,7 @@ def get_next_assign(file, i)
          return nil if file.eof
          l = file.gets().strip()
          if not /[^=]+=[^=]+/.match(l)
-           value += l if /[0-9A-Fa-f]{5}/.match(l)
+           value += l if /^[0-9A-Fa-f]{5}/.match(l)
          end
     end until /[^=]+=[^=]+/.match(l)
        $last_assign[i] = l
@@ -82,17 +84,16 @@ def compare(fname1, fname2)
     a = get_next_assign(file1, 0)
     b = get_next_assign(file2, 1)
        return if(a==nil or b==nil)
-       puts("") if pos%$linewidth==0 and pos!=0
-       putc((a==b)?'*':'!')
-#      puts("a == nil") if a==nil
-#      puts("b == nil") if b==nil
-       
+       if not $quiet
+      puts("") if pos%$linewidth==0 and pos!=0
+         putc((a==b)?'*':'!')
+      pos +=1
+       end
        if(a!=b and a!=nil and b!=nil)
-         $error = 1
-         puts("a key: "+a[0]+" value: "+a[1])
-         puts("b key: "+b[0]+" value: "+b[1])
-       end     
-       pos +=1
+         $error += 1
+         puts("a key: "+a[0]+" value: "+a[1]) if $debug
+         puts("b key: "+b[0]+" value: "+b[1]) if $debug
+       end
   end until a==nil or b==nil
 end
 
@@ -100,14 +101,30 @@ $error = 0
 $linewidth=64
 $last_assign=[nil, nil]
 
-if ARGV.size!=2
+if ARGV.size<2 or ARGV.size>3
   STDERR.print <<EOF
-  Usage: ruby #{$0} file1 file2
+  Usage: ruby #{$0} [-q|-v] file1 file2
 EOF
   exit(1)
 end
-puts("compare("+ARGV[1]+", "+ARGV[0]+")")
-compare(ARGV[1], ARGV[0])
-puts($error==0?"[ok]":"[failed]")
+$quiet = false
+if ARGV.size==3
+  f1 = ARGV[1]
+  f2 = ARGV[2]
+  if ARGV[0]=="-q"
+    $quiet=true
+  end
+else
+  f1 = ARGV[0]
+  f2 = ARGV[1]
+end
+
+puts("compare("+f1+", "+f2+")")
+compare(f1, f2)
+if $error!=0
+  puts("[failed] ("+$error.to_s()+")")
+else
+  puts("[ok]")
+end
 
 exit($error)