diffusion
Version:
Diffusion JavaScript client
71 lines (70 loc) • 3.24 kB
JavaScript
;
/**
* @module Services.Security
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthenticatorResponseSerialiser = exports.AuthenticatorResponseSerialiserClass = void 0;
var Codec = require("./../../io/codec");
var BEES = require("./../../serialisers/byte-encoded-enum-serialiser");
var serialiser_1 = require("./../../serialisers/serialiser");
var authenticator_response_1 = require("./authenticator-response");
/**
* Serialiser for {@link AuthenticatorResponse}
*/
var AuthenticatorResponseSerialiserClass = /** @class */ (function (_super) {
__extends(AuthenticatorResponseSerialiserClass, _super);
function AuthenticatorResponseSerialiserClass() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Read a {@link AuthenticatorResponse} from the stream
*
* @param bis the input stream
* @return the {@link AuthenticatorResponse} that was read
*/
AuthenticatorResponseSerialiserClass.prototype.read = function (bis) {
var type = BEES.read(bis, authenticator_response_1.TypeCode);
switch (type) {
case authenticator_response_1.TypeCode.ABSTAIN:
return authenticator_response_1.ABSTAIN;
case authenticator_response_1.TypeCode.ALLOW:
var properties = Codec.readDictionary(bis, Codec.readString);
return new authenticator_response_1.AuthenticatorResponse(authenticator_response_1.TypeCode.ALLOW, properties);
default:
return authenticator_response_1.DENY;
}
};
/**
* Write a {@link AuthenticatorResponse} to the stream
*
* @param bos the output stream
* @param value the {@link AuthenticatorResponse} to be written
*/
AuthenticatorResponseSerialiserClass.prototype.write = function (bos, value) {
BEES.write(bos, value.type);
if (value.type === authenticator_response_1.TypeCode.ALLOW) {
Codec.writeDictionary(bos, value.properties || {}, Codec.writeString);
}
};
return AuthenticatorResponseSerialiserClass;
}(serialiser_1.AbstractSerialiser));
exports.AuthenticatorResponseSerialiserClass = AuthenticatorResponseSerialiserClass;
/**
* The {@link AuthenticatorResponseSerialiser} singleton
*/ // eslint-disable-next-line @typescript-eslint/naming-convention
exports.AuthenticatorResponseSerialiser = new AuthenticatorResponseSerialiserClass();