2
0

pkey_meth_test.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright 2016-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. /* Internal tests for EVP_PKEY method ordering */
  10. /* We need to use some deprecated APIs */
  11. #define OPENSSL_SUPPRESS_DEPRECATED
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <openssl/evp.h>
  15. #include "testutil.h"
  16. /* Test of EVP_PKEY_ASN1_METHOD ordering */
  17. static int test_asn1_meths(void)
  18. {
  19. int i;
  20. int prev = -1;
  21. int good = 1;
  22. int pkey_id;
  23. const EVP_PKEY_ASN1_METHOD *ameth;
  24. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  25. ameth = EVP_PKEY_asn1_get0(i);
  26. EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
  27. if (pkey_id < prev)
  28. good = 0;
  29. prev = pkey_id;
  30. }
  31. if (!good) {
  32. TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
  33. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  34. const char *info;
  35. ameth = EVP_PKEY_asn1_get0(i);
  36. EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
  37. if (info == NULL)
  38. info = "<NO NAME>";
  39. TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
  40. }
  41. }
  42. return good;
  43. }
  44. #ifndef OPENSSL_NO_DEPRECATED_3_0
  45. /* Test of EVP_PKEY_METHOD ordering */
  46. static int test_pkey_meths(void)
  47. {
  48. size_t i;
  49. int prev = -1;
  50. int good = 1;
  51. int pkey_id;
  52. const EVP_PKEY_METHOD *pmeth;
  53. for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
  54. pmeth = EVP_PKEY_meth_get0(i);
  55. EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
  56. if (pkey_id < prev)
  57. good = 0;
  58. prev = pkey_id;
  59. }
  60. if (!good) {
  61. TEST_error("EVP_PKEY_METHOD table out of order");
  62. for (i = 0; i < EVP_PKEY_meth_get_count(); i++) {
  63. pmeth = EVP_PKEY_meth_get0(i);
  64. EVP_PKEY_meth_get0_info(&pkey_id, NULL, pmeth);
  65. TEST_note("%d : %s", pkey_id, OBJ_nid2ln(pkey_id));
  66. }
  67. }
  68. return good;
  69. }
  70. #endif
  71. int setup_tests(void)
  72. {
  73. ADD_TEST(test_asn1_meths);
  74. #ifndef OPENSSL_NO_DEPRECATED_3_0
  75. ADD_TEST(test_pkey_meths);
  76. #endif
  77. return 1;
  78. }