Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to sha1_smol and modernize #40

Merged
merged 10 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [mitsuhiko]
18 changes: 18 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Clippy

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Run clippy
run: cargo clippy
18 changes: 18 additions & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Rustfmt

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Run rustfmt
run: cargo fmt --check
32 changes: 32 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on: [push]

jobs:
test-latest:
name: Test on Latest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Test
run: cargo test

build-stable:
name: Build on 1.31.0
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.31.0
profile: minimal
override: true
- name: Build
run: cargo check
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "sha1"
name = "sha1_smol"
version = "0.6.0"
authors = ["Armin Ronacher <[email protected]>"]
keywords = ["sha1"]
description = "Minimal implementation of SHA1 for Rust."
description = "Minimal dependency free implementation of SHA1 for Rust."
license = "BSD-3-Clause"
repository = "https://github.com/mitsuhiko/rust-sha1"
repository = "https://github.com/mitsuhiko/sha1-smol"
edition = "2018"

[features]
std = []
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
# rust-sha1
# sha1-smol

Minimal implementation of SHA1 for Rust.
[![Build Status](https://github.com/mitsuhiko/sha1-smol/workflows/Tests/badge.svg?branch=master)](https://github.com/mitsuhiko/sha1-smol/actions?query=workflow%3ATests)
[![Crates.io](https://img.shields.io/crates/d/sha1-smol.svg)](https://crates.io/crates/sha1-smol)
[![License](https://img.shields.io/github/license/mitsuhiko/sha1-smol)](https://github.com/mitsuhiko/sha1-smol/blob/master/LICENSE)
[![rustc 1.31.0](https://img.shields.io/badge/rust-1.31%2B-orange.svg)](https://img.shields.io/badge/rust-1.31%2B-orange.svg)
[![Documentation](https://docs.rs/sha1-smol/badge.svg)](https://docs.rs/sha1-smol)

Right now SHA1 is quite frequently used and many things want to have an
implementation of it, that does not pull in too much other stuff.
Minimal and dependency free implementation of SHA1 for Rust.

SHA1 is not exactly a good choice for crypto hashes these days but unfortunately
SHA1 continues to be needed for a handful of situations due to legacy functionality.
If you have the need for a SHA1 implementation that does not pull in large dependency chains
you might want to consider this crate.

In all other cases use the new [`sha1`](https://crates.io/crates/sha1) crate
by the RustCrypto project instead.

## sha1 crate

This crate used to be published as `sha1` but in recent years a large ecosystem
of hash libraries was built around [`RustCrypto`](https://github.com/RustCrypto)
so the crate name was given to that project instead. Versions newer than `0.6`
of `sha1`.

This is largely based on the hash code in crypto-rs by Koka El Kiwi.

## License and Links

- [Documentation](https://docs.rs/sha1-smol/)
- [Issue Tracker](https://github.com/mitsuhiko/sha1-smol/issues)
- License: [3 Clause BDS](https://github.com/mitsuhiko/sha1-smol/blob/master/LICENSE)
65 changes: 36 additions & 29 deletions bench/bench.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
extern crate sha1;
extern crate ring;
extern crate sha1_smol as sha1;

use std::env;
use std::fs;
use std::io::{Read, Write};
use std::time::{Instant, Duration};
use std::process::{Command, Stdio};
use std::time::{Duration, Instant};

fn time<F, FMT>(desc: &str, f: F, fmt: FMT)
where F: Fn(),
FMT: Fn(Duration) -> String
where
F: Fn(),
FMT: Fn(Duration) -> String,
{
let start = Instant::now();
f();
Expand Down Expand Up @@ -37,32 +38,38 @@ fn main() {
};

if env::var("WITHOUT_SHA1SUM") != Ok("1".into()) {
time("sha1sum program",
|| {
let mut child = Command::new("sha1sum")
.stdin(Stdio::piped())
.spawn()
.unwrap();
if let Some(ref mut stdin) = child.stdin {
stdin.write(&out).unwrap();
}
child.wait().unwrap();
},
&throughput);
time(
"sha1sum program",
|| {
let mut child = Command::new("sha1sum")
.stdin(Stdio::piped())
.spawn()
.unwrap();
if let Some(ref mut stdin) = child.stdin {
stdin.write(&out).unwrap();
}
child.wait().unwrap();
},
&throughput,
);
}

time("sha1 crate",
|| {
let mut sha1 = sha1::Sha1::new();
sha1.update(&out);
println!("{}", sha1.digest());
},
&throughput);
time(
"sha1 crate",
|| {
let mut sha1 = sha1::Sha1::new();
sha1.update(&out);
println!("{}", sha1.digest());
},
&throughput,
);

time("ring crate",
|| {
let digest = ring::digest::digest(&ring::digest::SHA1, &out);
println!("{:?}", digest);
},
&throughput);
time(
"ring crate",
|| {
let digest = ring::digest::digest(&ring::digest::SHA1, &out);
println!("{:?}", digest);
},
&throughput,
);
}
1 change: 0 additions & 1 deletion rustfmt.toml

This file was deleted.

Loading