You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2006/06/08 20:27:47 UTC
svn commit: r412826 - in
/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom: DOMDigestMethod.java
DOMReference.java DOMXMLSignatureFactory.java
Author: mullan
Date: Thu Jun 8 11:27:46 2006
New Revision: 412826
URL: http://svn.apache.org/viewvc?rev=412826&view=rev
Log:
Add support for SHA256 & SHA512 digest algorithms.
Modified:
xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMDigestMethod.java
xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java
xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMDigestMethod.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMDigestMethod.java?rev=412826&r1=412825&r2=412826&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMDigestMethod.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMDigestMethod.java Thu Jun 8 11:27:46 2006
@@ -27,9 +27,6 @@
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
-import java.io.InputStream;
-import java.io.IOException;
-import java.security.DigestException;
import java.security.InvalidAlgorithmParameterException;
import java.security.spec.AlgorithmParameterSpec;
import org.w3c.dom.Document;
@@ -44,28 +41,22 @@
public abstract class DOMDigestMethod extends DOMStructure
implements DigestMethod {
- private String algorithm;
private DigestMethodParameterSpec params;
/**
* Creates a <code>DOMDigestMethod</code>.
*
- * @param algorithm the URI identifying the digest algorithm
* @param params the algorithm-specific params (may be <code>null</code>)
* @throws InvalidAlgorithmParameterException if the parameters are not
* appropriate for this digest method
*/
- protected DOMDigestMethod(String algorithm, AlgorithmParameterSpec params)
+ protected DOMDigestMethod(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
- if (algorithm == null) {
- throw new NullPointerException("algorithm cannot be null");
- }
if (params != null && !(params instanceof DigestMethodParameterSpec)) {
throw new InvalidAlgorithmParameterException
("params must be of type DigestMethodParameterSpec");
}
checkParams((DigestMethodParameterSpec) params);
- this.algorithm = algorithm;
this.params = (DigestMethodParameterSpec) params;
}
@@ -77,7 +68,6 @@
* @param dmElem a DigestMethod element
*/
protected DOMDigestMethod(Element dmElem) throws MarshalException {
- algorithm = DOMUtils.getAttributeValue(dmElem, "Algorithm");
Element paramsElem = DOMUtils.getFirstChildElement(dmElem);
if (paramsElem != null) {
params = unmarshalParams(paramsElem);
@@ -92,7 +82,11 @@
static DigestMethod unmarshal(Element dmElem) throws MarshalException {
String alg = DOMUtils.getAttributeValue(dmElem, "Algorithm");
if (alg.equals(DigestMethod.SHA1)) {
- return new DOMSHA1DigestMethod(dmElem);
+ return DOMSHADigestMethod.SHA1(dmElem);
+ } else if (alg.equals(DigestMethod.SHA256)) {
+ return DOMSHADigestMethod.SHA256(dmElem);
+ } else if (alg.equals(DigestMethod.SHA512)) {
+ return DOMSHADigestMethod.SHA512(dmElem);
} else {
throw new MarshalException("unsupported digest algorithm: " + alg);
}
@@ -112,10 +106,6 @@
return params;
}
- public final String getAlgorithm() {
- return algorithm;
- }
-
/**
* Unmarshals <code>DigestMethodParameterSpec</code> from the specified
* <code>Element</code>. Subclasses should implement this to unmarshal
@@ -138,7 +128,7 @@
Element dmElem = DOMUtils.createElement
(ownerDoc, "DigestMethod", XMLSignature.XMLNS, prefix);
- DOMUtils.setAttribute(dmElem, "Algorithm", algorithm);
+ DOMUtils.setAttribute(dmElem, "Algorithm", getAlgorithm());
if (params != null) {
marshalParams(dmElem, prefix);
@@ -147,18 +137,6 @@
parent.appendChild(dmElem);
}
- /**
- * Digests the specified data using the underlying message digest algorithm.
- *
- * @param is the input stream containing the data to be digested
- * @return the resulting hash value
- * @throws IOException if an I/O error occurs while reading from the stream
- * @throws DigestException if an unexpected error occurs while digesting
- * @throws NullPointerException if <code>is</code> is <code>null</code>
- */
- public abstract byte[] digest(InputStream is)
- throws IOException, DigestException;
-
public boolean equals(Object o) {
if (this == o) {
return true;
@@ -172,7 +150,7 @@
boolean paramsEqual = (params == null ? odm.getParameterSpec() == null :
params.equals(odm.getParameterSpec()));
- return (algorithm.equals(odm.getAlgorithm()) && paramsEqual);
+ return (getAlgorithm().equals(odm.getAlgorithm()) && paramsEqual);
}
public int hashCode() {
@@ -191,4 +169,9 @@
*/
protected abstract void marshalParams(Element parent, String prefix)
throws MarshalException;
+
+ /**
+ * Returns the MessageDigest standard algorithm name.
+ */
+ abstract String getMessageDigestAlgorithm();
}
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java?rev=412826&r1=412825&r2=412826&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMReference.java Thu Jun 8 11:27:46 2006
@@ -382,7 +382,8 @@
if (md == null) {
try {
- md = MessageDigest.getInstance("SHA-1");
+ md = MessageDigest.getInstance
+ (((DOMDigestMethod) digestMethod).getMessageDigestAlgorithm());
} catch (NoSuchAlgorithmException nsae) {
throw new XMLSignatureException(nsae);
}
Modified: xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java?rev=412826&r1=412825&r2=412826&view=diff
==============================================================================
--- xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java (original)
+++ xml/security/trunk/src/org/jcp/xml/dsig/internal/dom/DOMXMLSignatureFactory.java Thu Jun 8 11:27:46 2006
@@ -187,7 +187,11 @@
throw new NullPointerException();
}
if (algorithm.equals(DigestMethod.SHA1)) {
- return new DOMSHA1DigestMethod(params);
+ return DOMSHADigestMethod.SHA1(params);
+ } else if (algorithm.equals(DigestMethod.SHA256)) {
+ return DOMSHADigestMethod.SHA256(params);
+ } else if (algorithm.equals(DigestMethod.SHA512)) {
+ return DOMSHADigestMethod.SHA512(params);
} else {
throw new NoSuchAlgorithmException("unsupported algorithm");
}