UNPKG

diffusion

Version:

Diffusion JavaScript client

70 lines (69 loc) 1.76 kB
"use strict"; /** * @module Services.Authentication */ Object.defineProperty(exports, "__esModule", { value: true }); exports.write = exports.read = void 0; var Codec = require("./../../io/codec"); var BEES = require("./../../serialisers/byte-encoded-enum-serialiser"); /** * The type of the credentials data */ var Type; (function (Type) { /** * No data (null) */ Type[Type["NONE"] = 0] = "NONE"; /** * Plain string data */ Type[Type["PLAIN"] = 1] = "PLAIN"; /** * Custom data stored in a Uint8Array */ Type[Type["CUSTOM"] = 2] = "CUSTOM"; })(Type || (Type = {})); /** * Read credentials from an input stream * * @param input the input stream * @return the credentials that were read */ function read(input) { var type = BEES.read(input, Type); switch (type) { case Type.PLAIN: return Codec.readString(input) || null; case Type.CUSTOM: return Codec.readBytes(input); case Type.NONE: default: Codec.readBytes(input); return null; } } exports.read = read; /** * Write credentials to an output stream * * @param output the output stream * @param credentials the credentials to write */ function write(output, credentials) { if (credentials !== null && credentials !== undefined) { if (typeof credentials === 'string') { BEES.write(output, Type.PLAIN); Codec.writeString(output, credentials); } else { BEES.write(output, Type.CUSTOM); Codec.writeBytes(output, credentials); } } else { BEES.write(output, Type.NONE); Codec.writeInt32(output, 0); } } exports.write = write;