選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

76 行
2.4 KiB

  1. /* Copyright (c) 2016, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #include <openssl/obj.h>
  15. #include <assert.h>
  16. #include <string.h>
  17. #include <openssl/evp.h>
  18. #include "../../crypto/internal.h"
  19. struct wrapped_callback {
  20. void (*callback)(const OBJ_NAME *, void *arg);
  21. void *arg;
  22. };
  23. static void cipher_callback(const EVP_CIPHER *cipher, const char *name,
  24. const char *unused, void *arg) {
  25. const struct wrapped_callback *wrapped = (struct wrapped_callback *)arg;
  26. OBJ_NAME obj_name;
  27. OPENSSL_memset(&obj_name, 0, sizeof(obj_name));
  28. obj_name.type = OBJ_NAME_TYPE_CIPHER_METH;
  29. obj_name.name = name;
  30. obj_name.data = (const char *)cipher;
  31. wrapped->callback(&obj_name, wrapped->arg);
  32. }
  33. static void md_callback(const EVP_MD *md, const char *name, const char *unused,
  34. void *arg) {
  35. const struct wrapped_callback *wrapped = (struct wrapped_callback*) arg;
  36. OBJ_NAME obj_name;
  37. OPENSSL_memset(&obj_name, 0, sizeof(obj_name));
  38. obj_name.type = OBJ_NAME_TYPE_MD_METH;
  39. obj_name.name = name;
  40. obj_name.data = (const char *)md;
  41. wrapped->callback(&obj_name, wrapped->arg);
  42. }
  43. void OBJ_NAME_do_all_sorted(int type,
  44. void (*callback)(const OBJ_NAME *, void *arg),
  45. void *arg) {
  46. struct wrapped_callback wrapped;
  47. wrapped.callback = callback;
  48. wrapped.arg = arg;
  49. if (type == OBJ_NAME_TYPE_CIPHER_METH) {
  50. EVP_CIPHER_do_all_sorted(cipher_callback, &wrapped);
  51. } else if (type == OBJ_NAME_TYPE_MD_METH) {
  52. EVP_MD_do_all_sorted(md_callback, &wrapped);
  53. } else {
  54. assert(0);
  55. }
  56. }
  57. void OBJ_NAME_do_all(int type, void (*callback)(const OBJ_NAME *, void *arg),
  58. void *arg) {
  59. OBJ_NAME_do_all_sorted(type, callback, arg);
  60. }