-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Woohoo! First successful replication.
- Loading branch information
1 parent
ae531bf
commit 03a7325
Showing
14 changed files
with
668 additions
and
408 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
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
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
52 changes: 52 additions & 0 deletions
52
leyden/src/main/java/com/salesforce/apollo/leyden/DigestDatatype.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,52 @@ | ||
/* | ||
* Copyright (c) 2022, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
package com.salesforce.apollo.leyden; | ||
|
||
import com.salesforce.apollo.cryptography.Digest; | ||
import com.salesforce.apollo.cryptography.DigestAlgorithm; | ||
import org.h2.mvstore.WriteBuffer; | ||
import org.h2.mvstore.type.BasicDataType; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* @author hal.hildebrand | ||
*/ | ||
public final class DigestDatatype extends BasicDataType<Digest> { | ||
private final DigestAlgorithm algorithm; | ||
|
||
public DigestDatatype(DigestAlgorithm algorithm) { | ||
this.algorithm = algorithm; | ||
} | ||
|
||
@Override | ||
public int compare(Digest a, Digest b) { | ||
return a.compareTo(b); | ||
} | ||
|
||
@Override | ||
public Digest[] createStorage(int size) { | ||
return new Digest[size]; | ||
} | ||
|
||
@Override | ||
public int getMemory(Digest data) { | ||
return algorithm.longLength() * 8; | ||
} | ||
|
||
@Override | ||
public Digest read(ByteBuffer buff) { | ||
byte[] data = new byte[algorithm.longLength() * 8]; | ||
buff.get(data); | ||
return new Digest(algorithm, data); | ||
} | ||
|
||
@Override | ||
public void write(WriteBuffer buff, Digest data) { | ||
buff.put(data.getBytes()); | ||
} | ||
} |
Oops, something went wrong.