@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
166 lines (165 loc) • 5.45 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_DDO, _encode_DDO } from "../PKCS-15/DDO.ta.mjs";
/**
* @summary DIRRecord
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* DIRRecord ::= [APPLICATION 1] SEQUENCE {
* aid [APPLICATION 15] OCTET STRING,
* label [APPLICATION 16] UTF8String OPTIONAL,
* path [APPLICATION 17] OCTET STRING,
* ddo [APPLICATION 19] DDO OPTIONAL
* }
* ```
*
*/
export class DIRRecord {
aid;
label;
path;
ddo;
constructor(
/**
* @summary `aid`.
* @public
* @readonly
*/
aid,
/**
* @summary `label`.
* @public
* @readonly
*/
label,
/**
* @summary `path`.
* @public
* @readonly
*/
path,
/**
* @summary `ddo`.
* @public
* @readonly
*/
ddo) {
this.aid = aid;
this.label = label;
this.path = path;
this.ddo = ddo;
}
/**
* @summary Restructures an object into a DIRRecord
* @description
*
* This takes an `object` and converts it to a `DIRRecord`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `DIRRecord`.
* @returns {DIRRecord}
*/
static _from_object(_o) {
return new DIRRecord(_o.aid, _o.label, _o.path, _o.ddo);
}
}
/**
* @summary The Leading Root Component Types of DIRRecord
* @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_DIRRecord = [
new $.ComponentSpec("aid", false, $.hasTag(_TagClass.application, 15)),
new $.ComponentSpec("label", true, $.hasTag(_TagClass.application, 16)),
new $.ComponentSpec("path", false, $.hasTag(_TagClass.application, 17)),
new $.ComponentSpec("ddo", true, $.hasTag(_TagClass.application, 19)),
];
/**
* @summary The Trailing Root Component Types of DIRRecord
* @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_DIRRecord = [];
/**
* @summary The Extension Addition Component Types of DIRRecord
* @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_DIRRecord = [];
let _cached_decoder_for_DIRRecord = null;
/**
* @summary Decodes an ASN.1 element into a(n) DIRRecord
* @function
* @param {_Element} el The element being decoded.
* @returns {DIRRecord} The decoded data structure.
*/
export function _decode_DIRRecord(el) {
if (!_cached_decoder_for_DIRRecord) {
_cached_decoder_for_DIRRecord = $._decode_implicit(() => function (el) {
let aid;
let label;
let path;
let ddo;
const callbacks = {
aid: (_el) => {
aid = $._decode_implicit(() => $._decodeOctetString)(_el);
},
label: (_el) => {
label = $._decode_implicit(() => $._decodeUTF8String)(_el);
},
path: (_el) => {
path = $._decode_implicit(() => $._decodeOctetString)(_el);
},
ddo: (_el) => {
ddo = $._decode_implicit(() => _decode_DDO)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_DIRRecord, _extension_additions_list_spec_for_DIRRecord, _root_component_type_list_2_spec_for_DIRRecord, undefined);
return new DIRRecord(aid, label, path, ddo);
});
}
return _cached_decoder_for_DIRRecord(el);
}
let _cached_encoder_for_DIRRecord = null;
/**
* @summary Encodes a(n) DIRRecord 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 DIRRecord, encoded as an ASN.1 Element.
*/
export function _encode_DIRRecord(value, elGetter) {
if (!_cached_encoder_for_DIRRecord) {
_cached_encoder_for_DIRRecord = $._encode_implicit(_TagClass.application, 1, () => function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encode_implicit(_TagClass.application, 15, () => $._encodeOctetString, $.BER)(value.aid, $.BER),
/* IF_ABSENT */ value.label === undefined
? undefined
: $._encode_implicit(_TagClass.application, 16, () => $._encodeUTF8String, $.BER)(value.label, $.BER),
/* REQUIRED */ $._encode_implicit(_TagClass.application, 17, () => $._encodeOctetString, $.BER)(value.path, $.BER),
/* IF_ABSENT */ value.ddo === undefined
? undefined
: $._encode_implicit(_TagClass.application, 19, () => _encode_DDO, $.BER)(value.ddo, $.BER),
])
.filter((c) => !!c), $.BER);
}, $.BER);
}
return _cached_encoder_for_DIRRecord(value, elGetter);
}
/* eslint-enable */