asn1_internal_test.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 1999-2017 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 the asn1 module */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <openssl/asn1.h>
  13. #include <openssl/evp.h>
  14. #include <openssl/objects.h>
  15. #include "testutil.h"
  16. #include "internal/nelem.h"
  17. /**********************************************************************
  18. *
  19. * Test of a_strnid's tbl_standard
  20. *
  21. ***/
  22. #include "../crypto/asn1/tbl_standard.h"
  23. static int test_tbl_standard(void)
  24. {
  25. const ASN1_STRING_TABLE *tmp;
  26. int last_nid = -1;
  27. size_t i;
  28. for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
  29. if (tmp->nid < last_nid) {
  30. last_nid = 0;
  31. break;
  32. }
  33. last_nid = tmp->nid;
  34. }
  35. if (TEST_int_ne(last_nid, 0)) {
  36. TEST_info("asn1 tbl_standard: Table order OK");
  37. return 1;
  38. }
  39. TEST_info("asn1 tbl_standard: out of order");
  40. for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
  41. TEST_note("asn1 tbl_standard: Index %zu, NID %d, Name=%s",
  42. i, tmp->nid, OBJ_nid2ln(tmp->nid));
  43. return 0;
  44. }
  45. /**********************************************************************
  46. *
  47. * Test of ameth_lib's standard_methods
  48. *
  49. ***/
  50. #include "internal/asn1_int.h"
  51. #include "../crypto/asn1/standard_methods.h"
  52. static int test_standard_methods(void)
  53. {
  54. const EVP_PKEY_ASN1_METHOD **tmp;
  55. int last_pkey_id = -1;
  56. size_t i;
  57. for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
  58. i++, tmp++) {
  59. if ((*tmp)->pkey_id < last_pkey_id) {
  60. last_pkey_id = 0;
  61. break;
  62. }
  63. last_pkey_id = (*tmp)->pkey_id;
  64. }
  65. if (TEST_int_ne(last_pkey_id, 0)) {
  66. TEST_info("asn1 standard methods: Table order OK");
  67. return 1;
  68. }
  69. TEST_note("asn1 standard methods: out of order");
  70. for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
  71. i++, tmp++)
  72. TEST_note("asn1 standard methods: Index %zu, pkey ID %d, Name=%s",
  73. i, (*tmp)->pkey_id, OBJ_nid2sn((*tmp)->pkey_id));
  74. return 0;
  75. }
  76. int setup_tests(void)
  77. {
  78. ADD_TEST(test_tbl_standard);
  79. ADD_TEST(test_standard_methods);
  80. return 1;
  81. }