Skip to content

Commit eff0e97

Browse files
committed
Improved ErrorCode.
References #7.
1 parent 0344185 commit eff0e97

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

src/main/java/ro/kuberam/libs/java/crypto/CryptoException.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020
package ro.kuberam.libs.java.crypto;
2121

2222
public class CryptoException extends Exception {
23-
private final CryptoError cryptoError;
23+
private static final long serialVersionUID = -2606956271206243301L;
24+
private final CryptoError cryptoError;
2425

25-
public CryptoException(final CryptoError cryptoError) {
26-
super(cryptoError.asMessage());
27-
this.cryptoError = cryptoError;
28-
}
26+
public CryptoException(final CryptoError cryptoError) {
27+
super(cryptoError.getDescription());
28+
this.cryptoError = cryptoError;
29+
}
2930

30-
public CryptoException(final CryptoError cryptoError, final Throwable cause) {
31-
super(cryptoError.asMessage(), cause);
32-
this.cryptoError = cryptoError;
33-
}
31+
public CryptoException(final CryptoError cryptoError, final Throwable cause) {
32+
super(cryptoError.getDescription(), cause);
33+
this.cryptoError = cryptoError;
34+
}
3435

35-
public CryptoError getCryptoError() {
36-
return cryptoError;
37-
}
36+
public CryptoError getCryptoError() {
37+
return cryptoError;
38+
}
3839
}

src/main/java/ro/kuberam/libs/java/crypto/digitalSignature/GenerateXmlSignature.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static String generate(final Document inputDoc, final String canonicaliza
122122
final KeyStore keyStore;
123123
try {
124124
keyStore = KeyStore.getInstance(certificateDetails[0]);
125-
} catch (final Exception e) {
125+
} catch (Exception e) {
126126
throw new CryptoException(CryptoError.KEYSTORE_TYPE, e);
127127
}
128128
keyStore.load(keyStoreInputStream, certificateDetails[1].toCharArray());
@@ -209,16 +209,16 @@ public static String generate(final Document inputDoc, final String canonicaliza
209209
} else {
210210
return serializer.writeToString(sigParent);
211211
}
212-
} catch (final NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
212+
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
213213
throw new CryptoException(CryptoError.UNKNOWN_ALGORITH, e);
214-
} catch (final CertificateException e) {
214+
} catch (CertificateException e) {
215215
// TODO error code needs improving
216216
throw new CryptoException(CryptoError.INVALID_CRYPTO_KEY, e);
217-
} catch (final KeyStoreException e) {
217+
} catch (KeyStoreException e) {
218218
throw new CryptoException(CryptoError.UNREADABLE_KEYSTORE, e);
219-
} catch (final UnrecoverableKeyException | KeyException e) {
220-
throw new CryptoException(CryptoError.INVALID_KEY, e);
221-
} catch (final ParserConfigurationException | XPathExpressionException | MarshalException e) {
219+
} catch (UnrecoverableKeyException | KeyException e) {
220+
throw new CryptoException(CryptoError.INVALID_CRYPTO_KEY, e);
221+
} catch (ParserConfigurationException | XPathExpressionException | MarshalException e) {
222222
throw new IOException(e);
223223
}
224224
}

0 commit comments

Comments
 (0)