-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
405d961
commit 44e741a
Showing
3 changed files
with
122 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../java/com/example/beacon/vdf/application/combination/CombinationUncornCumulativeHash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.beacon.vdf.application.combination; | ||
|
||
import br.gov.inmetro.beacon.library.ciphersuite.suite0.ICipherSuite; | ||
import com.example.beacon.vdf.application.combination.dto.SeedUnicordCombinationVo; | ||
import com.example.beacon.vdf.sources.SeedSourceDto; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CombinationUncornCumulativeHash { | ||
|
||
private List<SeedUnicordCombinationVo> seedUnicordCombinationVos = new ArrayList<>(); | ||
|
||
public List<SeedUnicordCombinationVo> calcSeedConcat(ICipherSuite cipherSuite, List<SeedSourceDto> seedList) { | ||
|
||
String currentValue = ""; | ||
List<SeedUnicordCombinationVo> out = new ArrayList<>(); | ||
|
||
for (int i = 0; i < seedList.size(); i++) { | ||
SeedSourceDto dto = seedList.get(i); | ||
|
||
if (i == 0){ | ||
currentValue = cipherSuite.getDigest(seedList.get(0).getSeed()); | ||
} else { | ||
String teste = currentValue + dto.getSeed(); | ||
currentValue = cipherSuite.getDigest(teste); | ||
} | ||
|
||
String cumulativeDigest = currentValue; | ||
ZonedDateTime parse = ZonedDateTime.parse(dto.getTimeStamp(), DateTimeFormatter.ISO_DATE_TIME); | ||
out.add(new SeedUnicordCombinationVo(dto.getUri(), dto.getSeed(), dto.getDescription(), cumulativeDigest, parse)); | ||
} | ||
|
||
return out; | ||
} | ||
|
||
} | ||
|
80 changes: 80 additions & 0 deletions
80
...a/com/example/beacon/vdf/application/combination/CombinationUncornCumulativeHashTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.example.beacon.vdf.application.combination; | ||
|
||
import br.gov.inmetro.beacon.library.ciphersuite.suite0.CipherSuiteBuilder; | ||
import com.example.beacon.vdf.application.combination.dto.SeedUnicordCombinationVo; | ||
import com.example.beacon.vdf.infra.util.DateUtil; | ||
import com.example.beacon.vdf.sources.SeedSourceDto; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CombinationUncornCumulativeHashTest { | ||
|
||
@Test | ||
public void testOneSeed(){ | ||
List<SeedSourceDto> seeds = new ArrayList<>(); | ||
|
||
SeedSourceDto seedSourceDto1 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed1Test", "aDescription", null); | ||
|
||
seeds.add(seedSourceDto1); | ||
|
||
CombinationUncornCumulativeHash combinationUncornCumulativeHash = new CombinationUncornCumulativeHash(); | ||
List<SeedUnicordCombinationVo> resultList = combinationUncornCumulativeHash.calcSeedConcat(CipherSuiteBuilder.build(0), seeds); | ||
|
||
Assert.assertEquals("8ee0a0899c2d82b2e5b3fdc3b6c4e7d63fb35e33194089e129a131f575c87541811f8ebdb66fceb8e84e655c2e307f592a2046fdd2ace9ffa2ce6076f35814c0", | ||
resultList.get(0).getCumulativeHash()); | ||
|
||
//https://emn178.github.io/online-tools/sha512.html | ||
} | ||
|
||
@Test | ||
public void testTwoSeeds(){ | ||
List<SeedSourceDto> seeds = new ArrayList<>(); | ||
|
||
SeedSourceDto seedSourceDto1 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed1", "aDescription", null); | ||
SeedSourceDto seedSourceDto2 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed2", "aDescription2", null); | ||
|
||
seeds.add(seedSourceDto1); | ||
seeds.add(seedSourceDto2); | ||
|
||
CombinationUncornCumulativeHash combinationUncornCumulativeHash = new CombinationUncornCumulativeHash(); | ||
List<SeedUnicordCombinationVo> resultList = combinationUncornCumulativeHash.calcSeedConcat(CipherSuiteBuilder.build(0), seeds); | ||
|
||
Assert.assertEquals("175a91bccfefb53dad84d4a1ea49e66e2fe846f3210e3550c1fd874bdbe283965815b6f8db2caa5e9d0fc15b6fbd8810f3017e6ac315e828e75191a94128ceda", | ||
resultList.get(1).getCumulativeHash()); | ||
|
||
//https://emn178.github.io/online-tools/sha512.html | ||
} | ||
|
||
@Test | ||
public void testThreeSeeds(){ | ||
List<SeedSourceDto> seeds = new ArrayList<>(); | ||
|
||
SeedSourceDto seedSourceDto1 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed1", "aDescription", null); | ||
SeedSourceDto seedSourceDto2 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed2", "aDescription2", null); | ||
SeedSourceDto seedSourceDto3 = new SeedSourceDto(DateUtil.getTimeStampFormated(ZonedDateTime.now()), | ||
"uri", "aSeed2Test3", "aDescription2", null); | ||
|
||
seeds.add(seedSourceDto1); | ||
seeds.add(seedSourceDto2); | ||
seeds.add(seedSourceDto3); | ||
|
||
CombinationUncornCumulativeHash combinationUncornCumulativeHash = new CombinationUncornCumulativeHash(); | ||
List<SeedUnicordCombinationVo> resultList = combinationUncornCumulativeHash.calcSeedConcat(CipherSuiteBuilder.build(0), seeds); | ||
|
||
Assert.assertEquals("132543ac76c98f8b17c4893a275acb0871deea83726929dc391f93de435e763b9c739adaad329e0cdbc29e4c578f31ab702af4682c979f0837a7e9327299d179", | ||
resultList.get(2).getCumulativeHash()); | ||
|
||
//https://emn178.github.io/online-tools/sha512.html | ||
} | ||
|
||
|
||
} |