[pkg-opensc-commit] [libp11] 29/239: improve code: - reindent - display slot information - display error messages
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit c999be111dd17725999ce050ce1f35637432fe9b
Author: Ludovic Rousseau <ludovic.rousseau+github at gmail.com>
Date: Wed Aug 31 06:50:02 2005 +0000
improve code:
- reindent
- display slot information
- display error messages
---
examples/auth.c | 61 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 37 insertions(+), 24 deletions(-)
diff --git a/examples/auth.c b/examples/auth.c
index 2e6c5b1..ff8b1a4 100644
--- a/examples/auth.c
+++ b/examples/auth.c
@@ -1,49 +1,62 @@
#include <stdio.h>
#include <libp11.h>
-int main(int argc, char **argv)
+#define PKCS11_LIB "/usr/lib/opensc-pkcs11.so"
+
+int main(int argc, char *argv[])
{
PKCS11_CTX *ctx;
- PKCS11_SLOT *slot;
+ PKCS11_SLOT *slot;
unsigned char random[10];
- int rc,len;
+ int rc = 0, i, len;
ctx = PKCS11_CTX_new();
- /* load pkcs #11 module */
- rc = PKCS11_CTX_load(ctx, "/home/aj/opensc/lib/opensc-pkcs11.so");
- if (rc) {
- fprintf(stderr, "loading pkcs11 engine failed\n");
- rc=1;
+ /* load pkcs #11 module */
+ rc = PKCS11_CTX_load(ctx, PKCS11_LIB);
+ if (rc) {
+ fprintf(stderr, "loading pkcs11 engine failed: %s\n",
+ ERR_reason_error_string(ERR_get_error()));
+ rc = 1;
goto nolib;
- }
+ }
- /* get first slot with a token */
- slot = PKCS11_find_token(ctx);
- if (!slot || !slot->token) {
- fprintf(stderr, "no token available\n");
- rc=2;
- goto noslot;
- }
+ /* get first slot with a token */
+ slot = PKCS11_find_token(ctx);
+ if (!slot || !slot->token) {
+ fprintf(stderr, "no token available\n");
+ rc = 2;
+ goto noslot;
+ }
+ printf("Slot manufacturer......: %s\n", slot->manufacturer);
+ printf("Slot description.......: %s\n", slot->description);
+ printf("Slot token label.......: %s\n", slot->token->label);
+ printf("Slot token manufacturer: %s\n", slot->token->manufacturer);
+ printf("Slot token model.......: %s\n", slot->token->model);
+ printf("Slot token serialnr....: %s\n", slot->token->serialnr);
/* get 10 random bytes */
- len=sizeof(random);
+ len = sizeof(random);
rc = PKCS11_generate_random(slot, random, len);
if (rc < 0) {
- fprintf(stderr,"generate_random failed: %d\n",rc);
- rc=3;
+ fprintf(stderr, "generate_random failed: %s\n",
+ ERR_reason_error_string(ERR_get_error()));
+ rc = 3;
goto norandom;
}
- printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
- random[0], random[1], random[2], random[3], random[4],
- random[5], random[6], random[7], random[8], random[9]);
+ printf("\nRandom numbers generated by the token: ");
+ for (i=0; i<len; i++)
+ printf("%02X ", random[i]);
+ printf("\n");
- rc=0;
+ rc = 0;
norandom:
noslot:
- PKCS11_CTX_unload(ctx);
+ PKCS11_CTX_unload(ctx);
+
nolib:
PKCS11_CTX_free(ctx);
return rc;
}
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list