use the environment to determine usage flags (default to certify)
[monkeysphere.git] / src / keytrans / pem2openpgp
index 3d9f6f83eb34cc43fdac303891c45194d7a15bf5..315a2b5dc5a95638f5a031679f00f8c77b3c2d0c 100755 (executable)
@@ -352,7 +352,25 @@ my $hash_algo = pack('C', $digests->{sha1});
 # could an environment variable (if set) override 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 $timestamp = time();
+my $timestamp = 0;
+if (defined $ENV{PEM2OPENPGP_TIMESTAMP}) {
+  $timestamp = ($ENV{PEM2OPENPGP_TIMESTAMP} + 0);
+} else {
+  $timestamp = time();
+}
+
+my $flags = 0;
+if (! defined $ENV{PEM2OPENPGP_USAGE_FLAGS}) {
+  $flags = $usage_flags->{certify};
+} else {
+  my @ff = split(",", $ENV{PEM2OPENPGP_USAGE_FLAGS});
+  foreach my $f (@ff) {
+    if (! defined $usage_flags->{$f}) {
+      die "No such flag $f";
+    }
+    $flags |= $usage_flags->{$f};
+  }
+}
 
 my $creation_time_packet = pack('CCN', 5, $subpacket_types->{sig_creation_time}, $timestamp);
 
@@ -360,7 +378,7 @@ my $creation_time_packet = pack('CCN', 5, $subpacket_types->{sig_creation_time},
 # FIXME: HARDCODED: what if someone wants to select a different set of
 # usage flags?  For now, we do only authentication because that's what
 # monkeysphere needs.
-my $usage_packet = pack('CCC', 2, $subpacket_types->{usage_flags}, $usage_flags->{authenticate});
+my $usage_packet = pack('CCC', 2, $subpacket_types->{usage_flags}, $flags);
 
 
 # FIXME: HARDCODED: how should we determine how far off to set the