UNPKG

diffusion

Version:

Diffusion JavaScript client

44 lines (38 loc) 1.15 kB
/*eslint valid-jsdoc: "off"*/ var BufferOutputStream = require('io/buffer-output-stream'); var BufferInputStream = require('io/buffer-input-stream'); var serialiser = require('services/authentication/credentials-serialiser'); /** * Tunnel a V5 credentials object as an encoded string within v4 password. * <p> * Currently only supports an empty or string password. * <p> * This implementation encapsulates code from both V4CredentialsTunnel and * CredentialsSerialiser in the Java client. * * @param {Object} password - The password to tunnel * @returns {String} An encoded password */ function encodeAsString(password) { var bos = new BufferOutputStream(); serialiser.write(bos, password); return bos.getBase64(); } /** * Unpack V5 credentials from a string. * * @param s the string * @returns {Object} the v5 credentials */ function decodeAsString(s) { if (s) { var bis = new BufferInputStream(new Buffer(s, 'base64')); return serialiser.read(bis); } else { return null; } } module.exports = { encodeAsString : encodeAsString, decodeAsString : decodeAsString };