1 | ;
|
2 |
|
3 | const crc = require('crc').crc32;
|
4 |
|
5 | module.exports = {
|
6 |
|
7 | /**
|
8 | * Decode the base64 cookie value to an object.
|
9 | *
|
10 | * @param {String} string
|
11 | * @return {Object}
|
12 | * @api private
|
13 | */
|
14 |
|
15 | decode(string) {
|
16 | const body = new Buffer(string, 'base64').toString('utf8');
|
17 | const json = JSON.parse(body);
|
18 | return json;
|
19 | },
|
20 |
|
21 | /**
|
22 | * Encode an object into a base64-encoded JSON string.
|
23 | *
|
24 | * @param {Object} body
|
25 | * @return {String}
|
26 | * @api private
|
27 | */
|
28 |
|
29 | encode(body) {
|
30 | body = JSON.stringify(body);
|
31 | return new Buffer(body).toString('base64');
|
32 | },
|
33 |
|
34 | hash(sess) {
|
35 | return crc(JSON.stringify(sess));
|
36 | },
|
37 | };
|