Re: RFC 6234 code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Martin Rex wrote:
> Dearlove, Christopher (UK) wrote:
> >
> > I'd actually tried the authors, but no reply yet (only a few days).
> > I also tried the RFC Editor thinking they might have e.g. XML
> > from which extraction might have been easier, but also no response yet.
> 
> Extracting code from text is pretty trivial.
> 
> Use copy&paste from the output of below simple perl script
> (which removes the pagebreaks):

Modified script which also does the extraction of the files
into the current directory as well (below).

  cc -c shatest.c sha1.c sha224-256.c sha384-512.c usha.c hmac.c hkdf.c
  cc -o shatest shatest.o sha1.o sha224-256.o sha384-512.o usha.o hmac.o hkdf.o
  ./shatest

it seems to work (for me on Linux, at least)

-Martin



#!/usr/bin/perl
#
$rfcnum="6234";
$footerpattern="^Eastlake";
$headerpattern="^RFC ${rfcnum}";

$url = "http://tools.ietf.org/rfc/rfc${rfcnum}.txt";;

open(IN,"curl '${url}'|")
  || die("Download of \"$url\" failed: $!\n");
@origdoc = <IN>;
close(IN);

@doc  = ();
$show = 2;
$fname = "";
@file = ();

foreach $line ( @origdoc ) {

   $line =~ tr/\r\n//d;
   if ( $line =~ m/${footerpattern}/io ) {
      $show = 0;
      while ( $#doc >=0 && "" eq $doc[$#doc] ) {
         pop(@doc);
      }
      while ( $#file>=0 && "" eq $file[$#file] ) {
         pop(@file);
      }
   }
   if ( $show>0 ) {
      if ( 2==$show || $line ne "" ) {
         push(@doc, $line);
         $show = 2;
         if ( $fname eq "" && $line =~ m#^/\*\*.* (\w.+) \*\*#io ) {
            $fname = $1;
            $fname =~ tr/a-zA-Z0-9._-//cd;
            @file  = ();
         }
         if ( "" ne $fname ) {
            if ( $line =~ m/^\d/io ) {
               $filedata = join("\n",@file) . "\n";
               $filelen  = length($filedata);
               printf("Writing file \"$fname\" (len=${filelen})\n");
               open(OUT,">$fname")
                 || die("Could not write file \"$fname\": $!\n");
               print OUT $filedata;
               close(OUT);
               $fname = "";
            } else {
               push(@file, $line);
            }
         }
      }
   }
   if ( 0==$show && $line =~ m/${headerpattern}/io ) {
      $show = 1;
   }
}

# print join("\n",@doc), "\n";





[Index of Archives]     [IETF Annoucements]     [IETF]     [IP Storage]     [Yosemite News]     [Linux SCTP]     [Linux Newbies]     [Fedora Users]