@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
182 lines (181 loc) • 5.79 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_Path, _encode_Path } from "../PKCS-15/Path.ta.mjs";
/**
* @summary DDO
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* DDO ::= SEQUENCE {
* oid OBJECT IDENTIFIER,
* odfPath Path OPTIONAL,
* tokenInfoPath [0] Path OPTIONAL,
* unusedPath [1] Path OPTIONAL,
* ... -- For future extensions
* }
* ```
*
*/
export class DDO {
oid;
odfPath;
tokenInfoPath;
unusedPath;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `oid`.
* @public
* @readonly
*/
oid,
/**
* @summary `odfPath`.
* @public
* @readonly
*/
odfPath,
/**
* @summary `tokenInfoPath`.
* @public
* @readonly
*/
tokenInfoPath,
/**
* @summary `unusedPath`.
* @public
* @readonly
*/
unusedPath,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.oid = oid;
this.odfPath = odfPath;
this.tokenInfoPath = tokenInfoPath;
this.unusedPath = unusedPath;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a DDO
* @description
*
* This takes an `object` and converts it to a `DDO`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `DDO`.
* @returns {DDO}
*/
static _from_object(_o) {
return new DDO(_o.oid, _o.odfPath, _o.tokenInfoPath, _o.unusedPath, _o._unrecognizedExtensionsList);
}
}
/**
* @summary The Leading Root Component Types of DDO
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the leading root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_1_spec_for_DDO = [
new $.ComponentSpec("oid", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("odfPath", true, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("tokenInfoPath", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("unusedPath", true, $.hasTag(_TagClass.context, 1)),
];
/**
* @summary The Trailing Root Component Types of DDO
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the trailing root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_2_spec_for_DDO = [];
/**
* @summary The Extension Addition Component Types of DDO
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the extension addition component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _extension_additions_list_spec_for_DDO = [];
let _cached_decoder_for_DDO = null;
/**
* @summary Decodes an ASN.1 element into a(n) DDO
* @function
* @param {_Element} el The element being decoded.
* @returns {DDO} The decoded data structure.
*/
export function _decode_DDO(el) {
if (!_cached_decoder_for_DDO) {
_cached_decoder_for_DDO = function (el) {
let oid;
let odfPath;
let tokenInfoPath;
let unusedPath;
let _unrecognizedExtensionsList = [];
const callbacks = {
oid: (_el) => {
oid = $._decodeObjectIdentifier(_el);
},
odfPath: (_el) => {
odfPath = _decode_Path(_el);
},
tokenInfoPath: (_el) => {
tokenInfoPath = $._decode_implicit(() => _decode_Path)(_el);
},
unusedPath: (_el) => {
unusedPath = $._decode_implicit(() => _decode_Path)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_DDO, _extension_additions_list_spec_for_DDO, _root_component_type_list_2_spec_for_DDO, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new DDO(oid, odfPath, tokenInfoPath, unusedPath, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_DDO(el);
}
let _cached_encoder_for_DDO = null;
/**
* @summary Encodes a(n) DDO into an ASN.1 Element.
* @function
* @param value The element being encoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The DDO, encoded as an ASN.1 Element.
*/
export function _encode_DDO(value, elGetter) {
if (!_cached_encoder_for_DDO) {
_cached_encoder_for_DDO = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeObjectIdentifier(value.oid, $.BER),
/* IF_ABSENT */ value.odfPath === undefined
? undefined
: _encode_Path(value.odfPath, $.BER),
/* IF_ABSENT */ value.tokenInfoPath === undefined
? undefined
: $._encode_implicit(_TagClass.context, 0, () => _encode_Path, $.BER)(value.tokenInfoPath, $.BER),
/* IF_ABSENT */ value.unusedPath === undefined
? undefined
: $._encode_implicit(_TagClass.context, 1, () => _encode_Path, $.BER)(value.unusedPath, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_DDO(value, elGetter);
}
/* eslint-enable */