2
0

property_query.c 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2021 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 "internal/propertyerr.h"
  10. #include "internal/property.h"
  11. #include "property_local.h"
  12. static int property_idx_cmp(const void *keyp, const void *compare)
  13. {
  14. OSSL_PROPERTY_IDX key = *(const OSSL_PROPERTY_IDX *)keyp;
  15. const OSSL_PROPERTY_DEFINITION *defn =
  16. (const OSSL_PROPERTY_DEFINITION *)compare;
  17. return key - defn->name_idx;
  18. }
  19. const OSSL_PROPERTY_DEFINITION *
  20. ossl_property_find_property(const OSSL_PROPERTY_LIST *list,
  21. OSSL_LIB_CTX *libctx, const char *name)
  22. {
  23. OSSL_PROPERTY_IDX name_idx;
  24. if (list == NULL || name == NULL
  25. || (name_idx = ossl_property_name(libctx, name, 0)) == 0)
  26. return NULL;
  27. return ossl_bsearch(&name_idx, list->properties, list->num_properties,
  28. sizeof(*list->properties), &property_idx_cmp, 0);
  29. }
  30. OSSL_PROPERTY_TYPE ossl_property_get_type(const OSSL_PROPERTY_DEFINITION *prop)
  31. {
  32. return prop->type;
  33. }
  34. const char *ossl_property_get_string_value(OSSL_LIB_CTX *libctx,
  35. const OSSL_PROPERTY_DEFINITION *prop)
  36. {
  37. const char *value = NULL;
  38. if (prop != NULL && prop->type == OSSL_PROPERTY_TYPE_STRING)
  39. value = ossl_property_value_str(libctx, prop->v.str_val);
  40. return value;
  41. }
  42. int64_t ossl_property_get_number_value(const OSSL_PROPERTY_DEFINITION *prop)
  43. {
  44. int64_t value = 0;
  45. if (prop != NULL && prop->type == OSSL_PROPERTY_TYPE_NUMBER)
  46. value = prop->v.int_val;
  47. return value;
  48. }
  49. /* Does a property query have any optional clauses */
  50. int ossl_property_has_optional(const OSSL_PROPERTY_LIST *query)
  51. {
  52. return query->has_optional ? 1 : 0;
  53. }
  54. int ossl_property_is_enabled(OSSL_LIB_CTX *ctx, const char *property_name,
  55. const OSSL_PROPERTY_LIST *prop_list)
  56. {
  57. const OSSL_PROPERTY_DEFINITION *prop;
  58. prop = ossl_property_find_property(prop_list, ctx, property_name);
  59. /* Do a separate check for override as it does not set type */
  60. if (prop == NULL || prop->optional || prop->oper == OSSL_PROPERTY_OVERRIDE)
  61. return 0;
  62. return (prop->type == OSSL_PROPERTY_TYPE_STRING
  63. && ((prop->oper == OSSL_PROPERTY_OPER_EQ
  64. && prop->v.str_val == OSSL_PROPERTY_TRUE)
  65. || (prop->oper == OSSL_PROPERTY_OPER_NE
  66. && prop->v.str_val != OSSL_PROPERTY_TRUE)));
  67. }