Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib add a static functio...
details: https://anonhg.NetBSD.org/src/rev/0945b834c5eb
branches: trunk
changeset: 755017:0945b834c5eb
user: agc <agc%NetBSD.org@localhost>
date: Thu May 20 00:36:31 2010 +0000
description:
add a static function to resolve the userid in one place, and start to use it
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/netpgp.c | 50 +++++++++++------------
1 files changed, 24 insertions(+), 26 deletions(-)
diffs (89 lines):
diff -r 2cc0530d4a18 -r 0945b834c5eb crypto/external/bsd/netpgp/dist/src/lib/netpgp.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c Thu May 20 00:33:01 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/netpgp.c Thu May 20 00:36:31 2010 +0000
@@ -34,7 +34,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: netpgp.c,v 1.51 2010/05/19 02:50:16 agc Exp $");
+__RCSID("$NetBSD: netpgp.c,v 1.52 2010/05/20 00:36:31 agc Exp $");
#endif
#include <sys/types.h>
@@ -381,6 +381,25 @@
return (uint64_t)strtoll(s, NULL, 10);
}
+/* resolve the userid */
+static const __ops_key_t *
+resolve_userid(netpgp_t *netpgp, const char *userid)
+{
+ const __ops_key_t *key;
+ __ops_io_t *io;
+
+ if (userid == NULL) {
+ userid = netpgp_getvar(netpgp, "userid");
+ } else if (userid[0] == '0' && userid[1] == 'x') {
+ userid += 2;
+ }
+ io = netpgp->io;
+ if ((key = __ops_getkeybyname(io, netpgp->pubring, userid)) == NULL) {
+ (void) fprintf(io->errs, "Can't find key '%s'\n", userid);
+ }
+ return key;
+}
+
/***************************************************************************/
/* exported functions start here */
/***************************************************************************/
@@ -654,14 +673,7 @@
char *newkey;
io = netpgp->io;
- if (name == NULL) {
- name = netpgp_getvar(netpgp, "userid");
- } else if (name[0] == '0' && name[1] == 'x') {
- name += 2;
- }
- key = __ops_getkeybyname(netpgp->io, netpgp->pubring, name);
- if (key == NULL) {
- (void) fprintf(io->errs, "Can't find key '%s'\n", name);
+ if ((key = resolve_userid(netpgp, name)) == NULL) {
return NULL;
}
if (strcmp(fmt, "mr") == 0) {
@@ -684,16 +696,8 @@
__ops_io_t *io;
io = netpgp->io;
- if (name == NULL) {
- name = netpgp_getvar(netpgp, "userid");
- } else if (name[0] == '0' && name[1] == 'x') {
- name += 2;
- }
- key = __ops_getkeybyname(io, netpgp->pubring, name);
- if (key == NULL) {
- (void) fprintf(io->errs,
- "Cannot find own key \"%s\" in keyring\n", name);
- return 0;
+ if ((key = resolve_userid(netpgp, name)) == NULL) {
+ return NULL;
}
return __ops_export_key(io, key, NULL);
}
@@ -817,14 +821,8 @@
"netpgp_encrypt_file: no filename specified\n");
return 0;
}
- if (userid == NULL) {
- userid = netpgp_getvar(netpgp, "userid");
- }
suffix = (armored) ? ".asc" : ".gpg";
- keypair = __ops_getkeybyname(io, netpgp->pubring, userid);
- if (keypair == NULL) {
- (void) fprintf(io->errs, "Userid '%s' not found in keyring\n",
- userid);
+ if ((keypair = resolve_userid(netpgp, userid)) == NULL) {
return 0;
}
if (out == NULL) {
Home |
Main Index |
Thread Index |
Old Index