v3ext.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <stdio.h>
  10. #include <openssl/x509.h>
  11. #include <openssl/x509v3.h>
  12. #include <openssl/pem.h>
  13. #include <openssl/err.h>
  14. #include "testutil.h"
  15. static const char *infile;
  16. static int test_pathlen(void)
  17. {
  18. X509 *x = NULL;
  19. BIO *b = NULL;
  20. long pathlen;
  21. int ret = 0;
  22. if (!TEST_ptr(b = BIO_new_file(infile, "r"))
  23. || !TEST_ptr(x = PEM_read_bio_X509(b, NULL, NULL, NULL))
  24. || !TEST_int_eq(pathlen = X509_get_pathlen(x), 6))
  25. goto end;
  26. ret = 1;
  27. end:
  28. BIO_free(b);
  29. X509_free(x);
  30. return ret;
  31. }
  32. OPT_TEST_DECLARE_USAGE("cert.pem\n")
  33. int setup_tests(void)
  34. {
  35. if (!test_skip_common_options()) {
  36. TEST_error("Error parsing test options\n");
  37. return 0;
  38. }
  39. if (!TEST_ptr(infile = test_get_argument(0)))
  40. return 0;
  41. ADD_TEST(test_pathlen);
  42. return 1;
  43. }