pkey_meth_test.c 2.2 KB

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