@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
143 lines (142 loc) • 4.76 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary SecurityEnvironmentInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* SecurityEnvironmentInfo ::= SEQUENCE {
* se INTEGER (0..pkcs15-ub-seInfo),
* owner OBJECT IDENTIFIER,
* ... -- For future extensions
* }
* ```
*
*/
export class SecurityEnvironmentInfo {
se;
owner;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `se`.
* @public
* @readonly
*/
se,
/**
* @summary `owner`.
* @public
* @readonly
*/
owner,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.se = se;
this.owner = owner;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a SecurityEnvironmentInfo
* @description
*
* This takes an `object` and converts it to a `SecurityEnvironmentInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `SecurityEnvironmentInfo`.
* @returns {SecurityEnvironmentInfo}
*/
static _from_object(_o) {
return new SecurityEnvironmentInfo(_o.se, _o.owner, _o._unrecognizedExtensionsList);
}
}
/**
* @summary The Leading Root Component Types of SecurityEnvironmentInfo
* @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_SecurityEnvironmentInfo = [
new $.ComponentSpec("se", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("owner", false, $.hasTag(_TagClass.universal, 6)),
];
/**
* @summary The Trailing Root Component Types of SecurityEnvironmentInfo
* @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_SecurityEnvironmentInfo = [];
/**
* @summary The Extension Addition Component Types of SecurityEnvironmentInfo
* @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_SecurityEnvironmentInfo = [];
let _cached_decoder_for_SecurityEnvironmentInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) SecurityEnvironmentInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {SecurityEnvironmentInfo} The decoded data structure.
*/
export function _decode_SecurityEnvironmentInfo(el) {
if (!_cached_decoder_for_SecurityEnvironmentInfo) {
_cached_decoder_for_SecurityEnvironmentInfo = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("SecurityEnvironmentInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "se";
sequence[1].name = "owner";
let se;
let owner;
se = $._decodeInteger(sequence[0]);
owner = $._decodeObjectIdentifier(sequence[1]);
return new SecurityEnvironmentInfo(se, owner, sequence.slice(2));
};
}
return _cached_decoder_for_SecurityEnvironmentInfo(el);
}
let _cached_encoder_for_SecurityEnvironmentInfo = null;
/**
* @summary Encodes a(n) SecurityEnvironmentInfo 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 SecurityEnvironmentInfo, encoded as an ASN.1 Element.
*/
export function _encode_SecurityEnvironmentInfo(value, elGetter) {
if (!_cached_encoder_for_SecurityEnvironmentInfo) {
_cached_encoder_for_SecurityEnvironmentInfo = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeInteger(value.se, $.BER),
/* REQUIRED */ $._encodeObjectIdentifier(value.owner, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_SecurityEnvironmentInfo(value, elGetter);
}
/* eslint-enable */