UNPKG

diffusion

Version:

Diffusion JavaScript client

44 lines (43 loc) 1.4 kB
"use strict"; /** * @module V4Stack */ Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeAsString = exports.encodeAsString = void 0; var buffer_input_stream_1 = require("./../io/buffer-input-stream"); var buffer_output_stream_1 = require("./../io/buffer-output-stream"); var credentials_serialiser_1 = require("./../services/authentication/credentials-serialiser"); var uint8array_1 = require("../util/uint8array"); /** * Tunnel a V5 credentials object as an encoded string within v4 password. * * Currently only supports an empty or string password. * * This implementation encapsulates code from both V4CredentialsTunnel and * CredentialsSerialiser in the Java client. * * @param password the password to tunnel * @return an encoded password */ function encodeAsString(password) { var bos = new buffer_output_stream_1.BufferOutputStream(); credentials_serialiser_1.write(bos, password); return bos.getBase64(); } exports.encodeAsString = encodeAsString; /** * Unpack V5 credentials from a string. * * @param s the string * @return the v5 credentials */ function decodeAsString(s) { if (s) { var bis = new buffer_input_stream_1.BufferInputStream(uint8array_1.uint8FromBase64(s)); return credentials_serialiser_1.read(bis); } else { return null; } } exports.decodeAsString = decodeAsString;