Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dup-crypto-rs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This project is archived. Its data is
read-only
.
Show more breadcrumbs
libs
dup-crypto-rs
Merge requests
!3
Elois/rand
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Elois/rand
elois/rand
into
dev
Overview
0
Commits
3
Pipelines
1
Changes
7
Merged
Elois/rand
Éloïs
requested to merge
elois/rand
into
dev
Feb 21, 2020
Overview
0
Commits
3
Pipelines
1
Changes
7
0
0
Merge request reports
Compare
dev
dev (base)
and
latest version
latest version
aa3213a5
3 commits,
Feb 21, 2020
7 files
+
74
−
15
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
src/hashs/mod.rs
+
6
−
4
View file @ aa3213a5
Edit in single-file editor
Open in Web IDE
Show full file
@@ -16,8 +16,9 @@
//! Provide wrappers for cryptographic hashs
use
crate
::
bases
::
*
;
#[cfg(feature
=
"rand"
)]
use
crate
::
rand
::
UnspecifiedRandError
;
use
ring
::
{
digest
,
rand
}
;
use
ring
::
digest
;
#[cfg(feature
=
"ser"
)]
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
fmt
::{
Debug
,
Display
,
Error
,
Formatter
};
@@ -57,12 +58,12 @@ impl Hash {
/// Hash size (in bytes).
pub
const
SIZE_IN_BYTES
:
usize
=
32
;
#[cfg(feature
=
"rand"
)]
/// Generate a random Hash
#[inline]
pub
fn
random
()
->
Result
<
Self
,
UnspecifiedRandError
>
{
let
random_bytes
=
rand
::
generate
::
<
[
u8
;
32
]
>
(
&
rand
::
SystemRandom
::
new
())
.map_err
(|
_
|
UnspecifiedRandError
)
?
;
Ok
(
Hash
(
random_bytes
.expose
()))
let
random_bytes
=
crate
::
rand
::
gen_32_bytes
()
.map_err
(|
_
|
UnspecifiedRandError
)
?
;
Ok
(
Hash
(
random_bytes
))
}
/// Compute hash of any binary datas
@@ -103,6 +104,7 @@ mod tests {
use
super
::
*
;
#[cfg(feature
=
"rand"
)]
#[test]
fn
test_hash_random
()
{
let
hash1
=
Hash
::
random
();
Loading