aboutsummaryrefslogtreecommitdiffstats
path: root/g10/ccid-driver.c
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2004-09-15 18:41:36 +0000
committerDavid Shaw <[email protected]>2004-09-15 18:41:36 +0000
commita46e83b8e31db620ec23dd0cb245a648d2f822a1 (patch)
treea53e5753d04e4e897946996e2fe0d1437ae64736 /g10/ccid-driver.c
parent* configure.ac: Give warning when using capabilities. Check for (diff)
downloadgnupg-a46e83b8e31db620ec23dd0cb245a648d2f822a1.tar.gz
gnupg-a46e83b8e31db620ec23dd0cb245a648d2f822a1.zip
* gpgv.c (agent_scd_getattr): Stub.
* misc.c (get_signature_count): New. Get the signature count from a smartcard. (pct_expando): Call it here so the %c expando becomes the number of signatures issued. This allows for notations or the like with an automatic signature count. * ccid-driver.c (usb_get_string_simple): Replacement function to work with older libusb.
Diffstat (limited to '')
-rw-r--r--g10/ccid-driver.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/g10/ccid-driver.c b/g10/ccid-driver.c
index 7fc241cc2..7277ac20c 100644
--- a/g10/ccid-driver.c
+++ b/g10/ccid-driver.c
@@ -214,7 +214,63 @@ static int bulk_out (ccid_driver_t handle, unsigned char *msg, size_t msglen);
static int bulk_in (ccid_driver_t handle, unsigned char *buffer, size_t length,
size_t *nread, int expected_type, int seqno);
+#ifndef HAVE_USB_GET_STRING_SIMPLE
+/* This function adapted from the libusb 0.1.8 sources. It's here so
+ that systems with an older libusb can still use smartcards. */
+
+static int usb_get_string_simple(usb_dev_handle *dev, int indx, char *buf,
+ size_t buflen)
+{
+ char tbuf[256];
+ int ret, langid, si, di;
+
+ /*
+ * Asking for the zero'th index is special - it returns a string
+ * descriptor that contains all the language IDs supported by the
+ * device. Typically there aren't many - often only one. The
+ * language IDs are 16 bit numbers, and they start at the third byte
+ * in the descriptor. See USB 2.0 specification, section 9.6.7, for
+ * more information on this. */
+
+ ret=usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
+ (USB_DT_STRING << 8), 0, tbuf, sizeof(tbuf), 1000);
+
+ if (ret < 0)
+ return ret;
+
+ if (ret < 4)
+ return -EIO;
+
+ langid = tbuf[2] | (tbuf[3] << 8);
+
+ ret=usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR,
+ (USB_DT_STRING << 8)+indx,langid,tbuf,sizeof(tbuf),1000);
+ if (ret < 0)
+ return ret;
+
+ if (tbuf[1] != USB_DT_STRING)
+ return -EIO;
+
+ if (tbuf[0] > ret)
+ return -EFBIG;
+
+ for (di = 0, si = 2; si < tbuf[0]; si += 2) {
+ if (di >= (buflen - 1))
+ break;
+
+ if (tbuf[si + 1]) /* high byte */
+ buf[di++] = '?';
+ else
+ buf[di++] = tbuf[si];
+ }
+
+ buf[di] = 0;
+
+ return di;
+}
+
+#endif /* !HAVE_USB_GET_STRING_SIMPLE */
/* Convert a little endian stored 4 byte value into an unsigned
integer. */