From 79439e76cc5b302222874a1f9e93665cb12801ac Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Mon, 5 Sep 2016 12:53:02 +0200 Subject: cpp: Add convenience update function to a key * lang/cpp/src/key.cpp (Key::update): New. * lang/cpp/src/key.h: Update accordingly. -- This function helps if you have an incomplete key or want to make sure all info in a key is complete (e.g. validity / tofuinfo) --- lang/cpp/src/key.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lang/cpp/src/key.cpp') diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 204eeca2..cfa1ba31 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -24,6 +24,7 @@ #include "util.h" #include "tofuinfo.h" +#include "context.h" #include @@ -322,6 +323,27 @@ const Key &Key::mergeWith(const Key &other) return *this; } +void Key::update() +{ + auto ctx = Context::createForProtocol(protocol()); + if (!ctx) { + return; + } + ctx->setKeyListMode(KeyListMode::Local | + KeyListMode::Signatures | + KeyListMode::SignatureNotations | + KeyListMode::Validate | + KeyListMode::WithTofu); + Error err; + auto newKey = ctx->key(primaryFingerprint(), err, hasSecret()); + delete ctx; + if (err) { + return; + } + swap(newKey); + return; +} + // // // class Subkey -- cgit v1.2.3