<commit_before>'use strict';

const stream = require('stream');
const dgram = require('dgram');
const fs = require('fs');

const mbed = require('./build/Release/node_mbed_dtls_client');

const MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY = -0x7880;

class DtlsSocket extends stream.Duplex {
	constructor(options) {
		super({ allowHalfOpen: false });
		options = options || {};

		this.remoteAddress = options.host;
		this.remotePort = options.port;
		this.dgramSocket = options.socket || dgram.createSocket('udp4');

		this._onMessage = this._onMessage.bind(this);
		this.dgramSocket.on('message', this._onMessage);
		this.dgramSocket.once('error', err => {
			this.emit('error', err);
			this._end();
		});
		this.dgramSocket.once('close', () => {
			this._socketClosed();
		});

		const publicKey = Buffer.isBuffer(options.cert) ? options.cert : fs.readFileSync(options.cert);
		const privateKey = Buffer.isBuffer(options.key) ? options.key : fs.readFileSync(options.key);
		const peerPublicKey = Buffer.isBuffer(options.peerPublicKey) ? options.peerPublicKey : fs.readFileSync(options.peerPublicKey);

		this.mbedSocket = new mbed.DtlsSocket(publicKey, privateKey, peerPublicKey,
			this._sendEncrypted.bind(this),
			this._handshakeComplete.bind(this),
			this._error.bind(this),
			options.debug);

		process.nextTick(() => {
			this.mbedSocket.connect();
		});
	}<commit_msg>Completely remove public key requirement<commit_after>'use strict';

const stream = require('stream');
const dgram = require('dgram');
const fs = require('fs');

const mbed = require('./build/Release/node_mbed_dtls_client');

const MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY = -0x7880;

class DtlsSocket extends stream.Duplex {
	constructor(options) {
		super({ allowHalfOpen: false });
		options = options || {};

		this.remoteAddress = options.host;
		this.remotePort = options.port;
		this.dgramSocket = options.socket || dgram.createSocket('udp4');

		this._onMessage = this._onMessage.bind(this);
		this.dgramSocket.on('message', this._onMessage);
		this.dgramSocket.once('error', err => {
			this.emit('error', err);
			this._end();
		});
		this.dgramSocket.once('close', () => {
			this._socketClosed();
		});

		const privateKey = Buffer.isBuffer(options.key) ? options.key : fs.readFileSync(options.key);
		const peerPublicKey = Buffer.isBuffer(options.peerPublicKey) ? options.peerPublicKey : fs.readFileSync(options.peerPublicKey);

		this.mbedSocket = new mbed.DtlsSocket(privateKey, peerPublicKey,
			this._sendEncrypted.bind(this),
			this._handshakeComplete.bind(this),
			this._error.bind(this),
			options.debug);

		process.nextTick(() => {
			this.mbedSocket.connect();
		});
	}
{'fraction_non_alphanumeric': 0.1527464258841234, 'fraction_numerical': 0.004514672686230248, 'mean_word_length': 4.948545861297539, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1236997', 'n_tokens_mistral': 951, 'n_tokens_neox': 866, 'n_words': 140}