pcy_lib.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2004-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 "internal/cryptlib.h"
  10. #include <openssl/x509.h>
  11. #include <openssl/x509v3.h>
  12. #include "pcy_local.h"
  13. /* accessor functions */
  14. /* X509_POLICY_TREE stuff */
  15. int X509_policy_tree_level_count(const X509_POLICY_TREE *tree)
  16. {
  17. if (!tree)
  18. return 0;
  19. return tree->nlevel;
  20. }
  21. X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree,
  22. int i)
  23. {
  24. if (!tree || (i < 0) || (i >= tree->nlevel))
  25. return NULL;
  26. return tree->levels + i;
  27. }
  28. STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies(const
  29. X509_POLICY_TREE
  30. *tree)
  31. {
  32. if (!tree)
  33. return NULL;
  34. return tree->auth_policies;
  35. }
  36. STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies(const
  37. X509_POLICY_TREE
  38. *tree)
  39. {
  40. if (!tree)
  41. return NULL;
  42. if (tree->flags & POLICY_FLAG_ANY_POLICY)
  43. return tree->auth_policies;
  44. else
  45. return tree->user_policies;
  46. }
  47. /* X509_POLICY_LEVEL stuff */
  48. int X509_policy_level_node_count(X509_POLICY_LEVEL *level)
  49. {
  50. int n;
  51. if (!level)
  52. return 0;
  53. if (level->anyPolicy)
  54. n = 1;
  55. else
  56. n = 0;
  57. if (level->nodes)
  58. n += sk_X509_POLICY_NODE_num(level->nodes);
  59. return n;
  60. }
  61. X509_POLICY_NODE *X509_policy_level_get0_node(const X509_POLICY_LEVEL *level, int i)
  62. {
  63. if (!level)
  64. return NULL;
  65. if (level->anyPolicy) {
  66. if (i == 0)
  67. return level->anyPolicy;
  68. i--;
  69. }
  70. return sk_X509_POLICY_NODE_value(level->nodes, i);
  71. }
  72. /* X509_POLICY_NODE stuff */
  73. const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node)
  74. {
  75. if (!node)
  76. return NULL;
  77. return node->data->valid_policy;
  78. }
  79. STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers(const
  80. X509_POLICY_NODE
  81. *node)
  82. {
  83. if (!node)
  84. return NULL;
  85. return node->data->qualifier_set;
  86. }
  87. const X509_POLICY_NODE *X509_policy_node_get0_parent(const X509_POLICY_NODE
  88. *node)
  89. {
  90. if (!node)
  91. return NULL;
  92. return node->parent;
  93. }