pcy_lib.c 2.8 KB

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