1 var signature = require('cookie-signature');
4 * Parse signed cookies, returning an object
5 * containing the decoded key/value pairs,
6 * while removing the signed key from `obj`.
13 exports.signedCookies = function(obj, secret){
14 var cookies = Object.keys(obj);
17 var ret = Object.create(null);
20 for (var i = 0; i < cookies.length; i++) {
23 dec = exports.signedCookie(val, secret);
35 * Parse a signed cookie string, return the decoded value
37 * @param {String} str signed cookie string
38 * @param {String} secret
39 * @return {String} decoded value
43 exports.signedCookie = function(str, secret){
44 return str.substr(0, 2) === 's:'
45 ? signature.unsign(str.slice(2), secret)
57 exports.JSONCookies = function(obj){
58 var cookies = Object.keys(obj);
62 for (var i = 0; i < cookies.length; i++) {
64 val = exports.JSONCookie(obj[key]);
75 * Parse JSON cookie string
78 * @return {Object} Parsed object or null if not json cookie
82 exports.JSONCookie = function(str) {
83 if (!str || str.substr(0, 2) !== 'j:') return;
86 return JSON.parse(str.slice(2));