@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
151 lines (150 loc) • 4.58 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_MacData, _encode_MacData, } from "../PKCS-12/MacData.ta.mjs";
import { _decode_PFX_version, _encode_PFX_version, } from "../PKCS-12/PFX-version.ta.mjs";
import { _decode_ContentInfo, _encode_ContentInfo, } from "../PKCS7/ContentInfo.ta.mjs";
/**
* @summary PFX
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* PFX ::= SEQUENCE {
* version INTEGER {v3(3)}(v3,...),
* authSafe ContentInfo,
* macData MacData OPTIONAL
* }
* ```
*
*/
export class PFX {
version;
authSafe;
macData;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `authSafe`.
* @public
* @readonly
*/
authSafe,
/**
* @summary `macData`.
* @public
* @readonly
*/
macData) {
this.version = version;
this.authSafe = authSafe;
this.macData = macData;
}
/**
* @summary Restructures an object into a PFX
* @description
*
* This takes an `object` and converts it to a `PFX`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `PFX`.
* @returns {PFX}
*/
static _from_object(_o) {
return new PFX(_o.version, _o.authSafe, _o.macData);
}
}
/**
* @summary The Leading Root Component Types of PFX
* @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_PFX = [
new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("authSafe", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("macData", true, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of PFX
* @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_PFX = [];
/**
* @summary The Extension Addition Component Types of PFX
* @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_PFX = [];
let _cached_decoder_for_PFX = null;
/**
* @summary Decodes an ASN.1 element into a(n) PFX
* @function
* @param {_Element} el The element being decoded.
* @returns {PFX} The decoded data structure.
*/
export function _decode_PFX(el) {
if (!_cached_decoder_for_PFX) {
_cached_decoder_for_PFX = function (el) {
let version;
let authSafe;
let macData;
const callbacks = {
version: (_el) => {
version = _decode_PFX_version(_el);
},
authSafe: (_el) => {
authSafe = _decode_ContentInfo(_el);
},
macData: (_el) => {
macData = _decode_MacData(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_PFX, _extension_additions_list_spec_for_PFX, _root_component_type_list_2_spec_for_PFX, undefined);
return new PFX(version, authSafe, macData);
};
}
return _cached_decoder_for_PFX(el);
}
let _cached_encoder_for_PFX = null;
/**
* @summary Encodes a(n) PFX 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 PFX, encoded as an ASN.1 Element.
*/
export function _encode_PFX(value, elGetter) {
if (!_cached_encoder_for_PFX) {
_cached_encoder_for_PFX = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_PFX_version(value.version, $.BER),
/* REQUIRED */ _encode_ContentInfo(value.authSafe, $.BER),
/* IF_ABSENT */ value.macData === undefined
? undefined
: _encode_MacData(value.macData, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_PFX(value, elGetter);
}
/* eslint-enable */