2 * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
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
10 #ifndef OSSL_INTERNAL_COMMON_H
11 # define OSSL_INTERNAL_COMMON_H
16 # include "openssl/configuration.h"
18 # include "internal/e_os.h" /* ossl_inline in many files */
19 # include "internal/nelem.h"
22 # define ossl_assert(x) ((x) != 0)
24 __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
25 const char *file, int line)
28 OPENSSL_die(exprstr, file, line);
33 # define ossl_assert(x) ossl_assert_int((x) != 0, "Assertion failed: "#x, \
38 /* Check if |pre|, which must be a string literal, is a prefix of |str| */
39 #define HAS_PREFIX(str, pre) (strncmp(str, pre "", sizeof(pre) - 1) == 0)
40 /* As before, and if check succeeds, advance |str| past the prefix |pre| */
41 #define CHECK_AND_SKIP_PREFIX(str, pre) \
42 (HAS_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
43 /* Check if the string literal |p| is a case-insensitive prefix of |s| */
44 #define HAS_CASE_PREFIX(s, p) (OPENSSL_strncasecmp(s, p "", sizeof(p) - 1) == 0)
45 /* As before, and if check succeeds, advance |str| past the prefix |pre| */
46 #define CHECK_AND_SKIP_CASE_PREFIX(str, pre) \
47 (HAS_CASE_PREFIX(str, pre) ? ((str) += sizeof(pre) - 1, 1) : 0)
48 /* Check if the string literal |suffix| is a case-insensitive suffix of |str| */
49 #define HAS_CASE_SUFFIX(str, suffix) (strlen(str) < sizeof(suffix) - 1 ? 0 : \
50 OPENSSL_strcasecmp(str + strlen(str) - sizeof(suffix) + 1, suffix "") == 0)
53 * Use this inside a union with the field that needs to be aligned to a
54 * reasonable boundary for the platform. The most pessimistic alignment
55 * of the listed types will be used by the compiler.
57 # define OSSL_UNION_ALIGN \
59 ossl_uintmax_t align_int; \
62 # define OPENSSL_CONF "openssl.cnf"
64 # ifndef OPENSSL_SYS_VMS
65 # define X509_CERT_AREA OPENSSLDIR
66 # define X509_CERT_DIR OPENSSLDIR "/certs"
67 # define X509_CERT_FILE OPENSSLDIR "/cert.pem"
68 # define X509_PRIVATE_DIR OPENSSLDIR "/private"
69 # define CTLOG_FILE OPENSSLDIR "/ct_log_list.cnf"
71 # define X509_CERT_AREA "OSSL$DATAROOT:[000000]"
72 # define X509_CERT_DIR "OSSL$DATAROOT:[CERTS]"
73 # define X509_CERT_FILE "OSSL$DATAROOT:[000000]cert.pem"
74 # define X509_PRIVATE_DIR "OSSL$DATAROOT:[PRIVATE]"
75 # define CTLOG_FILE "OSSL$DATAROOT:[000000]ct_log_list.cnf"
78 #ifndef OPENSSL_NO_WINSTORE
79 # define X509_CERT_URI "org.openssl.winstore://"
81 # define X509_CERT_URI ""
84 # define X509_CERT_URI_EVP "SSL_CERT_URI"
85 # define X509_CERT_PATH_EVP "SSL_CERT_PATH"
86 # define X509_CERT_DIR_EVP "SSL_CERT_DIR"
87 # define X509_CERT_FILE_EVP "SSL_CERT_FILE"
88 # define CTLOG_FILE_EVP "CTLOG_FILE"
90 /* size of string representations */
91 # define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
92 # define HEX_SIZE(type) (sizeof(type)*2)
94 static ossl_inline int ossl_ends_with_dirsep(const char *path)
97 path += strlen(path) - 1;
99 if (*path == ']' || *path == '>' || *path == ':')
101 # elif defined _WIN32
108 static ossl_inline int ossl_is_absolute_path(const char *path)
111 if (strchr(path, ':') != NULL
112 || ((path[0] == '[' || path[0] == '<')
113 && path[1] != '.' && path[1] != '-'
114 && path[1] != ']' && path[1] != '>'))
116 # elif defined _WIN32
118 || (path[0] != '\0' && path[1] == ':'))
121 return path[0] == '/';