Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
briar
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
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julian Dehm
briar
Commits
25a4caec
Verified
Commit
25a4caec
authored
8 years ago
by
Torsten Grote
Browse files
Options
Downloads
Patches
Plain Diff
Add Unit tests for CryptoComponent#hash()
parent
1081a08e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bramble-core/src/test/java/org/briarproject/bramble/crypto/HashTest.java
+50
-0
50 additions, 0 deletions
...c/test/java/org/briarproject/bramble/crypto/HashTest.java
with
50 additions
and
0 deletions
bramble-core/src/test/java/org/briarproject/bramble/crypto/HashTest.java
0 → 100644
+
50
−
0
View file @
25a4caec
package
org.briarproject.bramble.crypto
;
import
org.briarproject.bramble.BrambleTestCase
;
import
org.briarproject.bramble.TestSeedProvider
;
import
org.briarproject.bramble.TestUtils
;
import
org.briarproject.bramble.api.crypto.CryptoComponent
;
import
org.junit.Test
;
import
java.util.Arrays
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
public
class
HashTest
extends
BrambleTestCase
{
private
final
CryptoComponent
crypto
;
private
final
String
label
=
TestUtils
.
getRandomString
(
42
);
private
final
byte
[]
inputBytes
=
TestUtils
.
getRandomBytes
(
123
);
private
final
byte
[]
inputBytes1
=
TestUtils
.
getRandomBytes
(
234
);
private
final
byte
[]
inputBytes2
=
new
byte
[
0
];
public
HashTest
()
{
crypto
=
new
CryptoComponentImpl
(
new
TestSeedProvider
());
}
@Test
public
void
testIdenticalInputsProduceIdenticalHashes
()
{
byte
[]
hash1
=
crypto
.
hash
(
label
,
inputBytes
,
inputBytes1
,
inputBytes2
);
byte
[]
hash2
=
crypto
.
hash
(
label
,
inputBytes
,
inputBytes1
,
inputBytes2
);
assertArrayEquals
(
hash1
,
hash2
);
}
@Test
public
void
testDifferentInputsProduceDifferentHashes
()
{
byte
[]
hash1
=
crypto
.
hash
(
label
,
inputBytes
,
inputBytes1
,
inputBytes2
);
byte
[]
hash2
=
crypto
.
hash
(
label
,
inputBytes2
,
inputBytes1
,
inputBytes
);
assertFalse
(
Arrays
.
equals
(
hash1
,
hash2
));
}
@Test
public
void
testDifferentLabelsProduceDifferentHashes
()
{
String
label2
=
TestUtils
.
getRandomString
(
42
);
byte
[]
hash1
=
crypto
.
hash
(
label
,
inputBytes
,
inputBytes1
,
inputBytes2
);
byte
[]
hash2
=
crypto
.
hash
(
label2
,
inputBytes
,
inputBytes1
,
inputBytes2
);
assertFalse
(
Arrays
.
equals
(
hash1
,
hash2
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment