Skip to content

Commit b21e6a9

Browse files
crypto-helper:
* update yew dependencies; * add rustfmt.toml. format code; ci: * update trunk version; * move clippy to the 'check' job. add fmt step to it;
1 parent 8ad5ca3 commit b21e6a9

16 files changed

+92
-126
lines changed

.github/workflows/github-actions.yml

+22-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,30 @@ on:
77
branches:
88
- 'main'
99
jobs:
10+
check:
11+
name: Check code
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: 'Add nightly channel'
19+
run: 'rustup toolchain install nightly'
20+
21+
- name: 'Add nightly fmt'
22+
run: 'rustup component add rustfmt --toolchain nightly-x86_64-unknown-linux-gnu'
23+
24+
- name: 'Fmt'
25+
run: 'cargo +nightly fmt --all -- --check'
26+
27+
- name: 'Clippy'
28+
run: 'cargo clippy -- -D warnings'
29+
1030
deploy:
1131
name: Deploy
1232
runs-on: ubuntu-latest
33+
needs: check
1334

1435
permissions:
1536
contents: 'read'
@@ -20,10 +41,7 @@ jobs:
2041
uses: actions/checkout@v3
2142

2243
- name: 'Trunk Check'
23-
uses: jetli/[email protected]
24-
25-
- name: 'Clippy'
26-
run: 'cargo clippy -- -D warnings'
44+
uses: jetli/[email protected]
2745

2846
- id: 'auth'
2947
name: 'Authenticate to Google Cloud'

Cargo.lock

+12-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ license-file = "LICENSE"
99
repository = "https://github.com/TheBestTvarynka/crypto-helper"
1010

1111
[dependencies]
12-
yew = { git = "https://github.com/yewstack/yew.git", rev = "5355b65ff5f9747cbad801d4b337a5ac7a94d0f4", features = ["csr"] }
13-
yew-router = { git = "https://github.com/yewstack/yew.git", rev = "5355b65ff5f9747cbad801d4b337a5ac7a94d0f4" }
12+
yew = { version = "0.20", features = ["csr"] }
13+
yew-router = "0.17.0"
1414

1515
# wasm
1616
js-sys = "0.3.60"

rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
max_width = 120
2+
reorder_imports = true
3+
imports_granularity = "Module"
4+
group_imports = "StdExternalCrate"

src/crypto_helper.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,21 @@ mod input;
55
mod output;
66

77
pub use algorithm::RSA_HASH_ALGOS;
8-
98
use gloo_timers::callback::Timeout;
9+
use info::Info;
10+
use input::Input;
11+
use output::Output;
1012
use picky_krb::crypto::{ChecksumSuite, CipherSuite};
1113
use sha1::{Digest, Sha1};
1214
use uuid::Uuid;
1315
use yew::{classes, function_component, html, use_effect_with_deps, use_state, Callback, Html};
1416

15-
use info::Info;
16-
use input::Input;
17-
use output::Output;
18-
17+
use self::algorithm::Algorithm;
18+
use self::computations::{process_krb_cipher, process_krb_hmac, process_rsa};
1919
use crate::notification::{
2020
get_new_notifications, Notification, NotificationType, Notifications, NOTIFICATION_DURATION,
2121
};
2222

23-
use self::{
24-
algorithm::Algorithm,
25-
computations::{process_krb_cipher, process_krb_hmac, process_rsa},
26-
};
27-
2823
fn from_hex(input: &str) -> Result<Vec<u8>, String> {
2924
hex::decode(input).map_err(|err| format!("invalid hex input:{:?}", err))
3025
}
@@ -38,19 +33,11 @@ fn convert(algrithm: &Algorithm) -> Result<Vec<u8>, String> {
3833
Ok(sha1.finalize().to_vec())
3934
}
4035
Algorithm::Sha256(input) => Ok(hmac_sha256::Hash::hash(&from_hex(input)?).to_vec()),
41-
Algorithm::Sha512(input) => Ok(hmac_sha512::Hash::hash(&from_hex(input)?).to_vec()),
42-
Algorithm::Aes128CtsHmacSha196(input) => {
43-
process_krb_cipher(CipherSuite::Aes128CtsHmacSha196.cipher(), input)
44-
}
45-
Algorithm::Aes256CtsHmacSha196(input) => {
46-
process_krb_cipher(CipherSuite::Aes256CtsHmacSha196.cipher(), input)
47-
}
48-
Algorithm::HmacSha196Aes128(input) => {
49-
process_krb_hmac(ChecksumSuite::HmacSha196Aes128.hasher(), input)
50-
}
51-
Algorithm::HmacSha196Aes256(input) => {
52-
process_krb_hmac(ChecksumSuite::HmacSha196Aes256.hasher(), input)
53-
}
36+
Algorithm::Sha512(input) => Ok(hmac_sha512::Hash::hash(from_hex(input)?).to_vec()),
37+
Algorithm::Aes128CtsHmacSha196(input) => process_krb_cipher(CipherSuite::Aes128CtsHmacSha196.cipher(), input),
38+
Algorithm::Aes256CtsHmacSha196(input) => process_krb_cipher(CipherSuite::Aes256CtsHmacSha196.cipher(), input),
39+
Algorithm::HmacSha196Aes128(input) => process_krb_hmac(ChecksumSuite::HmacSha196Aes128.hasher(), input),
40+
Algorithm::HmacSha196Aes256(input) => process_krb_hmac(ChecksumSuite::HmacSha196Aes256.hasher(), input),
5441
Algorithm::Rsa(input) => process_rsa(input),
5542
}
5643
}

src/crypto_helper/computations.rs

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
use picky::{
2-
key::{PrivateKey, PublicKey},
3-
signature::SignatureAlgorithm,
4-
};
1+
use picky::key::{PrivateKey, PublicKey};
2+
use picky::signature::SignatureAlgorithm;
53
use picky_krb::crypto::{Checksum, Cipher};
64
use rand::SeedableRng;
75
use rand_chacha::ChaCha8Rng;
8-
use rsa::{
9-
pkcs1::{DecodeRsaPrivateKey, DecodeRsaPublicKey},
10-
PaddingScheme, PublicKey as PublicKeyTrait, RsaPrivateKey, RsaPublicKey,
11-
};
6+
use rsa::pkcs1::{DecodeRsaPrivateKey, DecodeRsaPublicKey};
7+
use rsa::{PaddingScheme, PublicKey as PublicKeyTrait, RsaPrivateKey, RsaPublicKey};
128

13-
use super::{
14-
algorithm::{KrbInput, KrbInputData, RsaAction, RsaInput},
15-
from_hex,
16-
};
9+
use super::algorithm::{KrbInput, KrbInputData, RsaAction, RsaInput};
10+
use super::from_hex;
1711

1812
pub fn process_rsa(input: &RsaInput) -> Result<Vec<u8>, String> {
1913
let payload = from_hex(&input.payload)?;
@@ -26,23 +20,20 @@ pub fn process_rsa(input: &RsaInput) -> Result<Vec<u8>, String> {
2620
.map_err(|err| err.to_string())
2721
}
2822
RsaAction::Decrypt(input) => {
29-
let private_key =
30-
RsaPrivateKey::from_pkcs1_pem(input).map_err(|err| err.to_string())?;
23+
let private_key = RsaPrivateKey::from_pkcs1_pem(input).map_err(|err| err.to_string())?;
3124
private_key
3225
.decrypt(PaddingScheme::PKCS1v15Encrypt, &payload)
3326
.map_err(|err| err.to_string())
3427
}
3528
RsaAction::Sign(input) => {
36-
let private_key =
37-
PrivateKey::from_pem_str(&input.rsa_key).map_err(|err| err.to_string())?;
29+
let private_key = PrivateKey::from_pem_str(&input.rsa_key).map_err(|err| err.to_string())?;
3830
Ok(SignatureAlgorithm::RsaPkcs1v15(input.hash_algorithm.0)
3931
.sign(&payload, &private_key)
4032
.map_err(|err| err.to_string())?)
4133
}
4234
RsaAction::Verify(input) => {
4335
let signature = from_hex(&input.signature)?;
44-
let public_key =
45-
PublicKey::from_pem_str(&input.rsa_key).map_err(|err| err.to_string())?;
36+
let public_key = PublicKey::from_pem_str(&input.rsa_key).map_err(|err| err.to_string())?;
4637
SignatureAlgorithm::RsaPkcs1v15(input.hash_algorithm.0)
4738
.verify(&public_key, &payload, &signature)
4839
.map(|_| vec![1])
@@ -79,10 +70,7 @@ pub fn process_krb_cipher(cipher: Box<dyn Cipher>, input: &KrbInput) -> Result<V
7970
}
8071
}
8172

82-
pub fn process_krb_hmac(
83-
hasher: Box<dyn Checksum>,
84-
input: &KrbInputData,
85-
) -> Result<Vec<u8>, String> {
73+
pub fn process_krb_hmac(hasher: Box<dyn Checksum>, input: &KrbInputData) -> Result<Vec<u8>, String> {
8674
hasher
8775
.checksum(
8876
&from_hex(&input.key).map_err(|err| format!("key: {}", err))?,

src/crypto_helper/info.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
mod algo_search;
22

33
use web_sys::HtmlInputElement;
4-
use yew::{
5-
classes, function_component, html, html::onchange::Event, use_state, Callback, Html,
6-
Properties, TargetCast, UseStateSetter,
7-
};
8-
9-
use crate::crypto_helper::info::algo_search::AlgoSearch;
4+
use yew::html::onchange::Event;
5+
use yew::{classes, function_component, html, use_state, Callback, Html, Properties, TargetCast, UseStateSetter};
106

117
use super::algorithm::{Algorithm, SUPPORTED_ALGORITHMS};
8+
use crate::crypto_helper::info::algo_search::AlgoSearch;
129

1310
#[derive(PartialEq, Properties)]
1411
pub struct InfoProps {

src/crypto_helper/info/algo_search.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use web_sys::{Event, FocusEvent, HtmlInputElement, InputEvent, KeyboardEvent, MouseEvent};
22
use yew::{
3-
classes, function_component, html, use_effect_with_deps, use_state, Callback, Html, Properties,
4-
TargetCast, UseStateSetter,
3+
classes, function_component, html, use_effect_with_deps, use_state, Callback, Html, Properties, TargetCast,
4+
UseStateSetter,
55
};
66

77
use crate::crypto_helper::algorithm::{Algorithm, SUPPORTED_ALGORITHMS};

src/crypto_helper/input.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ mod simple;
55
use picky_krb::crypto::CipherSuite;
66
use yew::{classes, function_component, html, Callback, Html, Properties, UseStateSetter};
77

8-
use self::{krb::build_krb_input, rsa::build_rsa_input, simple::build_simple_input};
9-
10-
use super::{algorithm::KrbInput, Algorithm};
8+
use self::krb::build_krb_input;
9+
use self::rsa::build_rsa_input;
10+
use self::simple::build_simple_input;
11+
use super::algorithm::KrbInput;
12+
use super::Algorithm;
1113

1214
fn get_input_components(algorithm: &Algorithm, setter: &UseStateSetter<Algorithm>) -> Html {
1315
let setter = setter.clone();
@@ -30,17 +32,13 @@ fn get_input_components(algorithm: &Algorithm, setter: &UseStateSetter<Algorithm
3032
),
3133
Algorithm::Aes128CtsHmacSha196(kerberos_input) => build_krb_input(
3234
kerberos_input.clone(),
33-
Callback::from(move |kerberos_input| {
34-
setter.set(Algorithm::Aes128CtsHmacSha196(kerberos_input))
35-
}),
35+
Callback::from(move |kerberos_input| setter.set(Algorithm::Aes128CtsHmacSha196(kerberos_input))),
3636
CipherSuite::Aes128CtsHmacSha196,
3737
true,
3838
),
3939
Algorithm::Aes256CtsHmacSha196(kerberos_input) => build_krb_input(
4040
kerberos_input.clone(),
41-
Callback::from(move |kerberos_input| {
42-
setter.set(Algorithm::Aes256CtsHmacSha196(kerberos_input))
43-
}),
41+
Callback::from(move |kerberos_input| setter.set(Algorithm::Aes256CtsHmacSha196(kerberos_input))),
4442
CipherSuite::Aes256CtsHmacSha196,
4543
true,
4644
),

src/crypto_helper/input/krb.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use picky_krb::crypto::CipherSuite;
22
use web_sys::{HtmlInputElement, InputEvent, MouseEvent};
33
use yew::{
4-
classes, function_component, html, use_effect, use_state, Callback, Html, Properties,
5-
TargetCast, UseStateSetter,
4+
classes, function_component, html, use_effect, use_state, Callback, Html, Properties, TargetCast, UseStateSetter,
65
};
76

87
use crate::common::Switch;

src/crypto_helper/input/rsa.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use web_sys::{Event, HtmlInputElement};
22
use yew::{classes, function_component, html, Callback, Classes, Html, Properties, TargetCast};
33

44
use crate::crypto_helper::algorithm::{
5-
RsaAction, RsaHashAlgorithm, RsaInput as RsaInputData, RsaSignInput, RsaVerifyInput,
6-
RSA_HASH_ALGOS,
5+
RsaAction, RsaHashAlgorithm, RsaInput as RsaInputData, RsaSignInput, RsaVerifyInput, RSA_HASH_ALGOS,
76
};
87

98
#[derive(Debug, PartialEq, Properties)]
@@ -20,10 +19,7 @@ fn get_action_classes(is_selected: bool) -> Classes {
2019
}
2120
}
2221

23-
fn generate_selection_action_component(
24-
action: &RsaAction,
25-
set_action: Callback<RsaAction>,
26-
) -> Html {
22+
fn generate_selection_action_component(action: &RsaAction, set_action: Callback<RsaAction>) -> Html {
2723
html! {
2824
<div class={classes!("rsa-actions-container")}>
2925
{RsaAction::enumerate_actions()
@@ -44,10 +40,7 @@ fn generate_selection_action_component(
4440
}
4541
}
4642

47-
fn get_hash_selection_component(
48-
hash_algorithm: &RsaHashAlgorithm,
49-
set_hash_algo: Callback<RsaHashAlgorithm>,
50-
) -> Html {
43+
fn get_hash_selection_component(hash_algorithm: &RsaHashAlgorithm, set_hash_algo: Callback<RsaHashAlgorithm>) -> Html {
5144
let onchange = Callback::from(move |event: Event| {
5245
let input: HtmlInputElement = event.target_unchecked_into();
5346

@@ -77,8 +70,7 @@ fn get_hash_selection_component(
7770
}
7871

7972
fn generate_rsa_input(input: &RsaAction, set_action: Callback<RsaAction>) -> Html {
80-
let selected_algorithm_component =
81-
generate_selection_action_component(input, set_action.clone());
73+
let selected_algorithm_component = generate_selection_action_component(input, set_action.clone());
8274
match input {
8375
RsaAction::Encrypt(input) => {
8476
let oninput = Callback::from(move |event: html::oninput::Event| {

src/crypto_helper/output.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,19 @@ mod simple;
33

44
use yew::{classes, function_component, html, Callback, Html, Properties};
55

6-
use crate::notification::Notification;
7-
8-
use self::{krb::build_krb_output, simple::build_simple_output};
9-
6+
use self::krb::build_krb_output;
7+
use self::simple::build_simple_output;
108
use super::Algorithm;
9+
use crate::notification::Notification;
1110

12-
fn get_output_components(
13-
algorithm: &Algorithm,
14-
output: &[u8],
15-
add_notification: &Callback<Notification>,
16-
) -> Html {
11+
fn get_output_components(algorithm: &Algorithm, output: &[u8], add_notification: &Callback<Notification>) -> Html {
1712
match algorithm {
1813
Algorithm::Md5(_) => build_simple_output(output, add_notification.clone()),
1914
Algorithm::Sha1(_) => build_simple_output(output, add_notification.clone()),
2015
Algorithm::Sha256(_) => build_simple_output(output, add_notification.clone()),
2116
Algorithm::Sha512(_) => build_simple_output(output, add_notification.clone()),
22-
Algorithm::Aes128CtsHmacSha196(input) => {
23-
build_krb_output(input, output, add_notification.clone())
24-
}
25-
Algorithm::Aes256CtsHmacSha196(input) => {
26-
build_krb_output(input, output, add_notification.clone())
27-
}
17+
Algorithm::Aes128CtsHmacSha196(input) => build_krb_output(input, output, add_notification.clone()),
18+
Algorithm::Aes256CtsHmacSha196(input) => build_krb_output(input, output, add_notification.clone()),
2819
Algorithm::HmacSha196Aes128(_) => build_simple_output(output, add_notification.clone()),
2920
Algorithm::HmacSha196Aes256(_) => build_simple_output(output, add_notification.clone()),
3021
Algorithm::Rsa(_) => build_simple_output(output, add_notification.clone()),

0 commit comments

Comments
 (0)