summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/doc/engine.pod
diff options
context:
space:
mode:
authormiod <>2014-07-10 14:14:04 +0000
committermiod <>2014-07-10 14:14:04 +0000
commit3ff93b65bfbf4da2c2e0cf6b752387131854fd98 (patch)
treeebb859fccda290f491c480e68ac91088c2cf7b19 /src/lib/libcrypto/doc/engine.pod
parentf8e6fe02fc43958d79cf9326eebabf8ef8d3ae34 (diff)
downloadopenbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.tar.gz
openbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.tar.bz2
openbsd-3ff93b65bfbf4da2c2e0cf6b752387131854fd98.zip
Try and fix the horrible coding style of the example code snippets.
Diffstat (limited to 'src/lib/libcrypto/doc/engine.pod')
-rw-r--r--src/lib/libcrypto/doc/engine.pod88
1 files changed, 50 insertions, 38 deletions
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod
index 4648af7543..4a6ee59138 100644
--- a/src/lib/libcrypto/doc/engine.pod
+++ b/src/lib/libcrypto/doc/engine.pod
@@ -363,15 +363,15 @@ illustrates how to approach this;
363 const char *engine_id = "ACME"; 363 const char *engine_id = "ACME";
364 ENGINE_load_builtin_engines(); 364 ENGINE_load_builtin_engines();
365 e = ENGINE_by_id(engine_id); 365 e = ENGINE_by_id(engine_id);
366 if(!e) 366 if (!e)
367 /* the engine isn't available */ 367 /* the engine isn't available */
368 return; 368 return;
369 if(!ENGINE_init(e)) { 369 if (!ENGINE_init(e)) {
370 /* the engine couldn't initialise, release 'e' */ 370 /* the engine couldn't initialise, release 'e' */
371 ENGINE_free(e); 371 ENGINE_free(e);
372 return; 372 return;
373 } 373 }
374 if(!ENGINE_set_default_RSA(e)) 374 if (!ENGINE_set_default_RSA(e))
375 /* This should only happen when 'e' can't initialise, but the previous 375 /* This should only happen when 'e' can't initialise, but the previous
376 * statement suggests it did. */ 376 * statement suggests it did. */
377 abort(); 377 abort();
@@ -445,42 +445,54 @@ cases but the name can not. This function should initialise the ENGINE
445and set it as the default for everything except RAND and then return a 445and set it as the default for everything except RAND and then return a
446boolean success or failure. 446boolean success or failure.
447 447
448 int generic_load_engine_fn(const char *engine_id, 448 int
449 const char **pre_cmds, int pre_num, 449 generic_load_engine_fn(const char *engine_id,
450 const char **post_cmds, int post_num) 450 const char **pre_cmds, int pre_num,
451 const char **post_cmds, int post_num)
451 { 452 {
452 ENGINE *e = ENGINE_by_id(engine_id); 453 ENGINE *e = ENGINE_by_id(engine_id);
453 if(!e) return 0; 454
454 while(pre_num--) { 455 if (!e)
455 if(!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) { 456 return 0;
456 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, 457 while (pre_num--) {
457 pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)"); 458 if (!ENGINE_ctrl_cmd_string(e,
458 ENGINE_free(e); 459 pre_cmds[0], pre_cmds[1], 0)) {
459 return 0; 460 fprintf(stderr,
460 } 461 "Failed command (%s - %s:%s)\n",
461 pre_cmds += 2; 462 engine_id, pre_cmds[0],
462 } 463 pre_cmds[1] ? pre_cmds[1] : "(NULL)");
463 if(!ENGINE_init(e)) { 464 ENGINE_free(e);
464 fprintf(stderr, "Failed initialisation\n"); 465 return 0;
465 ENGINE_free(e); 466 }
466 return 0; 467 pre_cmds += 2;
467 } 468 }
468 /* ENGINE_init() returned a functional reference, so free the structural 469 if (!ENGINE_init(e)) {
469 * reference from ENGINE_by_id(). */ 470 fprintf(stderr, "Failed initialisation\n");
470 ENGINE_free(e); 471 ENGINE_free(e);
471 while(post_num--) { 472 return 0;
472 if(!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) { 473 }
473 fprintf(stderr, "Failed command (%s - %s:%s)\n", engine_id, 474 /*
474 post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)"); 475 * ENGINE_init() returned a functional reference,
475 ENGINE_finish(e); 476 * so free the structural reference from
476 return 0; 477 * ENGINE_by_id().
477 } 478 */
478 post_cmds += 2; 479 ENGINE_free(e);
479 } 480 while (post_num--) {
480 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND); 481 if (!ENGINE_ctrl_cmd_string(e,
481 /* Success */ 482 post_cmds[0], post_cmds[1], 0)) {
482 return 1; 483 fprintf(stderr,
483 } 484 "Failed command (%s - %s:%s)\n",
485 engine_id, post_cmds[0],
486 post_cmds[1] ? post_cmds[1] : "(NULL)");
487 ENGINE_finish(e);
488 return 0;
489 }
490 post_cmds += 2;
491 }
492 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
493 /* Success */
494 return 1;
495}
484 496
485Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can 497Note that ENGINE_ctrl_cmd_string() accepts a boolean argument that can
486relax the semantics of the function - if set non-zero it will only return 498relax the semantics of the function - if set non-zero it will only return