+ return gensig($rsa, $uid, $args);
+}
+
+# FIXME: handle non-RSA keys
+
+# FIXME: this currently only makes self-sigs -- we should parameterize
+# it to make certifications over keys other than the issuer.
+sub gensig {
+ my $rsa = shift;
+ my $uid = shift;
+ my $args = shift;
+
+ # FIXME: allow signature creation using digests other than SHA256
+ $rsa->use_sha256_hash();
+
+ # see page 22 of RFC 4880 for why i think this is the right padding
+ # choice to use:
+ $rsa->use_pkcs1_padding();
+
+ if (! $rsa->check_key()) {
+ die "key does not check\n";
+ }
+
+ my $certtype = $args->{certification_type} + 0;
+
+ my $version = pack('C', 4);
+ my $sigtype = pack('C', $certtype);
+ # RSA
+ my $pubkey_algo = pack('C', $asym_algos->{rsa});
+ # SHA256 FIXME: allow signature creation using digests other than SHA256
+ my $hash_algo = pack('C', $digests->{sha256});
+
+ # FIXME: i'm worried about generating a bazillion new OpenPGP
+ # certificates from the same key, which could easily happen if you run
+ # this script more than once against the same key (because the
+ # timestamps will differ). How can we prevent this?
+
+ # this argument (if set) overrides the current time, to
+ # be able to create a standard key. If we read the key from a file
+ # instead of stdin, should we use the creation time on the file?
+ my $sig_timestamp = ($args->{sig_timestamp} + 0);
+ my $key_timestamp = ($args->{key_timestamp} + 0);
+
+ if ($key_timestamp > $sig_timestamp) {
+ die "key timestamp must not be later than signature timestamp\n";
+ }
+
+ my $creation_time_packet = pack('CCN', 5, $subpacket_types->{sig_creation_time}, $sig_timestamp);
+
+ my $hashed_subs = $creation_time_packet.$args->{hashed_subpackets};
+
+ my $subpacket_octets = pack('n', length($hashed_subs));