Skip to content

Commit

Permalink
Merge pull request #19 from janeumnn/develop
Browse files Browse the repository at this point in the history
Merge "develop" into "main"
  • Loading branch information
janeumnn authored Dec 12, 2021
2 parents 40e0401 + aa54057 commit 67e283b
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 138 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openssl-webapp",
"version": "0.3.0",
"version": "0.4.0",
"private": true,
"homepage": "https://janeumnn.github.io/openssl-webapp",
"dependencies": {
Expand Down
14 changes: 13 additions & 1 deletion src/components/app/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import { Card } from 'react-bootstrap';
import CardControl from '../card-control/CardControl';
import CommandLine from '../../components/command-line/CommandLine';
Expand Down Expand Up @@ -87,7 +87,19 @@ function App() {
}
};

const getAvailableCiphers = useCallback(async () => {
const ciphers = await command.getCiphers();
dispatch({ type: 'SET_AVAILABLE_CIPHERS', ciphers: ciphers });
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const getAvailableDigests = useCallback(async () => {
const digests = await command.getDigests();
dispatch({ type: 'SET_AVAILABLE_DIGEST', digests: digests });
}, []); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
getAvailableCiphers();
getAvailableDigests();
const result = command.resultAsObservable.subscribe((value) => {
if (value) {
dispatch({ type: 'SET_LOADING', isLoading: false });
Expand Down
33 changes: 11 additions & 22 deletions src/components/card-control/components/tab-digest/TabDigest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@ import { useTranslation } from 'react-i18next';

import './TabDigest.css';

const ALGORITHMS = [
'blake2s256',
'blake2b512',
'md5',
'sha1',
'sha3-224',
'sha3-256',
'sha3-384',
'sha3-512',
'sha224',
'sha384',
'sha256',
'sha512',
'sha512-224',
'sha512-256',
'shake128',
'shake256',
'sm3',
];

function TabDigest({ runCommand }) {
const { t } = useTranslation('translation');
const { state, dispatch } = useStore();
Expand All @@ -35,7 +15,7 @@ function TabDigest({ runCommand }) {
fileOutput: false,
});
const [dgst, setDgst] = useState({
algorithm: ALGORITHMS[0],
algorithm: '',
out: false,
outFile: '',
text: true,
Expand All @@ -55,6 +35,15 @@ function TabDigest({ runCommand }) {
});
}, [state.files]);

useEffect(() => {
setDgst((prev) => {
return {
...prev,
algorithm: state.availableDigests[0],
};
});
}, [state.availableDigests]);

const set = (key) => (event) => {
const value = event.target.type === 'checkbox' ? event.target.checked : event.target.value;
switch (key) {
Expand Down Expand Up @@ -194,7 +183,7 @@ function TabDigest({ runCommand }) {
<Form.Group as={Col} md={5} controlId="dgst-algorithm">
<Form.Label className="mb-2">{t('tabDigest.hashFunction')}</Form.Label>
<Form.Control as="select" value={dgst.algorithm} onChange={set('algorithm')} custom>
{ALGORITHMS.map((algorithm) => (
{state.availableDigests.map((algorithm) => (
<option key={algorithm}>{algorithm}</option>
))}
</Form.Control>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@ import { useTranslation } from 'react-i18next';

import './TabEncryption.css';

const CIPHERS = [
'aes-128-cbc',
'aes-192-cbc',
'aes-256-cbc',
'aria-128-cbc',
'aria-192-cbc',
'aria-256-cbc',
'bf',
'cast-cbc',
'cast5-cbc',
'camellia-128-cbc',
'camellia-192-cbc',
'camellia-256-cbc',
'des',
'des-ede',
'des-ede3',
'des3',
'desx',
'rc2',
'rc4',
'seed',
'sm4',
];

function TabEncryption({ runCommand }) {
const { t } = useTranslation('translation');
const { state, dispatch } = useStore();
Expand All @@ -52,7 +28,7 @@ function TabEncryption({ runCommand }) {
const [enc, setEnc] = useState({
e: true,
d: false,
cipher: CIPHERS[0],
cipher: '',
in: false,
inFile: '',
out: false,
Expand Down Expand Up @@ -83,6 +59,15 @@ function TabEncryption({ runCommand }) {
});
}, [state.files]);

useEffect(() => {
setEnc((prev) => {
return {
...prev,
cipher: state.availableCiphers[0],
};
});
}, [state.availableCiphers]);

const set = (key) => (event) => {
const value =
event.target.type === 'checkbox' || event.target.type === 'radio'
Expand Down Expand Up @@ -320,7 +305,7 @@ function TabEncryption({ runCommand }) {
<Form.Group as={Col} md={5} controlId="enc-cipher">
<Form.Label className="mb-2">{t('tabEncryption.cipher')}</Form.Label>
<Form.Control as="select" value={enc.cipher} onChange={set('cipher')} custom>
{CIPHERS.map((cipher) => (
{state.availableCiphers.map((cipher) => (
<option key={cipher}>{cipher}</option>
))}
</Form.Control>
Expand Down
14 changes: 14 additions & 0 deletions src/contexts/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const initialState = {
isLoading: false,
command: '',
files: [],
availableCiphers: [],
availableDigests: [],
};

const reducer = (state, action) => {
Expand Down Expand Up @@ -45,6 +47,18 @@ const reducer = (state, action) => {
files: state.files.filter((item) => item !== action.item),
};

case 'SET_AVAILABLE_CIPHERS':
return {
...state,
availableCiphers: action.ciphers,
};

case 'SET_AVAILABLE_DIGEST':
return {
...state,
availableDigests: action.digests,
};

default:
throw new Error(`Unhandled action type: ${action.type}`);
}
Expand Down
Loading

0 comments on commit 67e283b

Please sign in to comment.