pax_global_header00006660000000000000000000000064122720422570014515gustar00rootroot0000000000000052 comment=1d1b25bc8170c3b0d18d6ae378488a73ff6df846 node-cookie-signature-1.0.3/000077500000000000000000000000001227204225700157115ustar00rootroot00000000000000node-cookie-signature-1.0.3/.gitignore000066400000000000000000000000151227204225700176750ustar00rootroot00000000000000node_modules node-cookie-signature-1.0.3/.npmignore000066400000000000000000000000351227204225700177060ustar00rootroot00000000000000support test examples *.sock node-cookie-signature-1.0.3/History.md000066400000000000000000000005621227204225700176770ustar00rootroot000000000000001.0.3 / 2014-01-28 ================== * fix for timing attacks 1.0.2 / 2014-01-28 ================== * fix missing repository warning * fix typo in test 1.0.1 / 2013-04-15 ================== * Revert "Changed underlying HMAC algo. to sha512." * Revert "Fix for timing attacks on MAC verification." 0.0.1 / 2010-01-03 ================== * Initial release node-cookie-signature-1.0.3/Makefile000066400000000000000000000001311227204225700173440ustar00rootroot00000000000000 test: @./node_modules/.bin/mocha \ --require should \ --reporter spec .PHONY: testnode-cookie-signature-1.0.3/Readme.md000066400000000000000000000027221227204225700174330ustar00rootroot00000000000000 # cookie-signature Sign and unsign cookies. ## Example ```js var cookie = require('cookie-signature'); var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false; ``` ## License (The MIT License) Copyright (c) 2012 LearnBoost <tj@learnboost.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.node-cookie-signature-1.0.3/index.js000066400000000000000000000020631227204225700173570ustar00rootroot00000000000000/** * Module dependencies. */ var crypto = require('crypto'); /** * Sign the given `val` with `secret`. * * @param {String} val * @param {String} secret * @return {String} * @api private */ exports.sign = function(val, secret){ if ('string' != typeof val) throw new TypeError('cookie required'); if ('string' != typeof secret) throw new TypeError('secret required'); return val + '.' + crypto .createHmac('sha256', secret) .update(val) .digest('base64') .replace(/\=+$/, ''); }; /** * Unsign and decode the given `val` with `secret`, * returning `false` if the signature is invalid. * * @param {String} val * @param {String} secret * @return {String|Boolean} * @api private */ exports.unsign = function(val, secret){ if ('string' != typeof val) throw new TypeError('cookie required'); if ('string' != typeof secret) throw new TypeError('secret required'); var str = val.slice(0, val.lastIndexOf('.')) , mac = exports.sign(str, secret); return exports.sign(mac, secret) == exports.sign(val, secret) ? str : false; }; node-cookie-signature-1.0.3/package.json000066400000000000000000000006171227204225700202030ustar00rootroot00000000000000{ "name": "cookie-signature", "version": "1.0.3", "description": "Sign and unsign cookies", "keywords": ["cookie", "sign", "unsign"], "author": "TJ Holowaychuk ", "repository": { "type": "git", "url": "https://github.com/visionmedia/node-cookie-signature.git"}, "dependencies": {}, "devDependencies": { "mocha": "*", "should": "*" }, "main": "index" } node-cookie-signature-1.0.3/test/000077500000000000000000000000001227204225700166705ustar00rootroot00000000000000node-cookie-signature-1.0.3/test/index.js000066400000000000000000000012261227204225700203360ustar00rootroot00000000000000/** * Module dependencies. */ var cookie = require('..'); describe('.sign(val, secret)', function(){ it('should sign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); val.should.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); var val = cookie.sign('hello', 'luna'); val.should.not.equal('hello.DGDUkGlIkCzPz+C0B064FNgHdEjox7ch8tOBGslZ5QI'); }) }) describe('.unsign(val, secret)', function(){ it('should unsign the cookie', function(){ var val = cookie.sign('hello', 'tobiiscool'); cookie.unsign(val, 'tobiiscool').should.equal('hello'); cookie.unsign(val, 'luna').should.be.false; }) })