get_micalg (from mutt)
ActivePublic

Authored by werner on Feb 14 2018, 12:18 PM.
1​/* Find the "micalg" parameter from the last Gpgme operation on
2​ context CTX. It is expected that this operation was a sign
3​ operation. Return the algorithm name as a C string in buffer BUF
4​ which must have been allocated by the caller with size BUFLEN.
5​ Returns 0 on success or -1 in case of an error. The return string
6​ is truncted to BUFLEN - 1. */
7​static int get_micalg (gpgme_ctx_t ctx, int use_smime, char *buf, size_t buflen)
8​{
9​ gpgme_sign_result_t result = NULL;
10​ const char *algorithm_name = NULL;
11
12​ if (buflen < 5)
13​ return -1;
14
15​ *buf = 0;
16​ result = gpgme_op_sign_result (ctx);
17​ if (result && result->signatures)
18​ {
19​ algorithm_name = gpgme_hash_algo_name (result->signatures->hash_algo);
20​ if (algorithm_name)
21​ {
22​ if (use_smime)
23​ {
24​ /* convert GPGME raw hash name to RFC 2633 format */
25​ snprintf (buf, buflen, "%s", algorithm_name);
26​ ascii_strlower (buf);
27​ } else {
28​ /* convert GPGME raw hash name to RFC 3156 format */
29​ snprintf (buf, buflen, "pgp-%s", algorithm_name);
30​ ascii_strlower (buf + 4);
31​ }
32​ }
33​ }
34
35​ return *buf? 0:-1;
36​}
werner created this paste.Feb 14 2018, 12:18 PM