
# Copyright (C) Dmitry Volyntsev
# Copyright (C) NGINX, Inc.


NJS_OPENSSL_LIB=
NJS_HAVE_OPENSSL=NO

if [ $NJS_OPENSSL = YES ]; then
    njs_found=no

    njs_feature="OpenSSL library"
    njs_feature_name=NJS_HAVE_OPENSSL
    njs_feature_run=yes
    njs_feature_incs=
    njs_feature_libs=""
    njs_feature_test="#include <openssl/evp.h>

                      int main() {
                          EVP_CIPHER_CTX  *ctx;
                          ctx = EVP_CIPHER_CTX_new();
                          EVP_CIPHER_CTX_free(ctx);
                          return 0;
                     }"
    . auto/feature

    if [ $njs_found = no ]; then
        njs_feature="OpenSSL library -lcrypto"
        njs_feature_libs="-lcrypto"

        . auto/feature
    fi


    if [ $njs_found = yes ]; then
        njs_feature="EVP_aes_128_wrap()"
        njs_feature_name=NJS_HAVE_AES_WRAP
        njs_feature_run=
        njs_feature_test="#include <openssl/evp.h>

                          int main() {
                              (void) EVP_aes_128_wrap();
                              return 0;
                         }"
        . auto/feature

        # Ed25519 and X25519 share the same Curve25519 implementation and
        # were introduced together in OpenSSL 1.1.1, LibreSSL 3.7.0,
        # BoringSSL, and AWS-LC.  No known build configuration enables
        # one without the other, so a single probe is sufficient.

        njs_feature="EVP_PKEY_ED25519"
        njs_feature_name=NJS_HAVE_ED25519
        njs_feature_run=
        njs_feature_test="#include <openssl/evp.h>

                          int main() {
                              return EVP_PKEY_new_raw_public_key(
                                  EVP_PKEY_ED25519, NULL, NULL, 0) == NULL;
                         }"
        . auto/feature

        njs_feature="OpenSSL version"
        njs_feature_name=NJS_OPENSSL_VERSION
        njs_feature_run=value
        njs_feature_test="#include <openssl/ssl.h>

                          int main() {
                              printf(\"\\\"%s\\\"\", OPENSSL_VERSION_TEXT);
                              return 0;
                          }"
        . auto/feature

        NJS_HAVE_OPENSSL=YES
        NJS_OPENSSL_LIB="$njs_feature_libs"
        NJS_LIB_AUX_LIBS="$NJS_LIB_AUX_LIBS $njs_feature_libs"
    fi

fi
