UNPKG

894 BJavaScriptView Raw
1const fs = require('fs')
2const crypto = require('crypto')
3
4function cipherProcessor (exercise) {
5 exercise.addSetup(function (mode, callback) {
6 const { algorithm, key, iv } = this.cipherArgs
7
8 this.submissionArgs = this.submissionArgs.concat(this.execArgs)
9 this.solutionArgs = this.solutionArgs.concat(this.execArgs)
10
11 this.submissionCipher = crypto.createCipheriv(algorithm, key, iv)
12 this.solutionCipher = crypto.createCipheriv(algorithm, key, iv)
13
14 process.nextTick(callback)
15 })
16
17 exercise.addProcessor(function (mode, callback) {
18 fs.createReadStream(this.inputFilePath).pipe(this.submissionCipher).pipe(this.submissionChild.stdin)
19
20 if (mode === 'verify') {
21 fs.createReadStream(this.inputFilePath).pipe(this.solutionCipher).pipe(this.solutionChild.stdin)
22 }
23
24 process.nextTick(callback)
25 })
26
27 return exercise
28}
29
30module.exports = cipherProcessor