<commit_before>// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#include <tm.h>

#include <os_port.h>
#include <ssl.h>
#include <assert.h>

#ifdef TLS_VERBOSE
#define TLS_DEBUG(...) printf(__VA_ARGS__)
#else
#define TLS_DEBUG(...) if (0) { printf(__VA_ARGS__); }
#endif

static void display_cipher(tm_ssl_session_t ssl);
static void display_session_id(tm_ssl_session_t ssl);

int tm_ssl_write (tm_ssl_session_t ssl, const uint8_t *buf, size_t *buf_len)
{
    int res = ssl_write(ssl, buf, *buf_len);
    if (res < 0) {
        *buf_len = 0;
        return res;
    } else {
        *buf_len = res;
        return 0;
    }
}

// TODO less than 1024
int tm_ssl_read (tm_ssl_session_t ssl, uint8_t *buf, size_t *buf_len)
{
    uint8_t *read_buf;
    int res = ssl_read(ssl, &read_buf);
    if (res < 0) {
        *buf_len = 0;
        return res;
    } else {
        assert(res <= (int) *buf_len);
        memcpy(buf, read_buf, res);
        *buf_len = res;
        return 0;
    }
}

typedef struct dir_reg { const char *path; const unsigned char *src; unsigned int len; } dir_reg_t;
extern dir_reg_t cacert_bundle[];

int tm_ssl_context_create (tm_ssl_ctx_t* ctx)<commit_msg>flip back to more correct cast as was in feature branch, aka nate being ocd<commit_after>// Copyright 2014 Technical Machine, Inc. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#include <tm.h>

#include <os_port.h>
#include <ssl.h>
#include <assert.h>

#ifdef TLS_VERBOSE
#define TLS_DEBUG(...) printf(__VA_ARGS__)
#else
#define TLS_DEBUG(...) if (0) { printf(__VA_ARGS__); }
#endif

static void display_cipher(tm_ssl_session_t ssl);
static void display_session_id(tm_ssl_session_t ssl);

int tm_ssl_write (tm_ssl_session_t ssl, const uint8_t *buf, size_t *buf_len)
{
    int res = ssl_write(ssl, buf, *buf_len);
    if (res < 0) {
        *buf_len = 0;
        return res;
    } else {
        *buf_len = res;
        return 0;
    }
}

// TODO less than 1024
int tm_ssl_read (tm_ssl_session_t ssl, uint8_t *buf, size_t *buf_len)
{
    uint8_t *read_buf;
    int res = ssl_read(ssl, &read_buf);
    if (res < 0) {
        *buf_len = 0;
        return res;
    } else {
        assert((unsigned int) res <= *buf_len);
        memcpy(buf, read_buf, res);
        *buf_len = res;
        return 0;
    }
}

typedef struct dir_reg { const char *path; const unsigned char *src; unsigned int len; } dir_reg_t;
extern dir_reg_t cacert_bundle[];

int tm_ssl_context_create (tm_ssl_ctx_t* ctx)
{'fraction_non_alphanumeric': 0.11848341232227488, 'fraction_numerical': 0.013902053712480253, 'mean_word_length': 3.2213333333333334, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '290647', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1126, 'n_words': 338}