'Generate the public key.'

def generate(self, module):

    if (not os.path.exists(self.privatekey_path)):
        raise PublicKeyError(('The    private    key    %s    does    not    exist' % self.privatekey_path))
    if ((not self.check(module, perms_required=False)) or self.force):
        try:
            if (self.format == 'OpenSSH'):
                privatekey_content = open(self.privatekey_path, 'rb').read()
                key = crypto_serialization.load_pem_private_key(privatekey_content, password=self.privatekey_passphrase, backend=default_backend())
                publickey_content = key.public_key().public_bytes(crypto_serialization.Encoding.OpenSSH, crypto_serialization.PublicFormat.OpenSSH)
            else:
                self.privatekey = crypto_utils.load_privatekey(self.privatekey_path, self.privatekey_passphrase)
                publickey_content = crypto.dump_publickey(crypto.FILETYPE_PEM, self.privatekey)
            with open(self.path, 'wb') as publickey_file:
                publickey_file.write(publickey_content)
            self.changed = True
        except (IOError, OSError) as exc:
            raise PublicKeyError(exc)
        except AttributeError as exc:
            self.remove()
            raise PublicKeyError('You    need    to    have    PyOpenSSL>=16.0.0    to    generate    public    keys')
    self.fingerprint = crypto_utils.get_fingerprint(self.privatekey_path, self.privatekey_passphrase)
    file_args = module.load_file_common_arguments(module.params)
    if module.set_fs_attributes_if_different(file_args, False):
        self.changed = True
