<commit_before>#!/usr/bin/env node

const pull = require('pull-stream')
const toPull = require('stream-to-pull-stream')
const { createServer } = require('../..')

const appKey = Buffer.from(process.argv[2], 'hex')
const bob = { // the keypair of the server
  secretKey: Buffer.from(process.argv[3], 'hex'),
  publicKey: Buffer.from(process.argv[4], 'hex')
}
const authorize = (pubKey, cb) => cb(null, true) // all clients are allowed to connect
const timeout = 30 // I hope this is milliseconds?

const shake = createServer(bob, authorize, appKey, timeout)((err, stream) => {
  if (err) {
    log(`! ${err}`)
    // shs1-test : If the server detects that the client is not well-behaved, it must immediately exit with a non-zero exit code, without writing any further data to stdout.
    process.exit(1)
  } else {
    const { encryptKey, decryptKey, encryptNonce, decryptNonce } = stream.crypto
    const result = Buffer.concat([ encryptKey, encryptNonce, decryptKey, decryptNonce ])
    log(`< writing ${result.length} bytes (final)`)
    process.stdout.write(result)

    // process.kill(process.pid)
  }
})

process.on('SIGTERM', () => {
  log('X received SIGTERM')
})

pull(
  toPull.source(process.stdin),
  pull.through(data => log(`> reading ${data.length} bytes`)),
  shake, // duplex handshake stream
  pull.through(data => log(`< writing ${data.length} bytes`)),
  toPull.sink(process.stdout)
)

function log (string) {
  // uncomment this to get some debugging data
  process.stderr.write(`PID ${process.pid}: ${string}\n`)
}
<commit_msg>shs1-test server tests working !<commit_after>#!/usr/bin/env node

const pull = require('pull-stream')
const toPull = require('stream-to-pull-stream')
const { createServer } = require('../..')

const appKey = Buffer.from(process.argv[2], 'hex')
const bob = { // the keypair of the server
  secretKey: Buffer.from(process.argv[3], 'hex'),
  publicKey: Buffer.from(process.argv[4], 'hex')
}
const authorize = (pubKey, cb) => cb(null, true) // all clients are allowed to connect
const timeout = 500 // I hope this is milliseconds!

const shake = createServer(bob, authorize, appKey, timeout)((err, stream) => {
  if (err) {
    log(`! ${err}`)
    process.exit(1)
    // shs1-test : If the server detects that the client is not well-behaved,
    // it must immediately exit with a non-zero exit code, without writing any further data to stdout.
  }

  const { encryptKey, decryptKey, encryptNonce, decryptNonce } = stream.crypto
  const result = Buffer.concat([ encryptKey, encryptNonce, decryptKey, decryptNonce ])

  log(`< writing ${result.length} bytes (final)`)
  process.stdout.write(result)
})

process.on('SIGTERM', () => {
  log('X received SIGTERM')
})

pull(
  toPull.source(process.stdin),
  pull.through(data => log(`> reading ${data.length} bytes`)),
  shake, // duplex handshake stream
  pull.through(data => log(`< writing ${data.length} bytes`)),
  toPull.sink(process.stdout)
)

function log (string) {
  // uncomment this to get some debugging data
  // process.stderr.write(`PID ${process.pid}: ${string}\n`)
}

{'fraction_non_alphanumeric': 0.15794605134871628, 'fraction_numerical': 0.005199870003249919, 'mean_word_length': 4.079207920792079, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3592948', 'n_tokens_mistral': 1025, 'n_tokens_neox': 982, 'n_words': 286}