From 864c05f81c8a0375b49a52bee18d4daa661a3a07 Mon Sep 17 00:00:00 2001 From: vgoma Date: Wed, 7 Oct 2020 18:54:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=BA=D1=82=D1=83=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D1=81=20React?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/react/src/App.css | 38 ------ examples/react/src/App.js | 127 +++++++++++++++--- examples/react/src/components/Certificate.js | 101 ++++++++++++++ .../src/components/CryptoPro/CertInfo.js | 55 -------- .../src/components/CryptoPro/CertList.js | 31 ----- .../react/src/components/CryptoPro/Sign.js | 27 ---- .../react/src/components/CryptoPro/index.js | 27 ---- examples/react/src/components/Hash.js | 25 ++++ examples/react/src/components/Message.js | 35 +++++ examples/react/src/components/Signature.js | 23 ++++ .../react/src/components/SignatureType.js | 36 +++++ .../components/{CryptoPro => }/SystemInfo.js | 19 ++- examples/react/src/index.css | 13 -- examples/react/src/index.js | 1 - 14 files changed, 347 insertions(+), 211 deletions(-) delete mode 100644 examples/react/src/App.css create mode 100644 examples/react/src/components/Certificate.js delete mode 100644 examples/react/src/components/CryptoPro/CertInfo.js delete mode 100644 examples/react/src/components/CryptoPro/CertList.js delete mode 100644 examples/react/src/components/CryptoPro/Sign.js delete mode 100644 examples/react/src/components/CryptoPro/index.js create mode 100644 examples/react/src/components/Hash.js create mode 100644 examples/react/src/components/Message.js create mode 100644 examples/react/src/components/Signature.js create mode 100644 examples/react/src/components/SignatureType.js rename examples/react/src/components/{CryptoPro => }/SystemInfo.js (56%) delete mode 100644 examples/react/src/index.css diff --git a/examples/react/src/App.css b/examples/react/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/examples/react/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/examples/react/src/App.js b/examples/react/src/App.js index 7e9e533..dc8e28e 100644 --- a/examples/react/src/App.js +++ b/examples/react/src/App.js @@ -1,21 +1,118 @@ -import React from 'react'; -import './App.css'; -import CryptoPro from './components/CryptoPro'; +import React, { useState } from 'react'; +import { createAttachedSignature, createDetachedSignature, createHash } from 'crypto-pro'; +import Message from './components/Message'; +import Certificate from './components/Certificate'; +import SignatureType from './components/SignatureType'; +import Hash from './components/Hash'; +import Signature from './components/Signature'; +import SystemInfo from './components/SystemInfo'; function App() { + const [message, setMessage] = useState(''); + const [certificate, setCertificate] = useState(null); + const [detachedSignature, setSignatureType] = useState(null); + const [hash, setHash] = useState(''); + const [hashStatus, setHashStatus] = useState('Не вычислен'); + const [hashError, setHashError] = useState(null); + const [signature, setSignature] = useState(''); + const [signatureStatus, setSignatureStatus] = useState('Не создана'); + const [signatureError, setSignatureError] = useState(null); + + async function createSignature(event) { + let hash; + + event.preventDefault(); + + setSignature(''); + setSignatureError(null); + + setHash(''); + setHashError(null); + setHashStatus('Вычисляется...'); + + try { + hash = await createHash(message); + + setHash(hash); + } catch (error) { + setHashError(error.message); + + return; + } + + setHashStatus('Не вычислен'); + setSignatureStatus('Создается...'); + + if (detachedSignature) { + try { + setSignature(await createDetachedSignature(certificate.thumbprint, hash)); + } catch (error) { + setSignatureError(error.message); + } + + setSignatureStatus('Не создана'); + + return; + } + + try { + setSignature(await createAttachedSignature(certificate.thumbprint, message)); + } catch (error) { + setSignatureError(error.message); + } + + setSignatureStatus('Не создана'); + } + return ( - {({certificate, setCertificate, signature, setSignature, error, setError}) => - <> - - - Создать подпись - - -