<commit_before>#!/bin/sh

# Test interop with OpenSSL and GnuTLS (and self-op while at it).
#
# Check each common ciphersuite, with each version, both ways (client/server),
# with and without client authentication.
#
# Peer version requirements:
# - OpenSSL 1.0.1e 11 Feb 2013 (probably since 1.0.1, tested with 1.0.1e)
# - GnuTLS 3.2.15 (probably works since 3.2.12 but tested only with 3.2.15)

set -u

# initialise counters
TESTS=0
FAILED=0
SKIPPED=0
SRVMEM=0

# default commands, can be overriden by the environment
: ${P_SRV:=../programs/ssl/ssl_server2}
: ${P_CLI:=../programs/ssl/ssl_client2}
: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
: ${GNUTLS_CLI:=gnutls-cli}
: ${GNUTLS_SERV:=gnutls-serv}

# do we have a recent enough GnuTLS?
if ( which $GNUTLS_CLI && which $GNUTLS_SERV ) >/dev/null; then
    eval $( $GNUTLS_CLI --version | head -n1 | sed 's/.* \([0-9]*\)\.\([0-9]\)*\.\([0-9]*\)$/MAJOR="\1" MINOR="\2" PATCH="\3"/' )
    if [ $MAJOR -lt 3 -o \
        \( $MAJOR -eq 3 -a $MINOR -lt 2 \) -o \
        \( $MAJOR -eq 3 -a $MINOR -eq 2 -a $PATCH -lt 15 \) ]
    then
        PEER_GNUTLS=""
    else
        PEER_GNUTLS=" GnuTLS"
    fi
else
    PEER_GNUTLS=""
fi

# default values for options
MODES="ssl3 tls1 tls1_1 tls1_2"
VERIFIES="NO YES"
TYPES="ECDSA RSA PSK"
FILTER=""
EXCLUDE='NULL\|DES-CBC-' # avoid plain DES but keep 3DES-EDE-CBC (PolarSSL), DES-CBC3 (OpenSSL)
VERBOSE=""
MEMCHECK=0
PEERS="OpenSSL$PEER_GNUTLS PolarSSL"

print_usage() {
    echo "Usage: $0"
    echo -e "  -h|--help\tPrint this help."
    echo -e "  -f|--filter\tOnly matching ciphersuites are tested (Default: '$FILTER')"
    echo -e "  -e|--exclude\tMatching ciphersuites are excluded (Default: '$EXCLUDE')"
    echo -e "  -m|--modes\tWhich modes to perform (Default: '$MODES')"
    echo -e "  -t|--types\tWhich key exchange type to perform (Default: '$TYPES')"
    echo -e "  -V|--verify\tWhich verification modes to perform (Default: '$VERIFIES')"
    echo -e "  -p|--peers\tWhich peers to use (Default: '$PEERS')"
    echo -e "            \tAlso available: GnuTLS (needs v3.2.15 or higher)"
    echo -e "  -M|--memcheck\tCheck memory leaks and errors."
    echo -e "  -v|--verbose\tSet verbose output."
}

get_options() {
    while [ $# -gt 0 ]; do
        case "$1" in
            -f|--filter)
                shift; FILTER=$1
                ;;
            -e|--exclude)
                shift; EXCLUDE=$1
                ;;
            -m|--modes)
                shift; MODES=$1
                ;;
            -t|--types)
                shift; TYPES=$1
                ;;
            -V|--verify)
                shift; VERIFIES=$1
                ;;
            -p|--peers)
                shift; PEERS=$1
                ;;
            -v|--verbose)
                VERBOSE=1
                ;;
            -M|--memcheck)
                MEMCHECK=1
                ;;
            -h|--help)
                print_usage
                exit 0
                ;;
            *)
                echo "Unknown argument: '$1'"
                print_usage
                exit 1
                ;;
        esac
        shift
    done
}

log() {
  if [ "X" != "X$VERBOSE" ]; then
    echo "$@"<commit_msg>compat.sh: make options a bit more robust<commit_after>#!/bin/sh

# Test interop with OpenSSL and GnuTLS (and self-op while at it).
#
# Check each common ciphersuite, with each version, both ways (client/server),
# with and without client authentication.
#
# Peer version requirements:
# - OpenSSL 1.0.1e 11 Feb 2013 (probably since 1.0.1, tested with 1.0.1e)
# - GnuTLS 3.2.15 (probably works since 3.2.12 but tested only with 3.2.15)

set -u

# initialise counters
TESTS=0
FAILED=0
SKIPPED=0
SRVMEM=0

# default commands, can be overriden by the environment
: ${P_SRV:=../programs/ssl/ssl_server2}
: ${P_CLI:=../programs/ssl/ssl_client2}
: ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system
: ${GNUTLS_CLI:=gnutls-cli}
: ${GNUTLS_SERV:=gnutls-serv}

# do we have a recent enough GnuTLS?
if ( which $GNUTLS_CLI && which $GNUTLS_SERV ) >/dev/null; then
    eval $( $GNUTLS_CLI --version | head -n1 | sed 's/.* \([0-9]*\)\.\([0-9]\)*\.\([0-9]*\)$/MAJOR="\1" MINOR="\2" PATCH="\3"/' )
    if [ $MAJOR -lt 3 -o \
        \( $MAJOR -eq 3 -a $MINOR -lt 2 \) -o \
        \( $MAJOR -eq 3 -a $MINOR -eq 2 -a $PATCH -lt 15 \) ]
    then
        PEER_GNUTLS=""
    else
        PEER_GNUTLS=" GnuTLS"
    fi
else
    PEER_GNUTLS=""
fi

# default values for options
MODES="ssl3 tls1 tls1_1 tls1_2"
VERIFIES="NO YES"
TYPES="ECDSA RSA PSK"
FILTER=""
EXCLUDE='NULL\|DES-CBC-' # avoid plain DES but keep 3DES-EDE-CBC (PolarSSL), DES-CBC3 (OpenSSL)
VERBOSE=""
MEMCHECK=0
PEERS="OpenSSL$PEER_GNUTLS PolarSSL"

print_usage() {
    echo "Usage: $0"
    echo -e "  -h|--help\tPrint this help."
    echo -e "  -f|--filter\tOnly matching ciphersuites are tested (Default: '$FILTER')"
    echo -e "  -e|--exclude\tMatching ciphersuites are excluded (Default: '$EXCLUDE')"
    echo -e "  -m|--modes\tWhich modes to perform (Default: '$MODES')"
    echo -e "  -t|--types\tWhich key exchange type to perform (Default: '$TYPES')"
    echo -e "  -V|--verify\tWhich verification modes to perform (Default: '$VERIFIES')"
    echo -e "  -p|--peers\tWhich peers to use (Default: '$PEERS')"
    echo -e "            \tAlso available: GnuTLS (needs v3.2.15 or higher)"
    echo -e "  -M|--memcheck\tCheck memory leaks and errors."
    echo -e "  -v|--verbose\tSet verbose output."
}

get_options() {
    while [ $# -gt 0 ]; do
        case "$1" in
            -f|--filter)
                shift; FILTER=$1
                ;;
            -e|--exclude)
                shift; EXCLUDE=$1
                ;;
            -m|--modes)
                shift; MODES=$1
                ;;
            -t|--types)
                shift; TYPES=$1
                ;;
            -V|--verify)
                shift; VERIFIES=$1
                ;;
            -p|--peers)
                shift; PEERS=$1
                ;;
            -v|--verbose)
                VERBOSE=1
                ;;
            -M|--memcheck)
                MEMCHECK=1
                ;;
            -h|--help)
                print_usage
                exit 0
                ;;
            *)
                echo "Unknown argument: '$1'"
                print_usage
                exit 1
                ;;
        esac
        shift
    done

    # sanitize some options (modes checked later)
    VERIFIES="$( echo $VERIFIES | tr [a-z] [A-Z] )"
    TYPES="$( echo $TYPES | tr [a-z] [A-Z] )"
}

log() {
  if [ "X" != "X$VERBOSE" ]; then
    echo "$@"
{'fraction_non_alphanumeric': 0.15332428765264586, 'fraction_numerical': 0.02321724709784411, 'mean_word_length': 1.7526970954356846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7438256', 'n_tokens_mistral': 2542, 'n_tokens_neox': 2337, 'n_words': 618}