1

GPGME提供有关密钥信任级别的信息作为类型为的owner_trust字段。但是,我在文档或头文件中找不到允许我更改密钥有效性的函数。gpgme_validity_tgpgme.h

GnuPG 命令行工具确实允许更改密钥的信任级别:

$ gpg --edit-key alice@example.com
> trust

GPGME 库是否甚至支持更改owner_trust字段?如果是这样,我该如何使用它?

我正在使用最新版本的 GPGME,即1.16.0(提交哈希1021c8645555502d914afffaa3707609809c9459)。

4

1 回答 1

1

应该可以gpgme_op_interact用来实现这一点。

下面演示了使用 Python 绑定的过程,但应该可以使用 C API 编写类似的代码。

import gpg

def trust_at(level):
    done = False
    def interact_cb(status, arg):
        nonlocal done
        if status in ('KEY_CONSIDERED', 'GOT_IT', ''):
            return
        if status == 'GET_LINE':
            if arg == 'keyedit.prompt':
                if done:
                    return 'quit'
                done = True
                return 'trust'
            if arg == 'edit_ownertrust.value':
                return level
        # needed if we set trust level to 5
        if (status, arg) == ('GET_BOOL', 'edit_ownertrust.set_ultimate.okay'):
            return 'y'
        assert False
    return interact_cb

with gpg.Context() as gnupg:
    key = gnupg.get_key(FINGERPRINT)
    gnupg.interact(key, trust_at('4'))
于 2022-02-11T19:15:51.787 回答