(string)
| 24 | ///--- Helpers |
| 25 | |
| 26 | function parseBasic(string) { |
| 27 | var decoded; |
| 28 | var index; |
| 29 | var pieces; |
| 30 | |
| 31 | decoded = new Buffer(string, 'base64').toString('utf8'); |
| 32 | |
| 33 | if (!decoded) { |
| 34 | throw new InvalidHeaderError('Authorization header invalid'); |
| 35 | } |
| 36 | |
| 37 | index = decoded.indexOf(':'); |
| 38 | |
| 39 | if (index === -1) { |
| 40 | pieces = [decoded]; |
| 41 | } else { |
| 42 | pieces = [decoded.slice(0, index), decoded.slice(index + 1)]; |
| 43 | } |
| 44 | |
| 45 | if (!pieces || typeof pieces[0] !== 'string') { |
| 46 | throw new InvalidHeaderError('Authorization header invalid'); |
| 47 | } |
| 48 | |
| 49 | // Allows for usernameless authentication |
| 50 | if (!pieces[0]) { |
| 51 | pieces[0] = null; |
| 52 | } |
| 53 | |
| 54 | // Allows for passwordless authentication |
| 55 | if (!pieces[1]) { |
| 56 | pieces[1] = null; |
| 57 | } |
| 58 | |
| 59 | return { |
| 60 | username: pieces[0], |
| 61 | password: pieces[1] |
| 62 | }; |
| 63 | } |
| 64 | |
| 65 | function parseSignature(request, options) { |
| 66 | var opts = options || {}; |
no outgoing calls
no test coverage detected