summaryrefslogtreecommitdiffstats
path: root/common/sexputil.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2005-04-13 11:39:38 +0200
committerWerner Koch <wk@gnupg.org>2005-04-13 11:39:38 +0200
commitf084afaeda288a0111f5d1c0e49a78a0a85c56a8 (patch)
tree2336fffc3f58211192402c14b3c0c92c731e8b69 /common/sexputil.c
parent(confucius_mktmpdir): Changed to use mkdtmp(3). (diff)
downloadgnupg2-f084afaeda288a0111f5d1c0e49a78a0a85c56a8.tar.xz
gnupg2-f084afaeda288a0111f5d1c0e49a78a0a85c56a8.zip
Added missing file
Diffstat (limited to 'common/sexputil.c')
-rw-r--r--common/sexputil.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/common/sexputil.c b/common/sexputil.c
new file mode 100644
index 000000000..853d7e58a
--- /dev/null
+++ b/common/sexputil.c
@@ -0,0 +1,63 @@
+/* sexputil.c - Utility fnctions for S-expressions.
+ * Copyright (C) 2005 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+/* This file implements a few utility functions useful when working
+ with canonical encrypted S-expresions (i.e. not the S-exprssion
+ objects from libgcrypt). */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include "util.h"
+
+
+/* Return the so called "keygrip" which is the SHA-1 hash of the
+ public key parameters expressed in a way depended on the algorithm.
+
+ KEY is expected to be an canonical encoded S-expression with a
+ public or private key. KEYLEN is the length of that buffer.
+
+ GRIP must be at least 20 bytes long On success 0 is return, on
+ error an aerror code. */
+gpg_error_t
+keygrip_from_canon_sexp (const unsigned char *key, size_t keylen,
+ unsigned char *grip)
+{
+ gpg_error_t err;
+ gcry_sexp_t sexp;
+
+ if (!grip)
+ return gpg_error (GPG_ERR_INV_VALUE);
+ err = gcry_sexp_sscan (&sexp, NULL, key, keylen);
+ if (err)
+ return err;
+ if (!gcry_pk_get_keygrip (sexp, grip))
+ err = gpg_error (GPG_ERR_INTERNAL);
+ gcry_sexp_release (sexp);
+ return err;
+}
+