2222
2323package eu .webeid .example .service .dto ;
2424
25+ import java .util .Arrays ;
26+ import java .util .HashSet ;
27+ import java .util .Set ;
28+
2529public class SignatureAlgorithmDTO {
2630
31+ // See https://github.com/web-eid/web-eid-app/blob/main/src/controller/command-handlers/signauthutils.cpp#L121-L127
32+ private static final Set <String > SUPPORTED_CRYPTO_ALGOS = new HashSet <>(Arrays .asList (
33+ "ECC" , "RSA"
34+ ));
35+ private static final Set <String > SUPPORTED_PADDING_SCHEMES = new HashSet <>(Arrays .asList (
36+ "NONE" , "PKCS1.5" , "PSS"
37+ ));
38+ // See https://github.com/web-eid/libelectronic-id/tree/main/src/electronic-id.cpp#L131
39+ private static final Set <String > SUPPORTED_HASH_FUNCTIONS = new HashSet <>(Arrays .asList (
40+ "SHA-224" , "SHA-256" , "SHA-384" , "SHA-512" ,
41+ "SHA3-224" , "SHA3-256" , "SHA3-384" , "SHA3-512"
42+ ));
43+
2744 private String cryptoAlgorithm ;
2845
2946 private String hashFunction ;
@@ -35,6 +52,9 @@ public String getCryptoAlgorithm() {
3552 }
3653
3754 public void setCryptoAlgorithm (String cryptoAlgorithm ) {
55+ if (!SUPPORTED_CRYPTO_ALGOS .contains (cryptoAlgorithm )) {
56+ throw new IllegalArgumentException ("The provided crypto algorithm is not supported" );
57+ }
3858 this .cryptoAlgorithm = cryptoAlgorithm ;
3959 }
4060
@@ -43,6 +63,9 @@ public String getHashFunction() {
4363 }
4464
4565 public void setHashFunction (String hashFunction ) {
66+ if (!SUPPORTED_HASH_FUNCTIONS .contains (hashFunction )) {
67+ throw new IllegalArgumentException ("The provided hash function is not supported" );
68+ }
4669 this .hashFunction = hashFunction ;
4770 }
4871
@@ -51,6 +74,9 @@ public String getPaddingScheme() {
5174 }
5275
5376 public void setPaddingScheme (String paddingScheme ) {
77+ if (!SUPPORTED_PADDING_SCHEMES .contains (paddingScheme )) {
78+ throw new IllegalArgumentException ("The provided padding scheme is not supported" );
79+ }
5480 this .paddingScheme = paddingScheme ;
5581 }
5682}
0 commit comments