code: def gen_key(self, input):
          
          args = ["--gen-key --cert-digest-algo SHA512 --batch"]
          key = self._result_map['generate'](self)
          f = _make_binary_stream(input, self._encoding)
          self._handle_io(args, f, key, binary=True)
          f.close()
  
          fpr = str(key.fingerprint)
          if len(fpr) == 20:
              for d in map(lambda x: os.path.dirname(x),
                           [self.temp_keyring, self.temp_secring]):
                  if not os.path.exists(d):
                      os.makedirs(d)
  
              if self.temp_keyring:
                  if os.path.isfile(self.temp_keyring):
                      prefix = os.path.join(self.temp_keyring, fpr)
                      try: os.rename(self.temp_keyring, prefix+".pubring")
                      except OSError as ose: log.error(str(ose))
  
              if self.temp_secring:
                  if os.path.isfile(self.temp_secring):
                      prefix = os.path.join(self.temp_secring, fpr)
                      try: os.rename(self.temp_secring, prefix+".secring")
                      except OSError as ose: log.error(str(ose))
  
          log.info("Key created. Fingerprint: %s" % fpr)
          key.keyring = self.temp_keyring
          key.secring = self.temp_secring
          self.temp_keyring = None
          self.temp_secring = None
  
          return key
docs: Generate a GnuPG key through batch file key generation. See
          :meth:`GPG.gen_key_input()` for creating the control input.
  
          >>> import gnupg
          >>> gpg = gnupg.GPG(homedir="doctests")
          >>> key_input = gpg.gen_key_input()
          >>> key = gpg.gen_key(key_input)
          >>> assert key.fingerprint
  
          :param dict input: A dictionary of parameters and values for the new
                             key.
          :returns: The result mapping with details of the new key, which is a
                    :class:`GenKey <gnupg._parsers.GenKey>` object.