Skip to content

Commit

Permalink
update dependencies and promisify
Browse files Browse the repository at this point in the history
  • Loading branch information
HR committed Jun 6, 2016
1 parent 4567d1a commit e054009
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"scripts": {
"electronVersion": "node_modules/.bin/electron -v | sed s/\\v//g",
"postinstall": "./node_modules/.bin/electron-rebuild",
"test": "TEST_RUN=true mocha --compilers js:babel-core/register test/test.js",
"xltest": "unset TEST_RUN && rm -rf ~/Library/Application\\ Support/CrypterTest/ && mocha --compilers js:babel-core/register ./test/ui/*.js",
"xtest": "npm run xtestbuild && npm run xltest",
Expand Down Expand Up @@ -63,13 +64,14 @@
"coveralls": "^2.11.9",
"devtron": "^1.1.0",
"electron-packager": "*",
"electron-rebuild": "^1.1.4",
"eslint": "*",
"eslint-plugin-html": "*",
"gulp": "*",
"gulp-babel": "^6.1.2",
"gulp-babel-istanbul": "^1.0.0",
"gulp-env": "^0.4.0",
"gulp-inject-modules": "^0.2.0",
"gulp-inject-modules": "^1.0.0",
"gulp-json-editor": "^2.2.1",
"gulp-less": "^3.0.5",
"gulp-mocha": "^2.2.0",
Expand Down
18 changes: 13 additions & 5 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,22 @@ exports.encrypt = function (origpath, destpath, mpkey) {
})
})
}
let readFile = function (path) {
return new Promise(function(resolve, reject) {
fs.readFile(path, 'utf-8', function (err, data) {
if (err) reject(err)
resolve(data)
})
})
}

exports.decrypt = function (origpath, destpath, mpkey, iv, authTag) {
// Decrypts any arbitrary data passed with the pass
return new Promise(function (resolve, reject) {
if (!iv || !authTag) {
// extract from last line of file
fs.readFile(origpath, 'utf-8', function (err, data) {
if (err) reject(err)

readFile(origpath).then((data) => {
let lines = data.trim().split('\n')
let lastLine = lines.slice(-1)[0]
let fields = lastLine.split('#')
Expand Down Expand Up @@ -148,8 +155,7 @@ exports.decrypt = function (origpath, destpath, mpkey, iv, authTag) {
// // read as stream
// origin.push(dec)
// origin.push(null)
//
// origin.pipe(dest)

let origin = new Readable()
// read as stream
origin.push(mainData)
Expand Down Expand Up @@ -178,8 +184,10 @@ exports.decrypt = function (origpath, destpath, mpkey, iv, authTag) {
}
})
} else {
reject(new Error('IV and authTag not supplied'))
reject(new Error('Not a Crypter file (can not get salt, iv and authTag)'))
}
}).catch((err) => {
reject(err)
})
} else {
// TODO: Implement normal flow
Expand Down

0 comments on commit e054009

Please sign in to comment.