update to upstream 20150115
[tools/build.git] / signdummy
1 #!/usr/bin/perl
2
3 ################################################################
4 #
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
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 version 2 or 3 as
9 # published by the Free Software Foundation.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #
21 ################################################################
22
23 # simple "sign" replacement that does nothing but
24 # write a 2048 byte file with a fixed signature.
25 # sign is used in kiwi builds to sign repositories
26
27 my $mode;
28
29 while (@ARGV) {
30   if ($ARGV[0] =~ /^-([cdrp])$/) {
31     $mode = $1;
32     shift @ARGV;
33     next;
34   }
35   if ($ARGV[0] eq '--') {
36     shift @ARGV;
37     last;
38   }
39   if ($ARGV[0] =~ /^-/) {
40     die("unsupported option $ARGV[0]\n");
41   }
42   last;
43 }
44 if ($mode eq 'p') {
45   my $block = "sIGnMeP\n";
46   $block .= "\0" x (8192 - length($block));
47   (syswrite(STDOUT, $block) || 0) == 8192 || die("pubkey write: $!\n");
48   exit 0;
49 }
50 die("only detached mode possible\n") if !$mode || $mode ne 'd';
51 die("filter mode not supported\n") unless @ARGV;
52
53 for my $file (@ARGV) {
54   local *F;
55   open(F, '<', $file) || die("$file: $!\n");
56   my $buf = '';
57   1 while sysread(F, $buf, 16384, length($buf));
58   close(F) || die("$file: $!\n");
59   my $block = "sIGnMe!\n";
60   $block .= sprintf("%08x%08x\n", length($buf), unpack("%32C*", $buf));
61   $block .= "\0" x (2048 - length($block));
62   open(F, '>', "$file.asc") || die("$file.asc: $!\n");
63   (syswrite(F, $block) || 0) == 2048 || die("$file.asc: $!\n");
64   close(F) || die("$file.asc: $!\n");
65 }