(feat): rename example-usage to just example
Some checks failed
CI / rustfmt (push) Successful in 17s
CI / clippy (push) Failing after 1m16s
CI / wasm build (push) Successful in 1m17s
CI / example (push) Successful in 1m29s
CI / test (push) Successful in 1m49s
CI / duplicate code (push) Successful in 12s
CI / web client (push) Failing after 27s
CI / cargo-machete (push) Successful in 1m10s
CI / cargo-deny (push) Failing after 2m20s

(feat): add the example's web-client dist folder to a gitignore
(fix): format issues
(fix): a lot of duplicate code
This commit is contained in:
Alois 2026-06-27 03:20:25 +02:00
commit 89a20044a5
43 changed files with 528 additions and 1619 deletions

View file

@ -18,6 +18,14 @@ pub trait AeadCipher: AeadEncrypt + AeadDecrypt {
fn key_size() -> usize;
}
#[cfg(any(feature = "chacha20poly1305", feature = "aes-gcm"))]
fn prepend_nonce(nonce: &[u8], ciphertext: &mut Vec<u8>) -> Vec<u8> {
let mut out = Vec::with_capacity(nonce.len() + ciphertext.len());
out.extend_from_slice(nonce);
out.append(ciphertext);
out
}
#[cfg(feature = "chacha20poly1305")]
pub struct ChaCha20Poly1305 {
key: [u8; 32],
@ -53,10 +61,7 @@ impl AeadEncrypt for ChaCha20Poly1305 {
.encrypt(nonce_ref, payload)
.map_err(|_| CryptoError::EncryptionFailed)?;
let mut out = Vec::with_capacity(nonce.len() + ciphertext.len());
out.extend_from_slice(&nonce);
out.append(&mut ciphertext);
Ok(out)
Ok(prepend_nonce(&nonce, &mut ciphertext))
}
}
@ -126,10 +131,7 @@ impl AeadEncrypt for Aes256Gcm {
.encrypt(nonce_ref, payload)
.map_err(|_| CryptoError::EncryptionFailed)?;
let mut out = Vec::with_capacity(nonce.len() + ciphertext.len());
out.extend_from_slice(&nonce);
out.append(&mut ciphertext);
Ok(out)
Ok(prepend_nonce(&nonce, &mut ciphertext))
}
}