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 is an archived project. Repository and other project resources are 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
Éloïs
requested to merge
elois/rand
into
dev
5 years ago
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,
5 years ago
7 files
+
74
−
15
Side-by-side
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 @@
@@ -16,8 +16,9 @@
//! Provide wrappers for cryptographic hashs
//! Provide wrappers for cryptographic hashs
use
crate
::
bases
::
*
;
use
crate
::
bases
::
*
;
#[cfg(feature
=
"rand"
)]
use
crate
::
rand
::
UnspecifiedRandError
;
use
crate
::
rand
::
UnspecifiedRandError
;
use
ring
::
{
digest
,
rand
}
;
use
ring
::
digest
;
#[cfg(feature
=
"ser"
)]
#[cfg(feature
=
"ser"
)]
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
std
::
fmt
::{
Debug
,
Display
,
Error
,
Formatter
};
use
std
::
fmt
::{
Debug
,
Display
,
Error
,
Formatter
};
@@ -57,12 +58,12 @@ impl Hash {
@@ -57,12 +58,12 @@ impl Hash {
/// Hash size (in bytes).
/// Hash size (in bytes).
pub
const
SIZE_IN_BYTES
:
usize
=
32
;
pub
const
SIZE_IN_BYTES
:
usize
=
32
;
#[cfg(feature
=
"rand"
)]
/// Generate a random Hash
/// Generate a random Hash
#[inline]
#[inline]
pub
fn
random
()
->
Result
<
Self
,
UnspecifiedRandError
>
{
pub
fn
random
()
->
Result
<
Self
,
UnspecifiedRandError
>
{
let
random_bytes
=
rand
::
generate
::
<
[
u8
;
32
]
>
(
&
rand
::
SystemRandom
::
new
())
let
random_bytes
=
crate
::
rand
::
gen_32_bytes
()
.map_err
(|
_
|
UnspecifiedRandError
)
?
;
.map_err
(|
_
|
UnspecifiedRandError
)
?
;
Ok
(
Hash
(
random_bytes
))
Ok
(
Hash
(
random_bytes
.expose
()))
}
}
/// Compute hash of any binary datas
/// Compute hash of any binary datas
@@ -103,6 +104,7 @@ mod tests {
@@ -103,6 +104,7 @@ mod tests {
use
super
::
*
;
use
super
::
*
;
#[cfg(feature
=
"rand"
)]
#[test]
#[test]
fn
test_hash_random
()
{
fn
test_hash_random
()
{
let
hash1
=
Hash
::
random
();
let
hash1
=
Hash
::
random
();
Loading