diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 19:02:05 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-05 19:02:05 +0100 |
commit | 8425cb894d4867d26fd5f7fae7862b0669f3c717 (patch) | |
tree | 5e2f00a8219e198f2dd074ca13f3ae681174228f /helpers/peertubeCrypto.js | |
parent | dac0a5319ab1c52a0958647b1593f85339b77e29 (diff) | |
download | PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.gz PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.tar.zst PeerTube-8425cb894d4867d26fd5f7fae7862b0669f3c717.zip |
Error handling mini refractoring
Diffstat (limited to 'helpers/peertubeCrypto.js')
-rw-r--r-- | helpers/peertubeCrypto.js | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/helpers/peertubeCrypto.js b/helpers/peertubeCrypto.js index 3e757659b..36271dba9 100644 --- a/helpers/peertubeCrypto.js +++ b/helpers/peertubeCrypto.js | |||
@@ -101,7 +101,7 @@ | |||
101 | logger.info('Generating a RSA key...') | 101 | logger.info('Generating a RSA key...') |
102 | openssl.exec('genrsa', { 'out': certDir + 'peertube.key.pem', '2048': false }, function (err) { | 102 | openssl.exec('genrsa', { 'out': certDir + 'peertube.key.pem', '2048': false }, function (err) { |
103 | if (err) { | 103 | if (err) { |
104 | logger.error('Cannot create private key on this pod.', { error: err }) | 104 | logger.error('Cannot create private key on this pod.') |
105 | return callback(err) | 105 | return callback(err) |
106 | } | 106 | } |
107 | logger.info('RSA key generated.') | 107 | logger.info('RSA key generated.') |
@@ -109,7 +109,7 @@ | |||
109 | logger.info('Manage public key...') | 109 | logger.info('Manage public key...') |
110 | openssl.exec('rsa', { 'in': certDir + 'peertube.key.pem', 'pubout': true, 'out': certDir + 'peertube.pub' }, function (err) { | 110 | openssl.exec('rsa', { 'in': certDir + 'peertube.key.pem', 'pubout': true, 'out': certDir + 'peertube.pub' }, function (err) { |
111 | if (err) { | 111 | if (err) { |
112 | logger.error('Cannot create public key on this pod .', { error: err }) | 112 | logger.error('Cannot create public key on this pod.') |
113 | return callback(err) | 113 | return callback(err) |
114 | } | 114 | } |
115 | 115 | ||
@@ -122,9 +122,7 @@ | |||
122 | 122 | ||
123 | function generatePassword (callback) { | 123 | function generatePassword (callback) { |
124 | crypto.randomBytes(32, function (err, buf) { | 124 | crypto.randomBytes(32, function (err, buf) { |
125 | if (err) { | 125 | if (err) return callback(err) |
126 | return callback(err) | ||
127 | } | ||
128 | 126 | ||
129 | callback(null, buf.toString('utf8')) | 127 | callback(null, buf.toString('utf8')) |
130 | }) | 128 | }) |
@@ -139,9 +137,7 @@ | |||
139 | 137 | ||
140 | function symetricEncrypt (text, callback) { | 138 | function symetricEncrypt (text, callback) { |
141 | generatePassword(function (err, password) { | 139 | generatePassword(function (err, password) { |
142 | if (err) { | 140 | if (err) return callback(err) |
143 | return callback(err) | ||
144 | } | ||
145 | 141 | ||
146 | var cipher = crypto.createCipher(algorithm, password) | 142 | var cipher = crypto.createCipher(algorithm, password) |
147 | var crypted = cipher.update(text, 'utf8', 'hex') | 143 | var crypted = cipher.update(text, 'utf8', 'hex') |