Add the git pre-commit hook

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2023-06-09 21:02:42 +02:00
parent e2874451d1
commit a32dfe098f
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
3 changed files with 32 additions and 13 deletions

View File

@ -15,3 +15,27 @@ you will find the result in `./target/release`
If you want to build the `Hati` server, you don't need to build this library If you want to build the `Hati` server, you don't need to build this library
separately. Just build the server and it will automatically include this lib separately. Just build the server and it will automatically include this lib
# Developing
we recommend to use the nix environment, so that you will have
exactly the same environment as the developers.
just enter the repository directory and run
```
nix develop
```
and everything should be done for you.
## Git
Please configure a pre-commit hook like the one in `var/git-pre-commit`
```
cp var/git-pre-commit .git/hooks/pre-commit
```
This will run `cargo test --offline` right before your commit,
to make sure that everything compiles and that the test pass

View File

@ -8,11 +8,7 @@ use crate::{
fn test_handshake_dirsync_req() { fn test_handshake_dirsync_req() {
let rand = enc::Random::new(); let rand = enc::Random::new();
let secret = enc::Secret::new_rand(&rand); let secret = enc::Secret::new_rand(&rand);
let cipher_send = enc::sym::CipherSend::new( let cipher = enc::sym::CipherKind::XChaCha20Poly1305;
enc::sym::CipherKind::XChaCha20Poly1305,
secret,
&rand,
);
let (_, exchange_key) = let (_, exchange_key) =
match enc::asym::KeyExchangeKind::X25519DiffieHellman.new_keypair(&rand) match enc::asym::KeyExchangeKind::X25519DiffieHellman.new_keypair(&rand)
@ -49,11 +45,7 @@ fn test_handshake_dirsync_req() {
let mut bytes = Vec::<u8>::with_capacity(h_req.len()); let mut bytes = Vec::<u8>::with_capacity(h_req.len());
bytes.resize(h_req.len(), 0); bytes.resize(h_req.len(), 0);
h_req.serialize( h_req.serialize(cipher.nonce_len(), cipher.tag_len(), &mut bytes);
cipher_send.kind().nonce_len(),
cipher_send.kind().tag_len(),
&mut bytes,
);
let mut deserialized = match Handshake::deserialize(&bytes) { let mut deserialized = match Handshake::deserialize(&bytes) {
Ok(deserialized) => deserialized, Ok(deserialized) => deserialized,
@ -65,10 +57,9 @@ fn test_handshake_dirsync_req() {
if let HandshakeData::DirSync(dirsync::DirSync::Req(r_a)) = if let HandshakeData::DirSync(dirsync::DirSync::Req(r_a)) =
&mut deserialized.data &mut deserialized.data
{ {
let enc_start = let enc_start = r_a.encrypted_offset() + cipher.nonce_len().0;
r_a.encrypted_offset() + cipher_send.kind().nonce_len().0;
if let Err(e) = r_a.data.deserialize_as_cleartext( if let Err(e) = r_a.data.deserialize_as_cleartext(
&bytes[enc_start..(bytes.len() - cipher_send.kind().tag_len().0)], &bytes[enc_start..(bytes.len() - cipher.tag_len().0)],
) { ) {
assert!(false, "DirSync Req Inner serialize: {}", e.to_string()); assert!(false, "DirSync Req Inner serialize: {}", e.to_string());
} }

4
var/git-pre-commit Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
RUSTFLAGS=-Awarnings exec cargo test --offline --profile dev