-
Notifications
You must be signed in to change notification settings - Fork 5
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
Showing
42 changed files
with
220 additions
and
208 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
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
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
38 changes: 38 additions & 0 deletions
38
io-hotmoka-crypto-api/src/main/java/io/hotmoka/crypto/api/Signer.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,38 @@ | ||
/* | ||
Copyright 2023 Fausto Spoto | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package io.hotmoka.crypto.api; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.security.SignatureException; | ||
|
||
/** | ||
* An object that computes the signature of a value with a private key. | ||
* | ||
* @param <T> the type of values that get signed | ||
*/ | ||
public interface Signer<T> { | ||
|
||
/** | ||
* Computes the signature of the given value with the given key. | ||
* | ||
* @param what the value to sign | ||
* @return the signature of the value | ||
* @throws InvalidKeyException if the private key used for signing is invalid | ||
* @throws SignatureException if the value cannot be signed | ||
*/ | ||
byte[] sign(T what) throws InvalidKeyException, SignatureException; | ||
} |
37 changes: 37 additions & 0 deletions
37
io-hotmoka-crypto/src/main/java/io/hotmoka/crypto/Signers.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,37 @@ | ||
package io.hotmoka.crypto; | ||
|
||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
|
||
import io.hotmoka.crypto.api.SignatureAlgorithm; | ||
import io.hotmoka.crypto.api.Signer; | ||
|
||
/** | ||
* Providers of objects that sign values with a private key. | ||
*/ | ||
public final class Signers<T> { | ||
|
||
private Signers() {} | ||
|
||
/** | ||
* Yields a signer for the given algorithm with the given key pair. | ||
* | ||
* @param signature the signing algorithm | ||
* @param keys the key pair | ||
* @return the signer | ||
*/ | ||
public static <T> Signer<T> with(SignatureAlgorithm<? super T> signature, KeyPair keys) { | ||
return with(signature, keys.getPrivate()); | ||
} | ||
|
||
/** | ||
* Yields a signer for the given algorithm with the given private key. | ||
* | ||
* @param signature the signing algorithm | ||
* @param key the private key | ||
* @return the signer | ||
*/ | ||
public static <T> Signer<T> with(SignatureAlgorithm<? super T> signature, PrivateKey key) { | ||
return what -> signature.sign(what, key); | ||
} | ||
} |
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
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
Oops, something went wrong.