Поправил тесты

linter fixes
This commit is contained in:
Artem Vasilev 2021-06-04 11:30:37 +03:00
parent da4763661c
commit 06e68c92ec
51 changed files with 93 additions and 8914 deletions

3
dist/api/index.d.ts vendored
View File

@ -1,5 +1,6 @@
export * from './getCertificate'; export * from './getCertificate';
export * from './getUserCertificates'; export * from './getUserCertificates';
export * from './getAllUserCertificates';
export * from './getSystemInfo'; export * from './getSystemInfo';
export * from './isValidSystemSetup'; export * from './isValidSystemSetup';
export * from './createSignature'; export * from './createSignature';
@ -10,3 +11,5 @@ export * from './createAttachedSignature';
export * from './addAttachedSignature'; export * from './addAttachedSignature';
export * from './createHash'; export * from './createHash';
export * from './certificate'; export * from './certificate';
export * from './getCspVersion';
export * from './getPluginVersion';

View File

@ -1,7 +0,0 @@
// Type definitions for crypto-pro 2.2.2
// Project: crypto-pro
// Definitions by: Vitalii Goma https://github.com/vgoma
export as namespace cryptoPro;
export * from './api';

5379
dist/crypto-pro.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +0,0 @@
/**
* Добавляет присоединенную подпись к подписанному сообщению по отпечатку сертификата
*
* @param thumbprint - отпечаток сертификата
* @param signedMessage - подписанное сообщение
* @returns подпись в формате PKCS#7
*/
export declare const addAttachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer) => Promise<string>;

View File

@ -1,9 +0,0 @@
/**
* Добавляет отсоединенную подпись хеша к подписанному сообщению по отпечатку сертификата
*
* @param thumbprint - отпечаток сертификата
* @param signedMessage - подписанное сообщение
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
* @returns подпись в формате PKCS#7
*/
export declare const addDetachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer, messageHash: string) => Promise<string>;

View File

@ -1,22 +0,0 @@
import { TagTranslation } from '../../helpers/_parseCertInfo';
import { ExtendedKeysTranslations } from './getDecodedExtendedKeyUsage';
export declare type CadesCertificate = any;
export declare class Certificate {
_cadesCertificate: CadesCertificate;
name: string;
issuerName: string;
subjectName: string;
thumbprint: string;
validFrom: string;
validTo: string;
constructor(_cadesCertificate: CadesCertificate, name: string, issuerName: string, subjectName: string, thumbprint: string, validFrom: string, validTo: string);
getOwnerInfo(): Promise<TagTranslation[]>;
getIssuerInfo(): Promise<TagTranslation[]>;
getExtendedKeyUsage(): Promise<string[]>;
getDecodedExtendedKeyUsage(): Promise<ExtendedKeysTranslations>;
getAlgorithm(): Promise<string>;
getCadesProp(propName: any): Promise<any>;
isValid(): Promise<boolean>;
exportBase64(): Promise<string>;
hasExtendedKeyUsage(oids: any): Promise<boolean>;
}

View File

@ -1,6 +0,0 @@
/**
* Экспортирует сертификат в формате base64
*
* @returns сертификат в формате base64
*/
export declare const exportBase64: () => Promise<string>;

View File

@ -1,11 +0,0 @@
interface AlgorithmInfo {
algorithm: string;
oid: string;
}
/**
* Возвращает информацию об алгоритме сертификата
*
* @returns информацию об алгоритме и его OID'е
*/
export declare const getAlgorithm: () => Promise<AlgorithmInfo>;
export {};

View File

@ -1,7 +0,0 @@
/**
* Возвращает указанное внутренее свойство у сертификата в формате Cades
*
* @param propName = наименование свойства
* @returns значение запрошенного свойства
*/
export declare const getCadesProp: (propName: string) => Promise<any>;

View File

@ -1,9 +0,0 @@
export interface ExtendedKeysTranslations {
[key: string]: string | null;
}
/**
* Возвращает расшифрованные ОИД'ы сертификата
*
* @returns словарь расшифрованных ОИД'ов
*/
export declare const getDecodedExtendedKeyUsage: () => Promise<ExtendedKeysTranslations>;

View File

@ -1,6 +0,0 @@
/**
* Возвращает ОИД'ы сертификата
*
* @returns список ОИД'ов
*/
export declare const getExtendedKeyUsage: () => Promise<string[]>;

View File

@ -1,10 +0,0 @@
import { TagsTranslations } from '../../constants/tags-translations';
import { TagTranslation } from '../../helpers/_parseCertInfo';
/**
* Возвращает расшифрованную информацию о сертификате из указанного свойства по тэгам
*
* @param tags = словарь
* @param entitiesPath = путь к разбираемой сущности
* @returns расшифрованная информация по отдельным тэгам
*/
export declare const getInfo: (tags: TagsTranslations[], entitiesPath: string) => Promise<TagTranslation[]>;

View File

@ -1,7 +0,0 @@
/**
* Проверяет наличие ОИД'а (ОИД'ов) у сертификата
*
* @param oids - ОИД'ы для проверки
* @returns флаг наличия ОИД'ов у сертификата
*/
export declare const hasExtendedKeyUsage: (oids: string | string[]) => Promise<boolean>;

View File

@ -1 +0,0 @@
export * from './certificate';

View File

@ -1,6 +0,0 @@
/**
* Проверяет действительность сертификата
*
* @returns флаг валидности
*/
export declare const isValid: () => Promise<boolean>;

View File

@ -1,8 +0,0 @@
/**
* Создает присоединенную подпись сообщения по отпечатку сертификата
*
* @param thumbprint - отпечаток сертификата
* @param message - подписываемое сообщение
* @returns подпись в формате PKCS#7
*/
export declare const createAttachedSignature: (thumbprint: string, unencryptedMessage: string | ArrayBuffer) => Promise<string>;

View File

@ -1,8 +0,0 @@
/**
* Создает отсоединенную подпись хеша по отпечатку сертификата
*
* @param thumbprint - отпечаток сертификата
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
* @returns подпись в формате PKCS#7
*/
export declare const createDetachedSignature: (thumbprint: string, messageHash: string) => Promise<string>;

View File

@ -1,9 +0,0 @@
/**
* Создает хеш сообщения по ГОСТ Р 34.11-2012 256 бит
* https://ru.wikipedia.org/wiki/%D0%A1%D1%82%D1%80%D0%B8%D0%B1%D0%BE%D0%B3_(%D1%85%D0%B5%D1%88-%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F)
*
* @param unencryptedMessage - сообщение для хеширования
*
* @returns хеш
*/
export declare const createHash: (unencryptedMessage: string | ArrayBuffer) => Promise<string>;

View File

@ -1,9 +0,0 @@
/**
* Создает подпись base64 строки по отпечатку сертификата
*
* @param thumbprint - отпечаток сертификата
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11
* @param detachedSignature = true - тип подписи открепленная (true) / присоединенная (false)
* @returns подпись
*/
export declare const createSignature: (thumbprint: string, messageHash: string, detachedSignature?: boolean) => Promise<string>;

View File

@ -1,8 +0,0 @@
/**
* Создает XML подпись для документа в формате XML
*
* @param thumbprint - отпечаток сертификата
* @param unencryptedMessage - подписываемое сообщение в формате XML
* @returns подпись
*/
export declare const createXMLSignature: (thumbprint: string, unencryptedMessage: string) => Promise<string>;

View File

@ -1,8 +0,0 @@
import { Certificate } from './certificate';
/**
* Возвращает сертификат по отпечатку
*
* @param thumbprint - отпечаток сертификата
* @returns сертификат
*/
export declare const getCertificate: (thumbprint: string) => Promise<Certificate>;

View File

@ -1,10 +0,0 @@
export interface SystemInfo {
cadesVersion: string;
cspVersion: string;
}
/**
* Предоставляет информацию о системе
*
* @returns информацию о CSP и плагине
*/
export declare const getSystemInfo: () => Promise<SystemInfo>;

View File

@ -1,8 +0,0 @@
import { Certificate } from './certificate';
/**
* Возвращает список сертификатов, доступных пользователю в системе
*
* @param resetCache = false - позволяет сбросить кэш ранее полученных сертификатов
* @returns список сертификатов
*/
export declare const getUserCertificates: (resetCache?: boolean) => Promise<Certificate[]>;

12
lib/api/index.d.ts vendored
View File

@ -1,12 +0,0 @@
export * from './getCertificate';
export * from './getUserCertificates';
export * from './getSystemInfo';
export * from './isValidSystemSetup';
export * from './createSignature';
export * from './createXMLSignature';
export * from './createDetachedSignature';
export * from './addDetachedSignature';
export * from './createAttachedSignature';
export * from './addAttachedSignature';
export * from './createHash';
export * from './certificate';

View File

@ -1,6 +0,0 @@
/**
* Проверяет корректность настроек ЭП на машине
*
* @returns флаг корректности настроек
*/
export declare const isValidSystemSetup: () => Promise<boolean>;

View File

@ -1,149 +0,0 @@
export declare const CADESCOM_ATTRIBUTE_OTHER = -1;
export declare const CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_DESCRIPTION = 2;
export declare const CADESCOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_NAME = 1;
export declare const CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME = 0;
export declare const CADESCOM_AllowNoOutstandingRequest = 1;
export declare const CADESCOM_AllowNone = 0;
export declare const CADESCOM_AllowUntrustedCertificate = 2;
export declare const CADESCOM_AllowUntrustedRoot = 4;
export declare const CADESCOM_BASE64_TO_BINARY = 1;
export declare const CADESCOM_CADES_BES = 1;
export declare const CADESCOM_CADES_DEFAULT = 0;
export declare const CADESCOM_CADES_T = 5;
export declare const CADESCOM_CADES_X_LONG_TYPE_1 = 93;
export declare const CADESCOM_CONTAINER_STORE = 100;
export declare const CADESCOM_CURRENT_USER_STORE = 2;
export declare const CADESCOM_DISPLAY_DATA_ATTRIBUTE = 2;
export declare const CADESCOM_DISPLAY_DATA_CONTENT = 1;
export declare const CADESCOM_DISPLAY_DATA_NONE = 0;
export declare const CADESCOM_ENCODE_ANY = -1;
export declare const CADESCOM_ENCODE_BASE64 = 0;
export declare const CADESCOM_ENCODE_BINARY = 1;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_3DES = 3;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_AES = 4;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_DES = 2;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_GOST_28147_89 = 25;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_RC2 = 0;
export declare const CADESCOM_ENCRYPTION_ALGORITHM_RC4 = 1;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411 = 100;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256 = 101;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256_HMAC = 111;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_512 = 102;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_512_HMAC = 112;
export declare const CADESCOM_HASH_ALGORITHM_CP_GOST_3411_HMAC = 110;
export declare const CADESCOM_HASH_ALGORITHM_MD2 = 1;
export declare const CADESCOM_HASH_ALGORITHM_MD4 = 2;
export declare const CADESCOM_HASH_ALGORITHM_MD5 = 3;
export declare const CADESCOM_HASH_ALGORITHM_SHA1 = 0;
export declare const CADESCOM_HASH_ALGORITHM_SHA_256 = 4;
export declare const CADESCOM_HASH_ALGORITHM_SHA_384 = 5;
export declare const CADESCOM_HASH_ALGORITHM_SHA_512 = 6;
export declare const CADESCOM_LOCAL_MACHINE_STORE = 1;
export declare const CADESCOM_PKCS7_TYPE = 65535;
export declare const CADESCOM_STRING_TO_UCS2LE = 0;
export declare const CADESCOM_SkipInstallToStore = 268435456;
export declare const CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED = 0;
export declare const CADESCOM_XML_SIGNATURE_TYPE_ENVELOPING = 1;
export declare const CADESCOM_XML_SIGNATURE_TYPE_TEMPLATE = 2;
export declare const CAPICOM_ACTIVE_DIRECTORY_USER_STORE = 3;
export declare const CAPICOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_DESCRIPTION = 2;
export declare const CAPICOM_AUTHENTICATED_ATTRIBUTE_DOCUMENT_NAME = 1;
export declare const CAPICOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME = 0;
export declare const CAPICOM_CERTIFICATE_FIND_APPLICATION_POLICY = 7;
export declare const CAPICOM_CERTIFICATE_FIND_CERTIFICATE_POLICY = 8;
export declare const CAPICOM_CERTIFICATE_FIND_EXTENDED_PROPERTY = 6;
export declare const CAPICOM_CERTIFICATE_FIND_EXTENSION = 5;
export declare const CAPICOM_CERTIFICATE_FIND_ISSUER_NAME = 2;
export declare const CAPICOM_CERTIFICATE_FIND_KEY_USAGE = 12;
export declare const CAPICOM_CERTIFICATE_FIND_ROOT_NAME = 3;
export declare const CAPICOM_CERTIFICATE_FIND_SHA1_HASH = 0;
export declare const CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1;
export declare const CAPICOM_CERTIFICATE_FIND_TEMPLATE_NAME = 4;
export declare const CAPICOM_CERTIFICATE_FIND_TIME_EXPIRED = 11;
export declare const CAPICOM_CERTIFICATE_FIND_TIME_NOT_YET_VALID = 10;
export declare const CAPICOM_CERTIFICATE_FIND_TIME_VALID = 9;
export declare const CAPICOM_CERTIFICATE_INCLUDE_CHAIN_EXCEPT_ROOT = 0;
export declare const CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY = 2;
export declare const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1;
export declare const CAPICOM_CERT_INFO_ISSUER_SIMPLE_NAME = 1;
export declare const CAPICOM_CERT_INFO_SUBJECT_SIMPLE_NAME = 0;
export declare const CAPICOM_CURRENT_USER_STORE = 2;
export declare const CAPICOM_DIGITAL_SIGNATURE_KEY_USAGE = 128;
export declare const CAPICOM_EKU_CLIENT_AUTH = 2;
export declare const CAPICOM_EKU_OTHER = 0;
export declare const CAPICOM_EKU_SMARTCARD_LOGON = 5;
export declare const CAPICOM_LOCAL_MACHINE_STORE = 1;
export declare const CAPICOM_MEMORY_STORE = 0;
export declare const CAPICOM_MY_STORE = "My";
export declare const CAPICOM_OID_KEY_USAGE_EXTENSION = 10;
export declare const CAPICOM_OID_OTHER = 0;
export declare const CAPICOM_PROPID_ACCESS_STATE = 14;
export declare const CAPICOM_PROPID_ARCHIVED = 19;
export declare const CAPICOM_PROPID_ARCHIVED_KEY_HASH = 65;
export declare const CAPICOM_PROPID_AUTO_ENROLL = 21;
export declare const CAPICOM_PROPID_CROSS_CERT_DIST_POINTS = 23;
export declare const CAPICOM_PROPID_CTL_USAGE = 9;
export declare const CAPICOM_PROPID_DATE_STAMP = 27;
export declare const CAPICOM_PROPID_DESCRIPTION = 13;
export declare const CAPICOM_PROPID_EFS = 17;
export declare const CAPICOM_PROPID_ENHKEY_USAGE = 9;
export declare const CAPICOM_PROPID_ENROLLMENT = 26;
export declare const CAPICOM_PROPID_EXTENDED_ERROR_INFO = 30;
export declare const CAPICOM_PROPID_FIRST_RESERVED = 66;
export declare const CAPICOM_PROPID_FIRST_USER = 32768;
export declare const CAPICOM_PROPID_FORTEZZA_DATA = 18;
export declare const CAPICOM_PROPID_FRIENDLY_NAME = 11;
export declare const CAPICOM_PROPID_HASH_PROP = 3;
export declare const CAPICOM_PROPID_IE30_RESERVED = 7;
export declare const CAPICOM_PROPID_ISSUER_PUBLIC_KEY_MD5_HASH = 24;
export declare const CAPICOM_PROPID_ISSUER_SERIAL_NUMBER_MD5_HASH = 28;
export declare const CAPICOM_PROPID_KEY_CONTEXT = 5;
export declare const CAPICOM_PROPID_KEY_IDENTIFIER = 20;
export declare const CAPICOM_PROPID_KEY_PROV_HANDLE = 1;
export declare const CAPICOM_PROPID_KEY_PROV_INFO = 2;
export declare const CAPICOM_PROPID_KEY_SPEC = 6;
export declare const CAPICOM_PROPID_LAST_RESERVED = 32767;
export declare const CAPICOM_PROPID_LAST_USER = 65535;
export declare const CAPICOM_PROPID_MD5_HASH = 4;
export declare const CAPICOM_PROPID_NEXT_UPDATE_LOCATION = 10;
export declare const CAPICOM_PROPID_PUBKEY_ALG_PARA = 22;
export declare const CAPICOM_PROPID_PUBKEY_HASH_RESERVED = 8;
export declare const CAPICOM_PROPID_PVK_FILE = 12;
export declare const CAPICOM_PROPID_RENEWAL = 64;
export declare const CAPICOM_PROPID_SHA1_HASH = 3;
export declare const CAPICOM_PROPID_SIGNATURE_HASH = 15;
export declare const CAPICOM_PROPID_SMART_CARD_DATA = 16;
export declare const CAPICOM_PROPID_SUBJECT_NAME_MD5_HASH = 29;
export declare const CAPICOM_PROPID_SUBJECT_PUBLIC_KEY_MD5_HASH = 25;
export declare const CAPICOM_PROPID_UNKNOWN = 0;
export declare const CAPICOM_SMART_CARD_USER_STORE = 4;
export declare const CAPICOM_STORE_OPEN_EXISTING_ONLY = 128;
export declare const CAPICOM_STORE_OPEN_INCLUDE_ARCHIVED = 256;
export declare const CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED = 2;
export declare const CAPICOM_STORE_OPEN_READ_ONLY = 0;
export declare const CAPICOM_STORE_OPEN_READ_WRITE = 1;
export declare const CHECK_NONE = 0;
export declare const CHECK_OFFLINE_REVOCATION_STATUS = 16;
export declare const CHECK_ONLINE_REVOCATION_STATUS = 8;
export declare const CHECK_SIGNATURE_VALIDITY = 4;
export declare const CHECK_TIME_VALIDITY = 2;
export declare const CHECK_TRUSTED_ROOT = 1;
export declare const LOG_LEVEL_DEBUG = 4;
export declare const LOG_LEVEL_ERROR = 1;
export declare const LOG_LEVEL_INFO = 2;
export declare const TRUST_CTL_IS_NOT_SIGNATURE_VALID = 262144;
export declare const TRUST_CTL_IS_NOT_TIME_VALID = 131072;
export declare const TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 524288;
export declare const TRUST_IS_CYCLIC = 128;
export declare const TRUST_IS_NOT_SIGNATURE_VALID = 8;
export declare const TRUST_IS_NOT_TIME_NESTED = 2;
export declare const TRUST_IS_NOT_TIME_VALID = 1;
export declare const TRUST_IS_NOT_VALID_FOR_USAGE = 16;
export declare const TRUST_IS_PARTIAL_CHAIN = 65536;
export declare const TRUST_IS_REVOKED = 4;
export declare const TRUST_IS_UNTRUSTED_ROOT = 32;
export declare const TRUST_REVOCATION_STATUS_UNKNOWN = 64;
export declare const XmlDsigGost3410Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411";
export declare const XmlDsigGost3410UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411";
export declare const XmlDsigGost3411Url = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr3411";
export declare const XmlDsigGost3411UrlObsolete = "http://www.w3.org/2001/04/xmldsig-more#gostr3411";

View File

@ -1,4 +0,0 @@
export * from './cades-constants';
export * from './issuer-tags-translations';
export * from './oids-dictionary';
export * from './subject-tags-translations';

View File

@ -1,2 +0,0 @@
import { TagsTranslations } from './tags-translations';
export declare const ISSUER_TAGS_TRANSLATIONS: TagsTranslations[];

View File

@ -1,44 +0,0 @@
export declare const OIDS_DICTIONARY: {
'1.2.643.2.2.34.6': string;
'1.2.643.2.39.1.1': string;
'1.2.643.3.131.1.1': string;
'1.2.643.3.141.1.1': string;
'1.2.643.3.141.1.2': string;
'1.2.643.3.2.100.65.13.11': string;
'1.2.643.3.8.100.1': string;
'1.2.643.3.8.100.1.1': string;
'1.2.643.3.8.100.1.10': string;
'1.2.643.3.8.100.1.11': string;
'1.2.643.3.8.100.1.12': string;
'1.2.643.3.8.100.1.13': string;
'1.2.643.3.8.100.1.14': string;
'1.2.643.3.8.100.1.2': string;
'1.2.643.3.8.100.1.3': string;
'1.2.643.3.8.100.1.4': string;
'1.2.643.3.8.100.1.5': string;
'1.2.643.3.8.100.1.6': string;
'1.2.643.3.8.100.1.7': string;
'1.2.643.3.8.100.1.8': string;
'1.2.643.3.8.100.1.9': string;
'1.2.643.5.1.24.2.1.3': string;
'1.2.643.5.1.24.2.1.3.1': string;
'1.2.643.5.1.24.2.2.2': string;
'1.2.643.5.1.24.2.2.3': string;
'1.2.643.6.2.1.7.1': string;
'1.2.643.6.2.1.7.2': string;
'1.2.643.6.3': string;
'1.2.643.6.3.1.1': string;
'1.2.643.6.3.1.2.1': string;
'1.2.643.6.3.1.2.2': string;
'1.2.643.6.3.1.2.3': string;
'1.2.643.6.3.1.3.1': string;
'1.2.643.6.3.1.4.1': string;
'1.2.643.6.3.1.4.2': string;
'1.2.643.6.3.1.4.3': string;
'1.2.840.113549.1.9.2': string;
'1.3.6.1.4.1.24138.1.1.8.1': string;
'1.3.6.1.4.1.29919.21': string;
'1.3.6.1.5.5.7.3.2': string;
'1.3.6.1.5.5.7.3.4': string;
'1.3.643.3.8.100.15': string;
};

View File

@ -1,2 +0,0 @@
import { TagsTranslations } from './tags-translations';
export declare const SUBJECT_TAGS_TRANSLATIONS: TagsTranslations[];

View File

@ -1,4 +0,0 @@
export interface TagsTranslations {
possibleNames: string[];
translation: string;
}

5
lib/crypto-pro.d.ts vendored
View File

@ -1,5 +0,0 @@
// Type definitions for crypto-pro 2.2.2
// Project: crypto-pro
// Definitions by: Vitalii Goma https://github.com/vgoma
export * from './api';

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
declare type Unpromisify<T> = T extends Promise<infer R> ? R : T;
export declare const _afterPluginsLoaded: <T extends (...args: any[]) => any>(fn: T) => (...args: Parameters<T>) => Promise<Unpromisify<ReturnType<T>>>;
export {};

View File

@ -1 +0,0 @@
export declare const _extractCommonName: (subjectName: string) => string;

View File

@ -1 +0,0 @@
export declare const _extractMeaningfulErrorMessage: (error: Error) => string;

View File

@ -1,3 +0,0 @@
export declare const __cadesAsyncToken__: {};
export declare const __createCadesPluginObject__: (...args: any[]) => any;
export declare const _generateCadesFn: (callback: Function) => string;

View File

@ -1,7 +0,0 @@
/**
* Возвращает сертификат в формате Cades по отпечатку
*
* @param thumbprint - отпечаток сертификата
* @returns сертификат в формате Cades
*/
export declare const _getCadesCert: (thumbprint: string) => Promise<any>;

View File

@ -1,7 +0,0 @@
/**
* Возвращает объект даты, совместимый с Cades plugin'ом, зависящий от браузера.
*
* В IE необходимо использовать специфичный формат "VT_DATE"
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Microsoft_Extensions/Date.getVarDate
*/
export declare const _getDateObj: (dateObj: any) => Date;

View File

@ -1 +0,0 @@
export declare const _isSupportedCSPVersion: (version: string) => boolean;

View File

@ -1 +0,0 @@
export declare const _isSupportedCadesVersion: (version: string) => boolean;

View File

@ -1,14 +0,0 @@
import { TagsTranslations } from '../constants/tags-translations';
export interface TagTranslation {
description: string;
title: string;
isTranslated: boolean;
}
/**
* Парсит информацию из строки с информацией о сертификате
*
* @param tagsTranslations - словарь с расшифровками тэгов
* @param rawInfo - данные для парсинга
* @returns расшифрованная информация по отдельным тэгам
*/
export declare const _parseCertInfo: (tagsTranslations: TagsTranslations[], rawInfo: string) => TagTranslation[];

View File

@ -1,10 +1,6 @@
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded';
import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage'; import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage';
import { import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn';
__cadesAsyncToken__,
__createCadesPluginObject__,
_generateCadesFn,
} from '../helpers/_generateCadesFn';
/** /**
* Предоставляет информацию о системе * Предоставляет информацию о системе
@ -19,8 +15,7 @@ export const getCspVersion = _afterPluginsLoaded((): string => {
let cadesAbout; let cadesAbout;
try { try {
cadesAbout = cadesAbout = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About');
__cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About');
cspVersion = __cadesAsyncToken__ + cadesAbout.CSPVersion(); cspVersion = __cadesAsyncToken__ + cadesAbout.CSPVersion();
@ -28,10 +23,7 @@ export const getCspVersion = _afterPluginsLoaded((): string => {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
throw new Error( throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при получении версии системы');
_extractMeaningfulErrorMessage(error) ||
'Ошибка при получении версии системы',
);
} }
return cspVersion; return cspVersion;

View File

@ -1,12 +1,7 @@
import 'cadesplugin'; import 'cadesplugin';
import { getPluginVersion } from './getPluginVersion'; import { getPluginVersion } from './getPluginVersion';
const executionSteps = [ const executionSteps = [Symbol('step 0'), Symbol('step 1'), Symbol('step 2'), Symbol('step 3')];
Symbol('step 0'),
Symbol('step 1'),
Symbol('step 2'),
Symbol('step 3'),
];
// "any" because of using toString on the literal // "any" because of using toString on the literal
const executionFlow: any = { const executionFlow: any = {
@ -22,9 +17,7 @@ const executionFlow: any = {
}; };
window.cadesplugin.__defineExecutionFlow(executionFlow); window.cadesplugin.__defineExecutionFlow(executionFlow);
window.cadesplugin.CreateObjectAsync.mockImplementation( window.cadesplugin.CreateObjectAsync.mockImplementation(() => executionSteps[0]);
() => executionSteps[0],
);
describe('getPluginVersion', () => { describe('getPluginVersion', () => {
test('returns information about plugin', async () => { test('returns information about plugin', async () => {

View File

@ -1,9 +1,5 @@
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded';
import { import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn';
__cadesAsyncToken__,
__createCadesPluginObject__,
_generateCadesFn,
} from '../helpers/_generateCadesFn';
import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage'; import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage';
/** /**
@ -19,8 +15,7 @@ export const getPluginVersion = _afterPluginsLoaded((): string => {
let cadesAbout; let cadesAbout;
try { try {
cadesAbout = cadesAbout = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About');
__cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About');
cadesVersion = __cadesAsyncToken__ + cadesAbout.PluginVersion; cadesVersion = __cadesAsyncToken__ + cadesAbout.PluginVersion;
@ -32,10 +27,7 @@ export const getPluginVersion = _afterPluginsLoaded((): string => {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
throw new Error( throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при получении информации о плагине');
_extractMeaningfulErrorMessage(error) ||
'Ошибка при получении информации о плагине',
);
} }
return cadesVersion; return cadesVersion;

View File

@ -13,14 +13,9 @@ export const _generateCadesFn = (callback: Function): string => {
const callbackLiteral = String(callback); const callbackLiteral = String(callback);
const callbackArguments = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)?.[1] || ''; const callbackArguments = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)?.[1] || '';
const callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1'); const callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1');
let crossEnvCallbackLiteral; let crossEnvCallbackLiteral = String(
if (callbackArguments) { new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody),
crossEnvCallbackLiteral = String( );
new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody),
);
} else {
crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackBody));
}
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace( crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(
/\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm, /\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm,

View File

@ -1,50 +1,88 @@
// @ts-ignore
import * as sinon from 'sinon';
import 'cadesplugin'; import 'cadesplugin';
import { CadesCertificate } from '../api/certificate'; import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from './_generateCadesFn';
import { _getCadesCert } from './_getCadesCert';
const certificateMock = { const CreateObjectAsync = window.cadesplugin.CreateObjectAsync;
IssuerName: 'no matter',
SubjectName: 'no matter',
Thumbprint: 'some thumbprint',
ValidFromDate: 'whatever',
ValidToDate: 'whatever',
};
const executionSteps = [Symbol('step 0'), Symbol('step 1'), Symbol('step 2'), Symbol('step 3'), Symbol('step 4')]; describe('_generateCadesFn', () => {
describe('synchronous environment', () => {
beforeEach(() => {
delete window.cadesplugin.CreateObjectAsync;
});
const executionFlow = { test('generates function body from named function callback', () => {
[executionSteps[0]]: { expect(
Certificates: executionSteps[1], _generateCadesFn(function namedFunction() {
Close: sinon.stub(), console.log('hello from named function');
Open: sinon.stub(), }),
}, ).toEqual(
[executionSteps[1]]: { `(function anonymous(
Count: executionSteps[3], ) {
Find: sinon.stub().returns(executionSteps[2]),
},
[executionSteps[2]]: {
Count: executionSteps[3],
Item: sinon.stub().returns(executionSteps[4]),
},
[executionSteps[3]]: 1,
[executionSteps[4]]: {
IssuerName: certificateMock.IssuerName,
SubjectName: certificateMock.SubjectName,
Thumbprint: certificateMock.Thumbprint,
ValidFromDate: certificateMock.ValidFromDate,
ValidToDate: certificateMock.ValidToDate,
},
};
window.cadesplugin.__defineExecutionFlow(executionFlow); console.log('hello from named function');
window.cadesplugin.CreateObjectAsync.mockImplementation(() => executionSteps[0]);
})();//# sourceURL=crypto-pro_namedFunction.js`,
);
});
describe('_getCadesCert', () => { test('generates function body from arrow function callback', () => {
test('returns certificate by a thumbprint', async () => { expect(_generateCadesFn(() => console.log('hello from arrow function'))).toEqual(
const certificate: CadesCertificate = await _getCadesCert(certificateMock.Thumbprint); `(function anonymous(
) {
return console.log('hello from arrow function');
})();//# sourceURL=crypto-pro_dynamicFn.js`,
);
});
expect(certificate).toStrictEqual(certificateMock); test('generates function body with synchronous vendor library references', () => {
expect(
_generateCadesFn(function methodInSyncEnvironment() {
const cadesFoo = __cadesAsyncToken__ + __createCadesPluginObject__('CADESCOM.Foo');
const cadesBar = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.Bar');
const cadesBarNoMatterWhat = __cadesAsyncToken__ + cadesBar.NoMatterWhat;
void (__cadesAsyncToken__ + cadesFoo.propset_WhateverProperty('whatever value'));
void (__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo));
}),
).toEqual(
`(function anonymous(
) {
var cadesFoo = cadesplugin.CreateObject('CADESCOM.Foo');
var cadesBar = cadesplugin.CreateObject('CAdESCOM.Bar');
var cadesBarNoMatterWhat = cadesBar.NoMatterWhat;
void (cadesFoo.WhateverProperty = 'whatever value');
void (cadesBarNoMatterWhat.whateverMethod(cadesFoo));
})();//# sourceURL=crypto-pro_methodInSyncEnvironment.js`,
);
});
});
describe('synchronous environment', () => {
beforeEach(() => {
window.cadesplugin.CreateObjectAsync = CreateObjectAsync;
});
test('generates function body with asynchronous vendor library references', () => {
expect(
_generateCadesFn(function methodInAsyncEnvironment() {
const cadesFoo = __cadesAsyncToken__ + __createCadesPluginObject__('CADESCOM.Foo');
const cadesBar = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.Bar');
const cadesBarNoMatterWhat = __cadesAsyncToken__ + cadesBar.NoMatterWhat;
void (__cadesAsyncToken__ + cadesFoo.propset_WhateverProperty('whatever value'));
void (__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo));
}),
).toEqual(
`cadesplugin.async_spawn(function* anonymous(
) {
var cadesFoo = yield cadesplugin.CreateObjectAsync('CADESCOM.Foo');
var cadesBar = yield cadesplugin.CreateObjectAsync('CAdESCOM.Bar');
var cadesBarNoMatterWhat = yield cadesBar.NoMatterWhat;
void (yield cadesFoo.propset_WhateverProperty('whatever value'));
void (yield cadesBarNoMatterWhat.whateverMethod(cadesFoo));
});//# sourceURL=crypto-pro_methodInAsyncEnvironment.js`,
);
});
}); });
}); });