Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit 911cc6d

Browse files
committed
More refactoring
git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1877725 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7ba9e17 commit 911cc6d

9 files changed

Lines changed: 86 additions & 18 deletions

File tree

src/main/java/org/apache/xml/security/keys/content/keyvalues/DSAKeyValue.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ public PublicKey getPublicKey() throws XMLSecurityException {
114114
PublicKey pk = dsaFactory.generatePublic(pkspec);
115115

116116
return pk;
117-
} catch (NoSuchAlgorithmException ex) {
118-
throw new XMLSecurityException(ex);
119-
} catch (InvalidKeySpecException ex) {
117+
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
120118
throw new XMLSecurityException(ex);
121119
}
122120
}

src/main/java/org/apache/xml/security/keys/content/keyvalues/ECKeyValue.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ public PublicKey getPublicKey() throws XMLSecurityException {
200200

201201
ECPublicKeySpec spec = new ECPublicKeySpec(ecPoint, ecParams);
202202
return KeyFactory.getInstance("EC").generatePublic(spec);
203-
} catch (NoSuchAlgorithmException ex) {
204-
throw new XMLSecurityException(ex);
205-
} catch (InvalidKeySpecException ex) {
206-
throw new XMLSecurityException(ex);
207-
} catch (MarshalException ex) {
203+
} catch (NoSuchAlgorithmException | InvalidKeySpecException | MarshalException ex) {
208204
throw new XMLSecurityException(ex);
209205
}
210206
}

src/main/java/org/apache/xml/security/keys/content/keyvalues/RSAKeyValue.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ public PublicKey getPublicKey() throws XMLSecurityException {
105105
PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
106106

107107
return pk;
108-
} catch (NoSuchAlgorithmException ex) {
109-
throw new XMLSecurityException(ex);
110-
} catch (InvalidKeySpecException ex) {
108+
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
111109
throw new XMLSecurityException(ex);
112110
}
113111
}

src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private boolean needsCircumvent(String str) {
115115
return str.indexOf("namespace") != -1 || str.indexOf("name()") != -1;
116116
}
117117

118-
static class XPathNodeFilter implements NodeFilter {
118+
private static class XPathNodeFilter implements NodeFilter {
119119

120120
private final XPathAPI xPathAPI;
121121
private final Node xpathnode;

src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverDirectHTTP.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,7 @@ private static URI getNewURI(String uri, String baseURI) throws URISyntaxExcepti
235235

236236
// if the URI contains a fragment, ignore it
237237
if (newUri.getFragment() != null) {
238-
URI uriNewNoFrag =
239-
new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
240-
return uriNewNoFrag;
238+
return new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
241239
}
242240
return newUri;
243241
}

src/main/java/org/apache/xml/security/utils/resolver/implementations/ResolverLocalFilesystem.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ private static URI getNewURI(String uri, String baseURI) throws URISyntaxExcepti
137137

138138
// if the URI contains a fragment, ignore it
139139
if (newUri.getFragment() != null) {
140-
URI uriNewNoFrag =
141-
new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
142-
return uriNewNoFrag;
140+
return new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
143141
}
144142
return newUri;
145143
}

src/test/java/org/apache/xml/security/test/dom/algorithms/DigestAlgorithmTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
import java.security.Security;
2626

2727
import org.apache.xml.security.algorithms.MessageDigestAlgorithm;
28+
import org.apache.xml.security.signature.XMLSignatureException;
2829
import org.apache.xml.security.test.dom.TestUtils;
2930
import org.junit.jupiter.api.Assumptions;
3031
import org.w3c.dom.Document;
3132

3233
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3334
import static org.junit.jupiter.api.Assertions.assertEquals;
3435
import static org.junit.jupiter.api.Assertions.assertNotNull;
36+
import static org.junit.jupiter.api.Assertions.assertThrows;
3537
import static org.junit.jupiter.api.Assertions.assertTrue;
3638

3739

@@ -294,4 +296,15 @@ public void testSHA3_512() throws Exception {
294296
assertArrayEquals(digest, digest2);
295297
}
296298

299+
@org.junit.jupiter.api.Test
300+
public void testNullAlgorithm() throws Exception {
301+
assertThrows(XMLSignatureException.class, () ->
302+
MessageDigestAlgorithm.getInstance(TestUtils.newDocument(), null));
303+
}
304+
305+
@org.junit.jupiter.api.Test
306+
public void testNoSuchAlgorithm() throws Exception {
307+
assertThrows(XMLSignatureException.class, () ->
308+
MessageDigestAlgorithm.getInstance(TestUtils.newDocument(), "xyz"));
309+
}
297310
}

src/test/java/org/apache/xml/security/test/dom/algorithms/SignatureAlgorithmTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import javax.crypto.SecretKey;
3535

3636
import org.apache.xml.security.algorithms.SignatureAlgorithm;
37+
import org.apache.xml.security.algorithms.implementations.SignatureBaseRSA;
38+
import org.apache.xml.security.exceptions.AlgorithmAlreadyRegisteredException;
3739
import org.apache.xml.security.exceptions.XMLSecurityException;
3840
import org.apache.xml.security.signature.XMLSignature;
3941
import org.apache.xml.security.signature.XMLSignatureException;
@@ -194,4 +196,20 @@ public void testHMACVerifyingKeyIsSecretKey() throws Exception {
194196
assertThrows(XMLSignatureException.class, () ->
195197
signatureAlgorithm.initVerify(keyPair.getPublic()));
196198
}
199+
200+
@org.junit.jupiter.api.Test
201+
public void testAlreadyRegisteredException() throws Exception {
202+
assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
203+
SignatureAlgorithm.register(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256,
204+
SignatureBaseRSA.SignatureRSASHA256.class)
205+
);
206+
}
207+
208+
@org.junit.jupiter.api.Test
209+
public void testAlreadyRegisteredExceptionFromString() throws Exception {
210+
assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
211+
SignatureAlgorithm.register(XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256,
212+
SignatureBaseRSA.SignatureRSASHA256.class.getName())
213+
);
214+
}
197215
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.xml.security.test.dom.transforms;
20+
21+
import org.apache.xml.security.Init;
22+
import org.apache.xml.security.exceptions.AlgorithmAlreadyRegisteredException;
23+
import org.apache.xml.security.transforms.Transform;
24+
import org.apache.xml.security.transforms.Transforms;
25+
import org.apache.xml.security.transforms.implementations.TransformC14N11;
26+
27+
import static org.junit.jupiter.api.Assertions.assertThrows;
28+
29+
public class TransformTest {
30+
31+
static {
32+
Init.init();
33+
}
34+
35+
@org.junit.jupiter.api.Test
36+
public void testAlreadyRegisteredException() throws Exception {
37+
assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
38+
Transform.register(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS, TransformC14N11.class)
39+
);
40+
}
41+
42+
@org.junit.jupiter.api.Test
43+
public void testAlreadyRegisteredExceptionFromString() throws Exception {
44+
assertThrows(AlgorithmAlreadyRegisteredException.class, () ->
45+
Transform.register(Transforms.TRANSFORM_C14N11_OMIT_COMMENTS,
46+
TransformC14N11.class.getName())
47+
);
48+
}
49+
}

0 commit comments

Comments
 (0)