x509_meth.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <errno.h>
  12. #include "internal/cryptlib.h"
  13. #include <openssl/asn1.h>
  14. #include <openssl/x509.h>
  15. #include <openssl/ossl_typ.h>
  16. #include "x509_lcl.h"
  17. X509_LOOKUP_METHOD *X509_LOOKUP_meth_new(const char *name)
  18. {
  19. X509_LOOKUP_METHOD *method = OPENSSL_zalloc(sizeof(X509_LOOKUP_METHOD));
  20. if (method != NULL) {
  21. method->name = OPENSSL_strdup(name);
  22. if (method->name == NULL) {
  23. X509err(X509_F_X509_LOOKUP_METH_NEW, ERR_R_MALLOC_FAILURE);
  24. goto err;
  25. }
  26. }
  27. return method;
  28. err:
  29. OPENSSL_free(method);
  30. return NULL;
  31. }
  32. void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method)
  33. {
  34. if (method != NULL)
  35. OPENSSL_free(method->name);
  36. OPENSSL_free(method);
  37. }
  38. int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
  39. int (*new_item) (X509_LOOKUP *ctx))
  40. {
  41. method->new_item = new_item;
  42. return 1;
  43. }
  44. int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
  45. (X509_LOOKUP *ctx)
  46. {
  47. return method->new_item;
  48. }
  49. int X509_LOOKUP_meth_set_free(
  50. X509_LOOKUP_METHOD *method,
  51. void (*free_fn) (X509_LOOKUP *ctx))
  52. {
  53. method->free = free_fn;
  54. return 1;
  55. }
  56. void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
  57. (X509_LOOKUP *ctx)
  58. {
  59. return method->free;
  60. }
  61. int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
  62. int (*init) (X509_LOOKUP *ctx))
  63. {
  64. method->init = init;
  65. return 1;
  66. }
  67. int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
  68. (X509_LOOKUP *ctx)
  69. {
  70. return method->init;
  71. }
  72. int X509_LOOKUP_meth_set_shutdown(
  73. X509_LOOKUP_METHOD *method,
  74. int (*shutdown) (X509_LOOKUP *ctx))
  75. {
  76. method->shutdown = shutdown;
  77. return 1;
  78. }
  79. int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
  80. (X509_LOOKUP *ctx)
  81. {
  82. return method->shutdown;
  83. }
  84. int X509_LOOKUP_meth_set_ctrl(
  85. X509_LOOKUP_METHOD *method,
  86. X509_LOOKUP_ctrl_fn ctrl)
  87. {
  88. method->ctrl = ctrl;
  89. return 1;
  90. }
  91. X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method)
  92. {
  93. return method->ctrl;
  94. }
  95. int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
  96. X509_LOOKUP_get_by_subject_fn get_by_subject)
  97. {
  98. method->get_by_subject = get_by_subject;
  99. return 1;
  100. }
  101. X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
  102. const X509_LOOKUP_METHOD *method)
  103. {
  104. return method->get_by_subject;
  105. }
  106. int X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method,
  107. X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial)
  108. {
  109. method->get_by_issuer_serial = get_by_issuer_serial;
  110. return 1;
  111. }
  112. X509_LOOKUP_get_by_issuer_serial_fn
  113. X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD *method)
  114. {
  115. return method->get_by_issuer_serial;
  116. }
  117. int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
  118. X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint)
  119. {
  120. method->get_by_fingerprint = get_by_fingerprint;
  121. return 1;
  122. }
  123. X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
  124. const X509_LOOKUP_METHOD *method)
  125. {
  126. return method->get_by_fingerprint;
  127. }
  128. int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
  129. X509_LOOKUP_get_by_alias_fn get_by_alias)
  130. {
  131. method->get_by_alias = get_by_alias;
  132. return 1;
  133. }
  134. X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
  135. const X509_LOOKUP_METHOD *method)
  136. {
  137. return method->get_by_alias;
  138. }