Exemplo n.º 1
0
  public void _sign(SignOptions options) throws Exception {
    String password = null;
    if (options.password() == null) {
      Console console = System.console();
      if (console == null) {
        error("No -p/--password set for PGP key and no console to ask");
      } else {
        char[] pw = console.readPassword("Passsword: ");
        if (pw == null || pw.length == 0) {
          error("Password not entered");
        }
        password = new String(pw);
      }
    } else password = options.password();

    Signer signer =
        new Signer(new String(password), options.command(getProperty("gpg", System.getenv("GPG"))));

    if (signer == null || password == null || !isOk()) return;

    List<String> args = options._arguments();

    if (args.isEmpty()) {
      List<URI> files = nexus.files();
      for (URI uri : files) {
        try {
          trace("signing %s", relative(uri));
          File f = nexus.download(uri);
          byte[] signature = signer.sign(f);
          if (options.show()) show(signature);
          else nexus.upload(new URI(uri + ".asc"), signature);
        } catch (Exception e) {
          exception(e, "could not download/sign/upload %s", relative(uri));
        }
      }
    } else {
      for (String arg : args) {
        File f = getFile(arg);
        if (!f.isFile()) {
          error("Can't find file %s", f);
        } else {
          byte[] signature = signer.sign(f);
          if (options.show()) show(signature);
          else {
            File out = new File(f.getParentFile(), f.getName() + ".asc");
            IO.store(signature, out);
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 public void _files(FilesOption options) throws Exception {
   URI base = this.options.url();
   for (URI uri : nexus.files()) {
     System.out.printf("%s%n", base.relativize(uri));
   }
 }