x509_meth.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2018-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (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/types.h>
  16. #include "x509_local.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. goto err;
  24. }
  25. return method;
  26. err:
  27. OPENSSL_free(method);
  28. return NULL;
  29. }
  30. void X509_LOOKUP_meth_free(X509_LOOKUP_METHOD *method)
  31. {
  32. if (method != NULL)
  33. OPENSSL_free(method->name);
  34. OPENSSL_free(method);
  35. }
  36. int X509_LOOKUP_meth_set_new_item(X509_LOOKUP_METHOD *method,
  37. int (*new_item) (X509_LOOKUP *ctx))
  38. {
  39. method->new_item = new_item;
  40. return 1;
  41. }
  42. int (*X509_LOOKUP_meth_get_new_item(const X509_LOOKUP_METHOD* method))
  43. (X509_LOOKUP *ctx)
  44. {
  45. return method->new_item;
  46. }
  47. int X509_LOOKUP_meth_set_free(
  48. X509_LOOKUP_METHOD *method,
  49. void (*free_fn) (X509_LOOKUP *ctx))
  50. {
  51. method->free = free_fn;
  52. return 1;
  53. }
  54. void (*X509_LOOKUP_meth_get_free(const X509_LOOKUP_METHOD* method))
  55. (X509_LOOKUP *ctx)
  56. {
  57. return method->free;
  58. }
  59. int X509_LOOKUP_meth_set_init(X509_LOOKUP_METHOD *method,
  60. int (*init) (X509_LOOKUP *ctx))
  61. {
  62. method->init = init;
  63. return 1;
  64. }
  65. int (*X509_LOOKUP_meth_get_init(const X509_LOOKUP_METHOD* method))
  66. (X509_LOOKUP *ctx)
  67. {
  68. return method->init;
  69. }
  70. int X509_LOOKUP_meth_set_shutdown(
  71. X509_LOOKUP_METHOD *method,
  72. int (*shutdown) (X509_LOOKUP *ctx))
  73. {
  74. method->shutdown = shutdown;
  75. return 1;
  76. }
  77. int (*X509_LOOKUP_meth_get_shutdown(const X509_LOOKUP_METHOD* method))
  78. (X509_LOOKUP *ctx)
  79. {
  80. return method->shutdown;
  81. }
  82. int X509_LOOKUP_meth_set_ctrl(
  83. X509_LOOKUP_METHOD *method,
  84. X509_LOOKUP_ctrl_fn ctrl)
  85. {
  86. method->ctrl = ctrl;
  87. return 1;
  88. }
  89. X509_LOOKUP_ctrl_fn X509_LOOKUP_meth_get_ctrl(const X509_LOOKUP_METHOD *method)
  90. {
  91. return method->ctrl;
  92. }
  93. int X509_LOOKUP_meth_set_get_by_subject(X509_LOOKUP_METHOD *method,
  94. X509_LOOKUP_get_by_subject_fn get_by_subject)
  95. {
  96. method->get_by_subject = get_by_subject;
  97. return 1;
  98. }
  99. X509_LOOKUP_get_by_subject_fn X509_LOOKUP_meth_get_get_by_subject(
  100. const X509_LOOKUP_METHOD *method)
  101. {
  102. return method->get_by_subject;
  103. }
  104. int X509_LOOKUP_meth_set_get_by_issuer_serial(X509_LOOKUP_METHOD *method,
  105. X509_LOOKUP_get_by_issuer_serial_fn get_by_issuer_serial)
  106. {
  107. method->get_by_issuer_serial = get_by_issuer_serial;
  108. return 1;
  109. }
  110. X509_LOOKUP_get_by_issuer_serial_fn
  111. X509_LOOKUP_meth_get_get_by_issuer_serial(const X509_LOOKUP_METHOD *method)
  112. {
  113. return method->get_by_issuer_serial;
  114. }
  115. int X509_LOOKUP_meth_set_get_by_fingerprint(X509_LOOKUP_METHOD *method,
  116. X509_LOOKUP_get_by_fingerprint_fn get_by_fingerprint)
  117. {
  118. method->get_by_fingerprint = get_by_fingerprint;
  119. return 1;
  120. }
  121. X509_LOOKUP_get_by_fingerprint_fn X509_LOOKUP_meth_get_get_by_fingerprint(
  122. const X509_LOOKUP_METHOD *method)
  123. {
  124. return method->get_by_fingerprint;
  125. }
  126. int X509_LOOKUP_meth_set_get_by_alias(X509_LOOKUP_METHOD *method,
  127. X509_LOOKUP_get_by_alias_fn get_by_alias)
  128. {
  129. method->get_by_alias = get_by_alias;
  130. return 1;
  131. }
  132. X509_LOOKUP_get_by_alias_fn X509_LOOKUP_meth_get_get_by_alias(
  133. const X509_LOOKUP_METHOD *method)
  134. {
  135. return method->get_by_alias;
  136. }