pkey_meth_test.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. /**********************************************************************
  15. *
  16. * Test of EVP_PKEY_ASN1 method ordering
  17. *
  18. ***/
  19. static int test_asn1_meths()
  20. {
  21. int i;
  22. int prev = -1;
  23. int good = 1;
  24. int pkey_id;
  25. const EVP_PKEY_ASN1_METHOD *ameth;
  26. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  27. ameth = EVP_PKEY_asn1_get0(i);
  28. EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, ameth);
  29. if (pkey_id < prev)
  30. good = 0;
  31. prev = pkey_id;
  32. }
  33. if (!good) {
  34. TEST_error("EVP_PKEY_ASN1_METHOD table out of order");
  35. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  36. const char *info;
  37. ameth = EVP_PKEY_asn1_get0(i);
  38. EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
  39. if (info == NULL)
  40. info = "<NO NAME>";
  41. fprintf(stderr, "%d : %s : %s\n", pkey_id, OBJ_nid2ln(pkey_id),
  42. info);
  43. }
  44. } else {
  45. fprintf(stderr, "Order OK\n");
  46. }
  47. return good;
  48. }
  49. void register_tests()
  50. {
  51. ADD_TEST(test_asn1_meths);
  52. }