summaryrefslogtreecommitdiffstats
path: root/dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js
diff options
context:
space:
mode:
authorTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:37:53 -0500
committerTimoney, Daniel (dt5972) <dtimoney@att.com>2017-02-15 10:40:37 -0500
commit324ee36fe31763e507b422ab0a88e4230045e205 (patch)
treed0b04520f6657601c918ce63fd27575977624187 /dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js
parentf0c97e8db427481e28c0a16b789bc73801b35e47 (diff)
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680 Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com> Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js')
-rw-r--r--dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js b/dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js
new file mode 100644
index 00000000..db1e6191
--- /dev/null
+++ b/dgbuilder/dgeflows/node_modules/cookie-parser/lib/parse.js
@@ -0,0 +1,90 @@
+var signature = require('cookie-signature');
+
+/**
+ * Parse signed cookies, returning an object
+ * containing the decoded key/value pairs,
+ * while removing the signed key from `obj`.
+ *
+ * @param {Object} obj
+ * @return {Object}
+ * @api private
+ */
+
+exports.signedCookies = function(obj, secret){
+ var cookies = Object.keys(obj);
+ var dec;
+ var key;
+ var ret = Object.create(null);
+ var val;
+
+ for (var i = 0; i < cookies.length; i++) {
+ key = cookies[i];
+ val = obj[key];
+ dec = exports.signedCookie(val, secret);
+
+ if (val !== dec) {
+ ret[key] = dec;
+ delete obj[key];
+ }
+ }
+
+ return ret;
+};
+
+/**
+ * Parse a signed cookie string, return the decoded value
+ *
+ * @param {String} str signed cookie string
+ * @param {String} secret
+ * @return {String} decoded value
+ * @api private
+ */
+
+exports.signedCookie = function(str, secret){
+ return str.substr(0, 2) === 's:'
+ ? signature.unsign(str.slice(2), secret)
+ : str;
+};
+
+/**
+ * Parse JSON cookies.
+ *
+ * @param {Object} obj
+ * @return {Object}
+ * @api private
+ */
+
+exports.JSONCookies = function(obj){
+ var cookies = Object.keys(obj);
+ var key;
+ var val;
+
+ for (var i = 0; i < cookies.length; i++) {
+ key = cookies[i];
+ val = exports.JSONCookie(obj[key]);
+
+ if (val) {
+ obj[key] = val;
+ }
+ }
+
+ return obj;
+};
+
+/**
+ * Parse JSON cookie string
+ *
+ * @param {String} str
+ * @return {Object} Parsed object or null if not json cookie
+ * @api private
+ */
+
+exports.JSONCookie = function(str) {
+ if (!str || str.substr(0, 2) !== 'j:') return;
+
+ try {
+ return JSON.parse(str.slice(2));
+ } catch (err) {
+ // no op
+ }
+};