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

42 lines
1.4 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';
interface AlgorithmInfo {
algorithm: string;
oid: string;
}
/**
* Возвращает информацию об алгоритме сертификата
*
* @returns информацию об алгоритме и его OID'е
*/
export const getAlgorithm = _afterPluginsLoaded(function (): AlgorithmInfo {
const cadesCertificate = (this as Certificate)._cadesCertificate;
return eval(
_generateCadesFn(function getAlgorithm(): AlgorithmInfo {
const algorithmInfo: AlgorithmInfo = {
algorithm: null,
oid: null,
};
let cadesPublicKey;
try {
cadesPublicKey = __cadesAsyncToken__ + cadesCertificate.PublicKey();
cadesPublicKey = __cadesAsyncToken__ + cadesPublicKey.Algorithm;
algorithmInfo.algorithm = __cadesAsyncToken__ + cadesPublicKey.FriendlyName;
algorithmInfo.oid = __cadesAsyncToken__ + cadesPublicKey.Value;
} catch (error) {
console.error(error);
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при получении алгоритма');
}
return algorithmInfo;
}),
);
});