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

[pull] master from mitsuhiko:master #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Armin Ronacher
- Koka El Kiwi
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[package]
name = "sha1"
version = "0.6.0"
name = "sha1_smol"
version = "1.0.1"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
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 = []
std = ["alloc"]
alloc = []

[dependencies]
serde = { version = "1.0", optional = true }
Expand Down
85 changes: 56 additions & 29 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
Copyright (c) 2014 by Armin Ronacher.
BSD 3-Clause License

Copyright (c) 2013 Koka El Kiwi

Some rights reserved.
Copyright (c) 2018, the respective contributors, as shown by the AUTHORS file.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* The names of the contributors may not be used to endorse or
promote products derived from this software without specific
prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-----

src/simd.rs is licensed under the MIT license:

Copyright (c) 2006-2009 Graydon Hoare
Copyright (c) 2009-2013 Mozilla Foundation

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
# rust-sha1
# sha1-smol

Minimal implementation of SHA1 for Rust.
[![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 BSD](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,
);
}
2 changes: 2 additions & 0 deletions legacy-shim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/Cargo.lock
25 changes: 25 additions & 0 deletions legacy-shim/Cargo.lock

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

19 changes: 19 additions & 0 deletions legacy-shim/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "sha1"
version = "0.6.1"
authors = ["Armin Ronacher <armin.ronacher@active-4.com>"]
keywords = ["sha1"]
description = "Minimal dependency free implementation of SHA1 for Rust."
license = "BSD-3-Clause"
repository = "https://github.com/mitsuhiko/sha1-smol"
edition = "2018"

[features]
std = ["sha1_smol/std"]
serde = ["sha1_smol/serde"]

[dependencies]
sha1_smol = "1.0.0"

[package.metadata.docs.rs]
all-features = true
1 change: 1 addition & 0 deletions legacy-shim/LICENSE
1 change: 1 addition & 0 deletions legacy-shim/README.md
Loading