pax_global_header00006660000000000000000000000064121330523630014510gustar00rootroot0000000000000052 comment=9de1b41f7ef6d3c23dcb04279a4b0fa1353c4e2c node-cookie-signature-1.0.1/000077500000000000000000000000001213305236300157025ustar00rootroot00000000000000node-cookie-signature-1.0.1/.gitignore000066400000000000000000000000151213305236300176660ustar00rootroot00000000000000node_modules node-cookie-signature-1.0.1/.npmignore000066400000000000000000000000351213305236300176770ustar00rootroot00000000000000support test examples *.sock node-cookie-signature-1.0.1/History.md000066400000000000000000000003241213305236300176640ustar00rootroot00000000000000 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.1/Makefile000066400000000000000000000001311213305236300173350ustar00rootroot00000000000000 test: @./node_modules/.bin/mocha \ --require should \ --reporter spec .PHONY: testnode-cookie-signature-1.0.1/Readme.md000066400000000000000000000027221213305236300174240ustar00rootroot00000000000000 # 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.1/index.js000066400000000000000000000017651213305236300173600ustar00rootroot00000000000000 /** * 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('.')); return exports.sign(str, secret) == val ? str : false; }; node-cookie-signature-1.0.1/package.json000066400000000000000000000004521213305236300201710ustar00rootroot00000000000000{ "name": "cookie-signature", "version": "1.0.1", "description": "Sign and unsign cookies", "keywords": ["cookie", "sign", "unsign"], "author": "TJ Holowaychuk ", "dependencies": {}, "devDependencies": { "mocha": "*", "should": "*" }, "main": "index" } node-cookie-signature-1.0.1/test/000077500000000000000000000000001213305236300166615ustar00rootroot00000000000000node-cookie-signature-1.0.1/test/index.js000066400000000000000000000012301213305236300203220ustar00rootroot00000000000000 /** * 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('hhello.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; }) })