Imported Upstream version 2013.11.12
[tools/build.git] / signdummy
1 #!/usr/bin/perl
2
3 # simple "sign" replacement that does nothing but
4 # write a 2048 byte file with a fixed signature.
5 # sign is used in kiwi builds to sign repositories
6
7 my $mode;
8
9 while (@ARGV) {
10   if ($ARGV[0] =~ /^-([cdrp])$/) {
11     $mode = $1;
12     shift @ARGV;
13     next;
14   }
15   if ($ARGV[0] eq '--') {
16     shift @ARGV;
17     last;
18   }
19   if ($ARGV[0] =~ /^-/) {
20     die("unsupported option $ARGV[0]\n");
21   }
22   last;
23 }
24 if ($mode eq 'p') {
25   my $block = "sIGnMeP\n";
26   $block .= "\0" x (8192 - length($block));
27   (syswrite(STDOUT, $block) || 0) == 8192 || die("pubkey write: $!\n");
28   exit 0;
29 }
30 die("only detached mode possible\n") if !$mode || $mode ne 'd';
31 die("filter mode not supported\n") unless @ARGV;
32
33 for my $file (@ARGV) {
34   local *F;
35   open(F, '<', $file) || die("$file: $!\n");
36   my $buf = '';
37   1 while sysread(F, $buf, 16384, length($buf));
38   close(F) || die("$file: $!\n");
39   my $block = "sIGnMe!\n";
40   $block .= sprintf("%08x%08x\n", length($buf), unpack("%32C*", $buf));
41   $block .= "\0" x (2048 - length($block));
42   open(F, '>', "$file.asc") || die("$file.asc: $!\n");
43   (syswrite(F, $block) || 0) == 2048 || die("$file.asc: $!\n");
44   close(F) || die("$file.asc: $!\n");
45 }