Skip to content

Commit b67038f

Browse files
Merge pull request #19 from joaquimserafim/2.1.4
fix some audit issues regarding some dev dependencies
2 parents 412c2c8 + 277ae0a commit b67038f

11 files changed

+5735
-348
lines changed

.coveralls.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: aIOvFO7phTMcwHDyACgpQuHHlxu91Rxy7

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
coverage
77
reports
88
*.html
9+
.nyc_output

.jscsrc

-8
This file was deleted.

.jshintrc

-15
This file was deleted.

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
language: node_js
22
node_js:
3-
- 4
4-
- 5
5-
- 6
3+
- 8
4+
- 10
5+
- 11
66
branches:
77
only:
88
- master

bench.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ new Benchmark.Suite()
4343
.on('complete', () => {
4444
console.log('benchmark finish')
4545
})
46-
.run({'async': true})
46+
.run({ 'async': true })
4747

4848
//
4949
//
@@ -52,4 +52,3 @@ new Benchmark.Suite()
5252
function uuid () {
5353
return (~~(Math.random() * 1e9)).toString(36)
5454
}
55-

index.js

+44-44
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
'use strict'
22

3-
const crypto = require('crypto')
4-
const b64url = require('base64-url')
5-
const inherits = require('util').inherits
6-
const parse = require('json-parse-safe')
7-
const extend = require('xtend')
8-
const isObject = require('is.object')
3+
const crypto = require('crypto')
4+
const b64url = require('base64-url')
5+
const inherits = require('util').inherits
6+
const parse = require('json-parse-safe')
7+
const extend = require('xtend')
8+
const isObject = require('is.object')
99

1010
//
1111
// supported algorithms
1212
//
1313

1414
const algorithms = {
15-
HS256: {hash: 'sha256', type: 'hmac'},
16-
HS384: {hash: 'sha384', type: 'hmac'},
17-
HS512: {hash: 'sha512', type: 'hmac'},
18-
RS256: {hash: 'RSA-SHA256', type: 'sign'}
15+
HS256: { hash: 'sha256', type: 'hmac' },
16+
HS384: { hash: 'sha384', type: 'hmac' },
17+
HS512: { hash: 'sha512', type: 'hmac' },
18+
RS256: { hash: 'RSA-SHA256', type: 'sign' }
1919
}
2020

2121
//
@@ -24,30 +24,30 @@ const algorithms = {
2424

2525
const jwt = module.exports
2626

27-
jwt.JWTError = JWTError
27+
jwt.JWTError = JWTError
2828
jwt.getAlgorithms = getAlgorithms
29-
jwt.encode = encode
30-
jwt.decode = decode
29+
jwt.encode = encode
30+
jwt.decode = decode
3131

3232
function getAlgorithms () {
3333
return Object.keys(algorithms)
3434
}
3535

3636
function encode (key, data, algorithm, cb) {
37-
if (paramIsValid(algorithm, 'function')) {
37+
if (isFunction(algorithm, 'function')) {
3838
cb = algorithm
3939
algorithm = 'HS256'
4040
}
4141

42-
var defaultHeader = {typ: 'JWT', alg: algorithm}
42+
var defaultHeader = { typ: 'JWT', alg: algorithm }
4343

44-
var payload = isObject(data) && data.payload ?
45-
data.payload :
46-
data
44+
var payload = isObject(data) && data.payload
45+
? data.payload
46+
: data
4747

48-
var header = isObject(data) && data.header ?
49-
extend(data.header, defaultHeader) :
50-
defaultHeader
48+
var header = isObject(data) && data.header
49+
? extend(data.header, defaultHeader)
50+
: defaultHeader
5151

5252
const validationError = encodeValidations(key, payload, algorithm)
5353

@@ -101,15 +101,15 @@ function decode (key, token, cb) {
101101
parts[2]
102102
)
103103

104-
return prcResult(!res && 'Invalid key!' || null, payload, header, cb)
104+
return prcResult((!res && 'Invalid key!') || null, payload, header, cb)
105105
}
106106

107107
function encodeValidations (key, payload, algorithm) {
108-
return paramsAreFalsy(key, payload) ?
109-
'The key and payload are mandatory!' :
110-
!Object.keys(payload).length ?
111-
'The payload is an empty object!' :
112-
!algorithms[algorithm] && 'The algorithm is not supported!'
108+
return paramsAreFalsy(key, payload)
109+
? 'The key and payload are mandatory!'
110+
: !Object.keys(payload).length
111+
? 'The payload is an empty object!'
112+
: !algorithms[algorithm] && 'The algorithm is not supported!'
113113
}
114114

115115
//
@@ -130,41 +130,41 @@ inherits(JWTError, Error)
130130
//
131131

132132
function sign (alg, key, input) {
133-
return 'hmac' === alg.type ?
134-
b64url.escape(crypto.createHmac(alg.hash, key)
133+
return alg.type === 'hmac'
134+
? b64url.escape(crypto.createHmac(alg.hash, key)
135135
.update(input)
136-
.digest('base64')) :
137-
b64url.escape(crypto.createSign(alg.hash)
136+
.digest('base64'))
137+
: b64url.escape(crypto.createSign(alg.hash)
138138
.update(input)
139139
.sign(key, 'base64'))
140140
}
141141

142142
function verify (alg, key, input, signVar) {
143-
return 'hmac' === alg.type ?
144-
signVar === sign(alg, key, input) :
145-
crypto.createVerify(alg.hash)
143+
return alg.type === 'hmac'
144+
? signVar === sign(alg, key, input)
145+
: crypto.createVerify(alg.hash)
146146
.update(input)
147147
.verify(key, b64url.unescape(signVar), 'base64')
148148
}
149149

150150
function prcResult (err, payload, header, cb) {
151-
if (paramIsValid(header, 'function')) {
151+
if (isFunction(header, 'function')) {
152152
cb = header
153153
header = undefined
154154
}
155155

156156
err = err && new JWTError(err)
157157

158-
return cb ?
159-
cb(err, payload, header) :
160-
(header ?
161-
{error: err, value: payload, header: header} :
162-
{error: err, value: payload}
163-
)
158+
return cb
159+
? cb(err, payload, header)
160+
: (header
161+
? { error: err, value: payload, header: header }
162+
: { error: err, value: payload }
163+
)
164164
}
165165

166-
function paramIsValid (param, type) {
167-
return !param || typeof param === type
166+
function isFunction (param) {
167+
return !param || typeof param === 'function'
168168
}
169169

170170
function paramsAreFalsy (param1, param2) {
@@ -174,5 +174,5 @@ function paramsAreFalsy (param1, param2) {
174174
function JSONParse (str) {
175175
const res = parse(str)
176176

177-
return res.error && '' || res.value
177+
return res.error ? '' : res.value
178178
}

0 commit comments

Comments
 (0)