mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2025-04-21 04:53:08 +03:00
2.3.0
This commit is contained in:
parent
c0566b7654
commit
c221132228
@ -123,6 +123,7 @@ import { getUserCertificates, Certificate } from 'crypto-pro';
|
|||||||
Используйте "createAttachedSignature" и "createDetachedSignature".
|
Используйте "createAttachedSignature" и "createDetachedSignature".
|
||||||
- [getSystemInfo](src/api/getSystemInfo.ts) - возвращает информацию о CSP и плагине
|
- [getSystemInfo](src/api/getSystemInfo.ts) - возвращает информацию о CSP и плагине
|
||||||
- [isValidSystemSetup](src/api/isValidSystemSetup.ts) - возвращает флаг корректности настроек ЭП на машине
|
- [isValidSystemSetup](src/api/isValidSystemSetup.ts) - возвращает флаг корректности настроек ЭП на машине
|
||||||
|
- [execute](src/api/execute.ts) - компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
|
||||||
<a name="api-certificate"></a>
|
<a name="api-certificate"></a>
|
||||||
### Методы объекта сертификата
|
### Методы объекта сертификата
|
||||||
|
27
dist/api/execute.d.ts
vendored
Normal file
27
dist/api/execute.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Функция кастомной реализации с доступом к Cades плагину напрямую
|
||||||
|
*
|
||||||
|
* @callback executeCallback
|
||||||
|
* @param exposedAPI - API доступные для кастомной реализации
|
||||||
|
* @param exposedAPI.cadesplugin - Cades плагин, предоставляемый КриптоПРО
|
||||||
|
* @param exposedAPI._generateCadesFn - функция, компилирующая тело передаваемой javascript функции для текущей среды
|
||||||
|
* @param exposedAPI.__cadesAsyncToken__ - синтетический маркер, подменяемый в рантайме
|
||||||
|
* @param exposedAPI.__createCadesPluginObject__ - функция для создания синхронных/асинхронных Cades объектов
|
||||||
|
* @param exposedAPI._extractMeaningfulErrorMessage - хелпер для извлечения текста ошибки
|
||||||
|
*
|
||||||
|
* @returns результат выполнения кастомной реализации
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
*
|
||||||
|
* @param {executeCallback} callback - функция, использующая низкоуровневый доступ к Cades плагину
|
||||||
|
*
|
||||||
|
* @returns асинхронный результат выполнения передаваемой функции
|
||||||
|
*/
|
||||||
|
export declare const execute: (callback: (exposedAPI: {
|
||||||
|
cadesplugin: any;
|
||||||
|
_generateCadesFn: (callback: Function) => string;
|
||||||
|
__cadesAsyncToken__: object;
|
||||||
|
__createCadesPluginObject__: (...args: any[]) => any;
|
||||||
|
_extractMeaningfulErrorMessage: (error: Error) => string;
|
||||||
|
}) => any) => Promise<any>;
|
1
dist/api/index.d.ts
vendored
1
dist/api/index.d.ts
vendored
@ -8,3 +8,4 @@ export * from './createDetachedSignature';
|
|||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
export * from './certificate';
|
export * from './certificate';
|
||||||
|
export * from './execute';
|
||||||
|
2
dist/crypto-pro.d.ts
vendored
2
dist/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// Type definitions for crypto-pro 2.2.0
|
// Type definitions for crypto-pro 2.3.0
|
||||||
// Project: crypto-pro
|
// Project: crypto-pro
|
||||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||||
|
|
||||||
|
92
dist/crypto-pro.js
vendored
92
dist/crypto-pro.js
vendored
@ -3324,6 +3324,93 @@ exports.createXMLSignature = _afterPluginsLoaded_1._afterPluginsLoaded(function
|
|||||||
}); });
|
}); });
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./api/execute.ts":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** ./api/execute.ts ***!
|
||||||
|
\************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
|
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||||
|
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||||
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||||
|
function step(op) {
|
||||||
|
if (f) throw new TypeError("Generator is already executing.");
|
||||||
|
while (_) try {
|
||||||
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||||
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||||
|
switch (op[0]) {
|
||||||
|
case 0: case 1: t = op; break;
|
||||||
|
case 4: _.label++; return { value: op[1], done: false };
|
||||||
|
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||||
|
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||||
|
default:
|
||||||
|
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||||
|
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||||
|
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||||
|
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||||
|
if (t[2]) _.ops.pop();
|
||||||
|
_.trys.pop(); continue;
|
||||||
|
}
|
||||||
|
op = body.call(thisArg, _);
|
||||||
|
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||||
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
var _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||||
|
var _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||||
|
var _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||||
|
/**
|
||||||
|
* Функция кастомной реализации с доступом к Cades плагину напрямую
|
||||||
|
*
|
||||||
|
* @callback executeCallback
|
||||||
|
* @param exposedAPI - API доступные для кастомной реализации
|
||||||
|
* @param exposedAPI.cadesplugin - Cades плагин, предоставляемый КриптоПРО
|
||||||
|
* @param exposedAPI._generateCadesFn - функция, компилирующая тело передаваемой javascript функции для текущей среды
|
||||||
|
* @param exposedAPI.__cadesAsyncToken__ - синтетический маркер, подменяемый в рантайме
|
||||||
|
* @param exposedAPI.__createCadesPluginObject__ - функция для создания синхронных/асинхронных Cades объектов
|
||||||
|
* @param exposedAPI._extractMeaningfulErrorMessage - хелпер для извлечения текста ошибки
|
||||||
|
*
|
||||||
|
* @returns результат выполнения кастомной реализации
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
*
|
||||||
|
* @param {executeCallback} callback - функция, использующая низкоуровневый доступ к Cades плагину
|
||||||
|
*
|
||||||
|
* @returns асинхронный результат выполнения передаваемой функции
|
||||||
|
*/
|
||||||
|
exports.execute = _afterPluginsLoaded_1._afterPluginsLoaded(function (callback) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0: return [4 /*yield*/, callback({
|
||||||
|
cadesplugin: window.cadesplugin,
|
||||||
|
_generateCadesFn: _generateCadesFn_1._generateCadesFn,
|
||||||
|
__cadesAsyncToken__: _generateCadesFn_1.__cadesAsyncToken__,
|
||||||
|
__createCadesPluginObject__: _generateCadesFn_1.__createCadesPluginObject__,
|
||||||
|
_extractMeaningfulErrorMessage: _extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage,
|
||||||
|
})];
|
||||||
|
case 1: return [2 /*return*/, _a.sent()];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); });
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ "./api/getCertificate.ts":
|
/***/ "./api/getCertificate.ts":
|
||||||
@ -3563,6 +3650,7 @@ __export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetac
|
|||||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
||||||
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
||||||
|
__export(__webpack_require__(/*! ./execute */ "./api/execute.ts"));
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -4154,8 +4242,8 @@ exports._generateCadesFn = function (callback) {
|
|||||||
var callbackArguments = ((_a = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
var callbackArguments = ((_a = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
||||||
var callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1');
|
var callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1');
|
||||||
var crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody));
|
var crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody));
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm, "cadesplugin.CreateObject" + (cadesGeneratorsAPI ? 'Async' : '') + "$1");
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/(?:\w+?\.)?__createCadesPluginObject__(\([\s\S]*?\))/gm, "cadesplugin.CreateObject" + (cadesGeneratorsAPI ? 'Async' : '') + "$1");
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/\w+?\.__cadesAsyncToken__\s*?\+\s*?\b/gm, cadesGeneratorsAPI ? 'yield ' : '');
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/(?:\w+?\.)?__cadesAsyncToken__\s*?\+\s*?\b/gm, cadesGeneratorsAPI ? 'yield ' : '');
|
||||||
if (!cadesGeneratorsAPI) {
|
if (!cadesGeneratorsAPI) {
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/propset_(.*?)\((.*?)\)/gm, '$1 = $2');
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/propset_(.*?)\((.*?)\)/gm, '$1 = $2');
|
||||||
}
|
}
|
||||||
|
2
dist/crypto-pro.js.map
vendored
2
dist/crypto-pro.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/crypto-pro.min.js
vendored
4
dist/crypto-pro.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/crypto-pro.min.js.map
vendored
2
dist/crypto-pro.min.js.map
vendored
File diff suppressed because one or more lines are too long
6
examples/angular/package-lock.json
generated
6
examples/angular/package-lock.json
generated
@ -3308,9 +3308,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.3.0.tgz",
|
||||||
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
"integrity": "sha512-cppYuMRRijEaZ0UKAOW5L1CQIvzQA3DTRp4pARINl6K8Pp1JMhlch5TyWwv6Z4Y3x677A9xxcW62okHD91Veqg=="
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"@angular/platform-browser": "~9.0.7",
|
"@angular/platform-browser": "~9.0.7",
|
||||||
"@angular/platform-browser-dynamic": "~9.0.7",
|
"@angular/platform-browser-dynamic": "~9.0.7",
|
||||||
"@angular/router": "~9.0.7",
|
"@angular/router": "~9.0.7",
|
||||||
"crypto-pro": "2.2.0",
|
"crypto-pro": "^2.3.0",
|
||||||
"rxjs": "~6.5.4",
|
"rxjs": "~6.5.4",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
"zone.js": "~0.10.2"
|
"zone.js": "~0.10.2"
|
||||||
|
@ -101,6 +101,8 @@
|
|||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Информация о системе</legend>
|
<legend>Информация о системе</legend>
|
||||||
|
<pre *ngIf="customSystemInfo">{{customSystemInfo | json}}</pre>
|
||||||
|
<pre>{{customSystemInfoError}}</pre>
|
||||||
<pre *ngIf="systemInfo">{{systemInfo | json}}</pre>
|
<pre *ngIf="systemInfo">{{systemInfo | json}}</pre>
|
||||||
<pre>{{systemInfoError}}</pre>
|
<pre>{{systemInfoError}}</pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
createHash,
|
createHash,
|
||||||
createDetachedSignature,
|
createDetachedSignature,
|
||||||
createAttachedSignature,
|
createAttachedSignature,
|
||||||
|
execute,
|
||||||
SystemInfo,
|
SystemInfo,
|
||||||
Certificate
|
Certificate
|
||||||
} from 'crypto-pro';
|
} from 'crypto-pro';
|
||||||
@ -25,6 +26,8 @@ export class CryptoProComponent implements OnInit {
|
|||||||
public thumbprint: string = null;
|
public thumbprint: string = null;
|
||||||
public signature: string = null;
|
public signature: string = null;
|
||||||
public signatureStatus = 'Не создана';
|
public signatureStatus = 'Не создана';
|
||||||
|
public customSystemInfo: string = null;
|
||||||
|
public customSystemInfoError: string = null;
|
||||||
public systemInfo: SystemInfo & {
|
public systemInfo: SystemInfo & {
|
||||||
isValidSystemSetup: boolean;
|
isValidSystemSetup: boolean;
|
||||||
};
|
};
|
||||||
@ -39,6 +42,7 @@ export class CryptoProComponent implements OnInit {
|
|||||||
|
|
||||||
public ngOnInit(): void {
|
public ngOnInit(): void {
|
||||||
this.displayCertificates();
|
this.displayCertificates();
|
||||||
|
this.displayCustomSystemInfo();
|
||||||
this.displaySystemInfo();
|
this.displaySystemInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,4 +145,43 @@ export class CryptoProComponent implements OnInit {
|
|||||||
this.systemInfoError = error.message;
|
this.systemInfoError = error.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async displayCustomSystemInfo() {
|
||||||
|
this.customSystemInfoError = null;
|
||||||
|
|
||||||
|
// Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider
|
||||||
|
const providerType = 75;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.customSystemInfo = await execute(function (utils) {
|
||||||
|
return eval(
|
||||||
|
utils._generateCadesFn(function getVersion() {
|
||||||
|
var cadesAbout, cadesVersion, minor, major, build, version, providerName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cadesAbout = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CAdESCOM.About');
|
||||||
|
providerName = utils.__cadesAsyncToken__ + cadesAbout.CSPName();
|
||||||
|
cadesVersion = utils.__cadesAsyncToken__ + cadesAbout.CSPVersion(providerName, providerType);
|
||||||
|
minor = utils.__cadesAsyncToken__ + cadesVersion.MinorVersion;
|
||||||
|
major = utils.__cadesAsyncToken__ + cadesVersion.MajorVersion;
|
||||||
|
build = utils.__cadesAsyncToken__ + cadesVersion.BuildVersion;
|
||||||
|
version = utils.__cadesAsyncToken__ + cadesVersion.toString();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(utils._extractMeaningfulErrorMessage(error) || 'Ошибка при извлечении информации');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
providerName,
|
||||||
|
[major, minor, build].join('.'),
|
||||||
|
version
|
||||||
|
].join(', ');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.customSystemInfoError = error.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
6
examples/react/package-lock.json
generated
6
examples/react/package-lock.json
generated
@ -3712,9 +3712,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.3.0.tgz",
|
||||||
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
"integrity": "sha512-cppYuMRRijEaZ0UKAOW5L1CQIvzQA3DTRp4pARINl6K8Pp1JMhlch5TyWwv6Z4Y3x677A9xxcW62okHD91Veqg=="
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"@testing-library/jest-dom": "4.2.4",
|
"@testing-library/jest-dom": "4.2.4",
|
||||||
"@testing-library/react": "9.5.0",
|
"@testing-library/react": "9.5.0",
|
||||||
"@testing-library/user-event": "7.2.1",
|
"@testing-library/user-event": "7.2.1",
|
||||||
"crypto-pro": "2.2.0",
|
"crypto-pro": "^2.3.0",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-app-polyfill": "1.0.6",
|
"react-app-polyfill": "1.0.6",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
@ -5,6 +5,7 @@ import Certificate from './components/Certificate';
|
|||||||
import SignatureType from './components/SignatureType';
|
import SignatureType from './components/SignatureType';
|
||||||
import Hash from './components/Hash';
|
import Hash from './components/Hash';
|
||||||
import Signature from './components/Signature';
|
import Signature from './components/Signature';
|
||||||
|
import CustomSystemInfo from './components/CustomSystemInfo';
|
||||||
import SystemInfo from './components/SystemInfo';
|
import SystemInfo from './components/SystemInfo';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@ -110,6 +111,8 @@ function App() {
|
|||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
<legend>Информация о системе</legend>
|
||||||
|
<CustomSystemInfo/>
|
||||||
<SystemInfo/>
|
<SystemInfo/>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</>
|
</>
|
||||||
|
58
examples/react/src/components/CustomSystemInfo.js
Normal file
58
examples/react/src/components/CustomSystemInfo.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { execute } from 'crypto-pro';
|
||||||
|
|
||||||
|
function CustomSystemInfo() {
|
||||||
|
const [customSystemInfo, setCustomSystemInfo] = useState(null);
|
||||||
|
const [customSystemInfoError, setCustomSystemInfoError] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
// Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider
|
||||||
|
const providerType = 75;
|
||||||
|
|
||||||
|
setCustomSystemInfo(await execute(function (utils) {
|
||||||
|
return eval(
|
||||||
|
utils._generateCadesFn(function getVersion() {
|
||||||
|
var cadesAbout, cadesVersion, minor, major, build, version, providerName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cadesAbout = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CAdESCOM.About');
|
||||||
|
providerName = utils.__cadesAsyncToken__ + cadesAbout.CSPName();
|
||||||
|
cadesVersion = utils.__cadesAsyncToken__ + cadesAbout.CSPVersion(providerName, providerType);
|
||||||
|
minor = utils.__cadesAsyncToken__ + cadesVersion.MinorVersion;
|
||||||
|
major = utils.__cadesAsyncToken__ + cadesVersion.MajorVersion;
|
||||||
|
build = utils.__cadesAsyncToken__ + cadesVersion.BuildVersion;
|
||||||
|
version = utils.__cadesAsyncToken__ + cadesVersion.toString();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(utils._extractMeaningfulErrorMessage(error) || 'Ошибка при извлечении информации');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
providerName,
|
||||||
|
[major, minor, build].join('.'),
|
||||||
|
version
|
||||||
|
].join(', ');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
setCustomSystemInfoError(error.message);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<pre>
|
||||||
|
{customSystemInfo ? (
|
||||||
|
JSON.stringify(customSystemInfo, null, ' ')
|
||||||
|
) : (
|
||||||
|
customSystemInfoError || null
|
||||||
|
)}
|
||||||
|
</pre>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CustomSystemInfo;
|
@ -19,9 +19,6 @@ function SystemInfo() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<legend>Информация о системе</legend>
|
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
{systemInfo ? (
|
{systemInfo ? (
|
||||||
JSON.stringify(systemInfo, null, ' ')
|
JSON.stringify(systemInfo, null, ' ')
|
||||||
@ -29,7 +26,6 @@ function SystemInfo() {
|
|||||||
systemInfoError || null
|
systemInfoError || null
|
||||||
)}
|
)}
|
||||||
</pre>
|
</pre>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
examples/script-tag/package-lock.json
generated
6
examples/script-tag/package-lock.json
generated
@ -42,9 +42,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.3.0.tgz",
|
||||||
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
"integrity": "sha512-cppYuMRRijEaZ0UKAOW5L1CQIvzQA3DTRp4pARINl6K8Pp1JMhlch5TyWwv6Z4Y3x677A9xxcW62okHD91Veqg=="
|
||||||
},
|
},
|
||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
"symlink-dir": "3.1.2"
|
"symlink-dir": "3.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-pro": "2.2.0"
|
"crypto-pro": "^2.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
examples/script-tag/public/custom-implementation.js
Normal file
49
examples/script-tag/public/custom-implementation.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Пример написания своей реализации используя Cades плагин
|
||||||
|
*/
|
||||||
|
;(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
function customAboutImplementation() {
|
||||||
|
// Crypto-Pro GOST R 34.10-2001 Cryptographic Service Provider
|
||||||
|
var providerType = 75;
|
||||||
|
|
||||||
|
return window.cryptoPro.execute(function (utils) {
|
||||||
|
return eval(
|
||||||
|
utils._generateCadesFn(function getVersion() {
|
||||||
|
var cadesAbout, cadesVersion, minor, major, build, version, providerName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cadesAbout = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CAdESCOM.About');
|
||||||
|
providerName = utils.__cadesAsyncToken__ + cadesAbout.CSPName();
|
||||||
|
cadesVersion = utils.__cadesAsyncToken__ + cadesAbout.CSPVersion(providerName, providerType);
|
||||||
|
minor = utils.__cadesAsyncToken__ + cadesVersion.MinorVersion;
|
||||||
|
major = utils.__cadesAsyncToken__ + cadesVersion.MajorVersion;
|
||||||
|
build = utils.__cadesAsyncToken__ + cadesVersion.BuildVersion;
|
||||||
|
version = utils.__cadesAsyncToken__ + cadesVersion.toString();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(utils._extractMeaningfulErrorMessage(error) || 'Ошибка при извлечении информации');
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
providerName,
|
||||||
|
[major, minor, build].join('.'),
|
||||||
|
version
|
||||||
|
].join(', ');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
customAboutImplementation().then(function (systemInfo) {
|
||||||
|
var $customSystemInfo = document.getElementById('customSystemInfo');
|
||||||
|
|
||||||
|
$customSystemInfo.textContent = systemInfo;
|
||||||
|
}, function (error) {
|
||||||
|
var $customSystemInfoError = document.getElementById('customSystemInfoError');
|
||||||
|
|
||||||
|
$customSystemInfoError.textContent = error.message;
|
||||||
|
});
|
||||||
|
})();
|
@ -72,6 +72,8 @@
|
|||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Информация о системе</legend>
|
<legend>Информация о системе</legend>
|
||||||
|
<pre id="customSystemInfo"></pre>
|
||||||
|
<pre id="customSystemInfoError"></pre>
|
||||||
<pre id="systemInfo"></pre>
|
<pre id="systemInfo"></pre>
|
||||||
<pre id="systemInfoError"></pre>
|
<pre id="systemInfoError"></pre>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@ -92,6 +94,7 @@
|
|||||||
<script src="cert-list.js"></script>
|
<script src="cert-list.js"></script>
|
||||||
<script src="create-sign.js"></script>
|
<script src="create-sign.js"></script>
|
||||||
<script src="get-env-info.js"></script>
|
<script src="get-env-info.js"></script>
|
||||||
|
<script src="custom-implementation.js"></script>
|
||||||
<script src="show-cert.js"></script>
|
<script src="show-cert.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
27
lib/api/execute.d.ts
vendored
Normal file
27
lib/api/execute.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Функция кастомной реализации с доступом к Cades плагину напрямую
|
||||||
|
*
|
||||||
|
* @callback executeCallback
|
||||||
|
* @param exposedAPI - API доступные для кастомной реализации
|
||||||
|
* @param exposedAPI.cadesplugin - Cades плагин, предоставляемый КриптоПРО
|
||||||
|
* @param exposedAPI._generateCadesFn - функция, компилирующая тело передаваемой javascript функции для текущей среды
|
||||||
|
* @param exposedAPI.__cadesAsyncToken__ - синтетический маркер, подменяемый в рантайме
|
||||||
|
* @param exposedAPI.__createCadesPluginObject__ - функция для создания синхронных/асинхронных Cades объектов
|
||||||
|
* @param exposedAPI._extractMeaningfulErrorMessage - хелпер для извлечения текста ошибки
|
||||||
|
*
|
||||||
|
* @returns результат выполнения кастомной реализации
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
*
|
||||||
|
* @param {executeCallback} callback - функция, использующая низкоуровневый доступ к Cades плагину
|
||||||
|
*
|
||||||
|
* @returns асинхронный результат выполнения передаваемой функции
|
||||||
|
*/
|
||||||
|
export declare const execute: (callback: (exposedAPI: {
|
||||||
|
cadesplugin: any;
|
||||||
|
_generateCadesFn: (callback: Function) => string;
|
||||||
|
__cadesAsyncToken__: object;
|
||||||
|
__createCadesPluginObject__: (...args: any[]) => any;
|
||||||
|
_extractMeaningfulErrorMessage: (error: Error) => string;
|
||||||
|
}) => any) => Promise<any>;
|
1
lib/api/index.d.ts
vendored
1
lib/api/index.d.ts
vendored
@ -8,3 +8,4 @@ export * from './createDetachedSignature';
|
|||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
export * from './certificate';
|
export * from './certificate';
|
||||||
|
export * from './execute';
|
||||||
|
2
lib/crypto-pro.d.ts
vendored
2
lib/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// Type definitions for crypto-pro 2.2.0
|
// Type definitions for crypto-pro 2.3.0
|
||||||
// Project: crypto-pro
|
// Project: crypto-pro
|
||||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||||
|
|
||||||
|
@ -3035,6 +3035,61 @@ exports.createXMLSignature = _afterPluginsLoaded_1._afterPluginsLoaded((thumbpri
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./api/execute.ts":
|
||||||
|
/*!************************!*\
|
||||||
|
!*** ./api/execute.ts ***!
|
||||||
|
\************************/
|
||||||
|
/*! no static exports found */
|
||||||
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||||
|
const _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||||
|
const _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||||
|
/**
|
||||||
|
* Функция кастомной реализации с доступом к Cades плагину напрямую
|
||||||
|
*
|
||||||
|
* @callback executeCallback
|
||||||
|
* @param exposedAPI - API доступные для кастомной реализации
|
||||||
|
* @param exposedAPI.cadesplugin - Cades плагин, предоставляемый КриптоПРО
|
||||||
|
* @param exposedAPI._generateCadesFn - функция, компилирующая тело передаваемой javascript функции для текущей среды
|
||||||
|
* @param exposedAPI.__cadesAsyncToken__ - синтетический маркер, подменяемый в рантайме
|
||||||
|
* @param exposedAPI.__createCadesPluginObject__ - функция для создания синхронных/асинхронных Cades объектов
|
||||||
|
* @param exposedAPI._extractMeaningfulErrorMessage - хелпер для извлечения текста ошибки
|
||||||
|
*
|
||||||
|
* @returns результат выполнения кастомной реализации
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
*
|
||||||
|
* @param {executeCallback} callback - функция, использующая низкоуровневый доступ к Cades плагину
|
||||||
|
*
|
||||||
|
* @returns асинхронный результат выполнения передаваемой функции
|
||||||
|
*/
|
||||||
|
exports.execute = _afterPluginsLoaded_1._afterPluginsLoaded((callback) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
return yield callback({
|
||||||
|
cadesplugin: window.cadesplugin,
|
||||||
|
_generateCadesFn: _generateCadesFn_1._generateCadesFn,
|
||||||
|
__cadesAsyncToken__: _generateCadesFn_1.__cadesAsyncToken__,
|
||||||
|
__createCadesPluginObject__: _generateCadesFn_1.__createCadesPluginObject__,
|
||||||
|
_extractMeaningfulErrorMessage: _extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage,
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ "./api/getCertificate.ts":
|
/***/ "./api/getCertificate.ts":
|
||||||
@ -3238,6 +3293,7 @@ __export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetac
|
|||||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
||||||
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
||||||
|
__export(__webpack_require__(/*! ./execute */ "./api/execute.ts"));
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -3746,8 +3802,8 @@ exports._generateCadesFn = (callback) => {
|
|||||||
const callbackArguments = ((_a = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
const callbackArguments = ((_a = callbackLiteral.match(/^function[\s\w]*?\((.*?)\)/)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
||||||
const callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1');
|
const callbackBody = callbackLiteral.replace(/^.*?{([\s\S]*?)}$/, '$1');
|
||||||
let crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody));
|
let crossEnvCallbackLiteral = String(new (cadesGeneratorsAPI ? getGeneratorConstructor() : Function)(callbackArguments, callbackBody));
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm, `cadesplugin.CreateObject${cadesGeneratorsAPI ? 'Async' : ''}$1`);
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/(?:\w+?\.)?__createCadesPluginObject__(\([\s\S]*?\))/gm, `cadesplugin.CreateObject${cadesGeneratorsAPI ? 'Async' : ''}$1`);
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/\w+?\.__cadesAsyncToken__\s*?\+\s*?\b/gm, cadesGeneratorsAPI ? 'yield ' : '');
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/(?:\w+?\.)?__cadesAsyncToken__\s*?\+\s*?\b/gm, cadesGeneratorsAPI ? 'yield ' : '');
|
||||||
if (!cadesGeneratorsAPI) {
|
if (!cadesGeneratorsAPI) {
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/propset_(.*?)\((.*?)\)/gm, '$1 = $2');
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(/propset_(.*?)\((.*?)\)/gm, '$1 = $2');
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "crypto-pro",
|
"name": "crypto-pro",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "crypto-pro",
|
"name": "crypto-pro",
|
||||||
"version": "2.2.0",
|
"version": "2.3.0",
|
||||||
"description": "API для взаимодействия с КриптоПро",
|
"description": "API для взаимодействия с КриптоПро",
|
||||||
"main": "./lib/crypto-pro.js",
|
"main": "./lib/crypto-pro.js",
|
||||||
"types": "./lib/crypto-pro.d.ts",
|
"types": "./lib/crypto-pro.d.ts",
|
||||||
|
35
src/api/execute.test.ts
Normal file
35
src/api/execute.test.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import 'cadesplugin';
|
||||||
|
import { execute } from './execute';
|
||||||
|
import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage';
|
||||||
|
import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn';
|
||||||
|
|
||||||
|
jest.mock('../helpers/_extractMeaningfulErrorMessage', () => ({ _extractMeaningfulErrorMessage: jest.fn() }));
|
||||||
|
jest.mock('../helpers/_generateCadesFn', () => ({
|
||||||
|
__cadesAsyncToken__: jest.fn(),
|
||||||
|
__createCadesPluginObject__: jest.fn(),
|
||||||
|
_generateCadesFn: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
(_extractMeaningfulErrorMessage as jest.Mock).mockClear();
|
||||||
|
(__cadesAsyncToken__ as jest.Mock).mockClear();
|
||||||
|
(__createCadesPluginObject__ as jest.Mock).mockClear();
|
||||||
|
(_generateCadesFn as jest.Mock).mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('execute', () => {
|
||||||
|
test('calls custom implementation with exposed API', async () => {
|
||||||
|
const customCallback = jest.fn();
|
||||||
|
|
||||||
|
await execute(customCallback);
|
||||||
|
|
||||||
|
expect(customCallback).toHaveBeenCalledTimes(1);
|
||||||
|
expect(customCallback).toHaveBeenCalledWith({
|
||||||
|
cadesplugin: window.cadesplugin,
|
||||||
|
_generateCadesFn,
|
||||||
|
__cadesAsyncToken__,
|
||||||
|
__createCadesPluginObject__,
|
||||||
|
_extractMeaningfulErrorMessage,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
43
src/api/execute.ts
Normal file
43
src/api/execute.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded';
|
||||||
|
import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage';
|
||||||
|
import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Функция кастомной реализации с доступом к Cades плагину напрямую
|
||||||
|
*
|
||||||
|
* @callback executeCallback
|
||||||
|
* @param exposedAPI - API доступные для кастомной реализации
|
||||||
|
* @param exposedAPI.cadesplugin - Cades плагин, предоставляемый КриптоПРО
|
||||||
|
* @param exposedAPI._generateCadesFn - функция, компилирующая тело передаваемой javascript функции для текущей среды
|
||||||
|
* @param exposedAPI.__cadesAsyncToken__ - синтетический маркер, подменяемый в рантайме
|
||||||
|
* @param exposedAPI.__createCadesPluginObject__ - функция для создания синхронных/асинхронных Cades объектов
|
||||||
|
* @param exposedAPI._extractMeaningfulErrorMessage - хелпер для извлечения текста ошибки
|
||||||
|
*
|
||||||
|
* @returns результат выполнения кастомной реализации
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Компилирует и выполняет переданную функцию для доступной браузерной среды (синхронной/асинхронной)
|
||||||
|
*
|
||||||
|
* @param {executeCallback} callback - функция, использующая низкоуровневый доступ к Cades плагину
|
||||||
|
*
|
||||||
|
* @returns асинхронный результат выполнения передаваемой функции
|
||||||
|
*/
|
||||||
|
export const execute = _afterPluginsLoaded(
|
||||||
|
async (
|
||||||
|
callback: (exposedAPI: {
|
||||||
|
cadesplugin: any;
|
||||||
|
_generateCadesFn: (callback: Function) => string;
|
||||||
|
__cadesAsyncToken__: object;
|
||||||
|
__createCadesPluginObject__: (...args) => any;
|
||||||
|
_extractMeaningfulErrorMessage: (error: Error) => string | null;
|
||||||
|
}) => any,
|
||||||
|
): Promise<any> =>
|
||||||
|
await callback({
|
||||||
|
cadesplugin: window.cadesplugin,
|
||||||
|
_generateCadesFn,
|
||||||
|
__cadesAsyncToken__,
|
||||||
|
__createCadesPluginObject__,
|
||||||
|
_extractMeaningfulErrorMessage,
|
||||||
|
}),
|
||||||
|
);
|
@ -8,3 +8,4 @@ export * from './createDetachedSignature';
|
|||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
export * from './certificate';
|
export * from './certificate';
|
||||||
|
export * from './execute';
|
||||||
|
@ -55,9 +55,32 @@ describe('_generateCadesFn', () => {
|
|||||||
})();//# sourceURL=crypto-pro_methodInSyncEnvironment.js`,
|
})();//# sourceURL=crypto-pro_methodInSyncEnvironment.js`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('generates function body for synchronous custom implementation', () => {
|
||||||
|
expect(
|
||||||
|
_generateCadesFn(function customSyncEnvImplementation(utils) {
|
||||||
|
const cadesFoo = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CADESCOM.Foo');
|
||||||
|
const cadesBar = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CAdESCOM.Bar');
|
||||||
|
const cadesBarNoMatterWhat = utils.__cadesAsyncToken__ + cadesBar.NoMatterWhat;
|
||||||
|
void (utils.__cadesAsyncToken__ + cadesFoo.propset_WhateverProperty('whatever value'));
|
||||||
|
void (utils.__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo));
|
||||||
|
}),
|
||||||
|
).toEqual(
|
||||||
|
`(function anonymous(utils
|
||||||
|
) {
|
||||||
|
|
||||||
|
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_customSyncEnvImplementation.js`,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('synchronous environment', () => {
|
describe('asynchronous environment', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
window.cadesplugin.CreateObjectAsync = CreateObjectAsync;
|
window.cadesplugin.CreateObjectAsync = CreateObjectAsync;
|
||||||
});
|
});
|
||||||
@ -84,5 +107,28 @@ describe('_generateCadesFn', () => {
|
|||||||
});//# sourceURL=crypto-pro_methodInAsyncEnvironment.js`,
|
});//# sourceURL=crypto-pro_methodInAsyncEnvironment.js`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('generates function body for asynchronous custom implementation', () => {
|
||||||
|
expect(
|
||||||
|
_generateCadesFn(function customAsyncEnvImplementation(utils) {
|
||||||
|
const cadesFoo = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CADESCOM.Foo');
|
||||||
|
const cadesBar = utils.__cadesAsyncToken__ + utils.__createCadesPluginObject__('CAdESCOM.Bar');
|
||||||
|
const cadesBarNoMatterWhat = utils.__cadesAsyncToken__ + cadesBar.NoMatterWhat;
|
||||||
|
void (utils.__cadesAsyncToken__ + cadesFoo.propset_WhateverProperty('whatever value'));
|
||||||
|
void (utils.__cadesAsyncToken__ + cadesBarNoMatterWhat.whateverMethod(cadesFoo));
|
||||||
|
}),
|
||||||
|
).toEqual(
|
||||||
|
`cadesplugin.async_spawn(function* anonymous(utils
|
||||||
|
) {
|
||||||
|
|
||||||
|
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_customAsyncEnvImplementation.js`,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -18,12 +18,12 @@ export const _generateCadesFn = (callback: Function): string => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(
|
||||||
/\w+?\.__createCadesPluginObject__(\([\s\S]*?\))/gm,
|
/(?:\w+?\.)?__createCadesPluginObject__(\([\s\S]*?\))/gm,
|
||||||
`cadesplugin.CreateObject${cadesGeneratorsAPI ? 'Async' : ''}$1`,
|
`cadesplugin.CreateObject${cadesGeneratorsAPI ? 'Async' : ''}$1`,
|
||||||
);
|
);
|
||||||
|
|
||||||
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(
|
crossEnvCallbackLiteral = crossEnvCallbackLiteral.replace(
|
||||||
/\w+?\.__cadesAsyncToken__\s*?\+\s*?\b/gm,
|
/(?:\w+?\.)?__cadesAsyncToken__\s*?\+\s*?\b/gm,
|
||||||
cadesGeneratorsAPI ? 'yield ' : '',
|
cadesGeneratorsAPI ? 'yield ' : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user