crypto-pro-js/src/api/certificate/getCadesProp.ts
2020-03-28 21:11:00 +03:00

31 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { _afterPluginsLoaded } from '../../helpers/_afterPluginsLoaded';
import { _extractMeaningfulErrorMessage } from '../../helpers/_extractMeaningfulErrorMessage';
import { __cadesAsyncToken__, _generateCadesFn } from '../../helpers/_generateCadesFn';
import { Certificate } from './certificate';
/**
* Возвращает указанное внутренее свойство у сертификата в формате Cades
*
* @param propName = наименование свойства
* @returns значение запрошенного свойства
*/
export const getCadesProp = _afterPluginsLoaded(function (propName: string): any {
const cadesCertificate = (this as Certificate)._cadesCertificate;
return eval(
_generateCadesFn(function getCadesProp() {
let propertyValue;
try {
propertyValue = __cadesAsyncToken__ + cadesCertificate[propName];
} catch (error) {
console.error(error);
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при обращении к свойству сертификата');
}
return propertyValue;
}),
);
});