-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
52 lines (46 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* global Buffer */
var zlib = require('zlib');
module.exports = {
encodeSamlRedirect: encodeSamlRedirect,
encodeSamlPost: encodeSamlPost,
decodeSamlRedirect: decodeSamlRedirect,
decodeSamlPost: decodeSamlPost
};
function encodeSamlRedirect(input, cb) {
if (input == null || input == "") {
return cb(new Error('Cannot encode null string'));
}
zlib.deflateRaw(input, function (err, deflated) {
if (!err) {
var b64 = deflated.toString('base64');
return cb(null, encodeURIComponent(b64));
} else {
return cb(err);
}
});
}
function decodeSamlRedirect(encoded, cb) {
if (encoded == null || encoded == "") {
return cb(new Error('Cannot decode null string'));
}
var deflated = new Buffer(decodeURIComponent(encoded), 'base64');
zlib.inflateRaw(deflated, function (err, inflated) {
if (!err) {
return cb(null, inflated.toString('ascii'));
} else {
return cb(err);
}
});
}
function encodeSamlPost(input, cb) {
if (input == null || input == "") {
return cb(new Error('Cannot encode null string'));
}
return cb(null, new Buffer(input).toString('base64'));
}
function decodeSamlPost(encoded, cb) {
if (encoded == null || encoded == "") {
return cb(new Error('Cannot decode null string'));
}
return cb(null, new Buffer(encoded, 'base64').toString('ascii'));
}