@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
157 lines • 6.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_Attribute = exports._decode_Attribute = exports._extension_additions_list_spec_for_Attribute = exports._root_component_type_list_2_spec_for_Attribute = exports._root_component_type_list_1_spec_for_Attribute = exports.Attribute = exports._encode_AttributeValue = exports._decode_AttributeValue = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const AttributeValue_ta_1 = require("../CryptographicMessageSyntax/AttributeValue.ta");
var AttributeValue_ta_2 = require("../CryptographicMessageSyntax/AttributeValue.ta");
Object.defineProperty(exports, "_decode_AttributeValue", { enumerable: true, get: function () { return AttributeValue_ta_2._decode_AttributeValue; } });
Object.defineProperty(exports, "_encode_AttributeValue", { enumerable: true, get: function () { return AttributeValue_ta_2._encode_AttributeValue; } });
/* START_OF_SYMBOL_DEFINITION Attribute */
/**
* @summary Attribute
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* Attribute ::= SEQUENCE {
* attrType OBJECT IDENTIFIER,
* attrValues SET OF AttributeValue
* }
* ```
*
* @class
*/
class Attribute {
constructor(
/**
* @summary `attrType`.
* @public
* @readonly
*/
attrType,
/**
* @summary `attrValues`.
* @public
* @readonly
*/
attrValues) {
this.attrType = attrType;
this.attrValues = attrValues;
}
/**
* @summary Restructures an object into a Attribute
* @description
*
* This takes an `object` and converts it to a `Attribute`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `Attribute`.
* @returns {Attribute}
*/
static _from_object(_o) {
return new Attribute(_o.attrType, _o.attrValues);
}
}
exports.Attribute = Attribute;
/* END_OF_SYMBOL_DEFINITION Attribute */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Attribute */
/**
* @summary The Leading Root Component Types of Attribute
* @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
*/
exports._root_component_type_list_1_spec_for_Attribute = [
new $.ComponentSpec("attrType", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 6), undefined, undefined),
new $.ComponentSpec("attrValues", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 17), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Attribute */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Attribute */
/**
* @summary The Trailing Root Component Types of Attribute
* @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
*/
exports._root_component_type_list_2_spec_for_Attribute = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Attribute */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Attribute */
/**
* @summary The Extension Addition Component Types of Attribute
* @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
*/
exports._extension_additions_list_spec_for_Attribute = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Attribute */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_Attribute */
let _cached_decoder_for_Attribute = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_Attribute */
/* START_OF_SYMBOL_DEFINITION _decode_Attribute */
/**
* @summary Decodes an ASN.1 element into a(n) Attribute
* @function
* @param {_Element} el The element being decoded.
* @returns {Attribute} The decoded data structure.
*/
function _decode_Attribute(el) {
if (!_cached_decoder_for_Attribute) {
_cached_decoder_for_Attribute = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new asn1_ts_1.ASN1ConstructionError("Attribute contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "attrType";
sequence[1].name = "attrValues";
let attrType;
let attrValues;
attrType = $._decodeObjectIdentifier(sequence[0]);
attrValues = $._decodeSetOf(() => AttributeValue_ta_1._decode_AttributeValue)(sequence[1]);
return new Attribute(attrType, attrValues);
};
}
return _cached_decoder_for_Attribute(el);
}
exports._decode_Attribute = _decode_Attribute;
/* END_OF_SYMBOL_DEFINITION _decode_Attribute */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_Attribute */
let _cached_encoder_for_Attribute = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_Attribute */
/* START_OF_SYMBOL_DEFINITION _encode_Attribute */
/**
* @summary Encodes a(n) Attribute into an ASN.1 Element.
* @function
* @param {value} el The element being decoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The Attribute, encoded as an ASN.1 Element.
*/
function _encode_Attribute(value, elGetter) {
if (!_cached_encoder_for_Attribute) {
_cached_encoder_for_Attribute = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeObjectIdentifier(value.attrType, $.BER),
/* REQUIRED */ $._encodeSetOf(() => AttributeValue_ta_1._encode_AttributeValue, $.BER)(value.attrValues, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_Attribute(value, elGetter);
}
exports._encode_Attribute = _encode_Attribute;
/* END_OF_SYMBOL_DEFINITION _encode_Attribute */
/* eslint-enable */
//# sourceMappingURL=Attribute.ta.js.map