src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMTransform.java
author weijun
Tue, 19 Jun 2018 08:06:35 +0800
changeset 50614 3810c9a2efa1
parent 47216 71c04702a3d5
child 53998 d870bb08194a
permissions -rw-r--r--
8177334: Update xmldsig implementation to Apache Santuario 2.1.1 Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    12
 * with the License. You may obtain a copy of the License at
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    21
 * under the License.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    22
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
/*
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    24
 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    25
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    26
/*
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    27
 * $Id: DOMTransform.java 1788465 2017-03-24 15:10:51Z coheigea $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.InvalidAlgorithmParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.NoSuchAlgorithmException;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    34
import java.security.Provider;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    37
import javax.xml.crypto.Data;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    38
import javax.xml.crypto.MarshalException;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    39
import javax.xml.crypto.XMLCryptoContext;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    40
import javax.xml.crypto.dsig.Transform;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    41
import javax.xml.crypto.dsig.TransformException;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    42
import javax.xml.crypto.dsig.TransformService;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    43
import javax.xml.crypto.dsig.XMLSignature;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    44
import javax.xml.crypto.dsig.dom.DOMSignContext;
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * DOM-based abstract implementation of Transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    53
public class DOMTransform extends BaseStructure implements Transform {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected TransformService spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
    58
     * Creates a {@code DOMTransform}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param spi the TransformService
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public DOMTransform(TransformService spi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.spi = spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    67
     * Creates a {@code DOMTransform} from an element. It unmarshals any
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    68
     * algorithm-specific input parameters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param transElem a Transform element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    72
    public DOMTransform(Element transElem, XMLCryptoContext context,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    73
                        Provider provider)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    74
        throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    75
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        String algorithm = DOMUtils.getAttributeValue(transElem, "Algorithm");
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    77
        if (provider == null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    78
            try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    79
                spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    80
            } catch (NoSuchAlgorithmException e1) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    81
                throw new MarshalException(e1);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    82
            }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    83
        } else {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    84
            try {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    85
                spi = TransformService.getInstance(algorithm, "DOM", provider);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    86
            } catch (NoSuchAlgorithmException nsae) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    87
                try {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    88
                    spi = TransformService.getInstance(algorithm, "DOM");
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    89
                } catch (NoSuchAlgorithmException e2) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    90
                    throw new MarshalException(e2);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
    91
                }
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    92
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            spi.init(new javax.xml.crypto.dom.DOMStructure(transElem), context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        } catch (InvalidAlgorithmParameterException iape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            throw new MarshalException(iape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   101
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public final AlgorithmParameterSpec getParameterSpec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return spi.getParameterSpec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   106
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        return spi.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   112
     * This method marshals any algorithm-specific parameters.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   114
    public void marshal(XmlWriter xwriter, String dsPrefix, XMLCryptoContext context)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   115
        throws MarshalException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   116
    {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   117
        String parentLocalName = xwriter.getCurrentLocalName();
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   118
        String localName = "Transforms".equals(parentLocalName) ? "Transform" : "CanonicalizationMethod";
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   119
        xwriter.writeStartElement(dsPrefix, localName, XMLSignature.XMLNS);
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   120
        xwriter.writeAttribute("", "", "Algorithm", getAlgorithm());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   122
        javax.xml.crypto.XMLStructure xmlStruct = xwriter.getCurrentNodeAsStructure();
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   123
        spi.marshalParams(xmlStruct, context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   125
        xwriter.writeEndElement(); // "Transforms" or "CanonicalizationMethod"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Transforms the specified data using the underlying transform algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param data the data to be transformed
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   132
     * @param xc the {@code XMLCryptoContext} containing
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   133
     *    additional context (may be {@code null} if not applicable)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return the transformed data
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   135
     * @throws NullPointerException if {@code data} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @throws XMLSignatureException if an unexpected error occurs while
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   137
     *    executing the transform
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   139
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public Data transform(Data data, XMLCryptoContext xc)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   141
        throws TransformException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   142
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return spi.transform(data, xc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Transforms the specified data using the underlying transform algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param data the data to be transformed
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   150
     * @param xc     the {@code XMLCryptoContext} containing
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   151
     *    additional context (may be {@code null} if not applicable)
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   152
     * @param os the {@code OutputStream} that should be used to write
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   153
     *    the transformed data to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the transformed data
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   155
     * @throws NullPointerException if {@code data} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @throws XMLSignatureException if an unexpected error occurs while
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   157
     *    executing the transform
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   159
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public Data transform(Data data, XMLCryptoContext xc, OutputStream os)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   161
        throws TransformException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   162
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return spi.transform(data, xc, os);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   166
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (this == o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (!(o instanceof Transform)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   175
        Transform otransform = (Transform)o;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   177
        return getAlgorithm().equals(otransform.getAlgorithm()) &&
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   178
                DOMUtils.paramsEqual(getParameterSpec(),
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   179
                                     otransform.getParameterSpec());
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   180
    }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   181
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   182
    @Override
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   183
    public int hashCode() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   184
        int result = 17;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   185
        result = 31 * result + getAlgorithm().hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   186
        AlgorithmParameterSpec spec = getParameterSpec();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   187
        if (spec != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   188
            result = 31 * result + spec.hashCode();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   189
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   190
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   191
        return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Transforms the specified data using the underlying transform algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * This method invokes the {@link #marshal marshal} method and passes it
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   197
     * the specified {@code DOMSignContext} before transforming the data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param data the data to be transformed
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   200
     * @param sc the {@code XMLCryptoContext} containing
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   201
     *    additional context (may be {@code null} if not applicable)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param context the marshalling context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the transformed data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @throws MarshalException if an exception occurs while marshalling
32003
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   205
     * @throws NullPointerException if {@code data} or {@code context}
acb12269398a 8132130: some docs cleanup
avstepan
parents: 25859
diff changeset
   206
     *    is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @throws XMLSignatureException if an unexpected error occurs while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *    executing the transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    Data transform(Data data, XMLCryptoContext xc, DOMSignContext context)
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   211
        throws MarshalException, TransformException
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 5506
diff changeset
   212
    {
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   213
        Node parent = context.getParent();
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   214
        XmlWriter xwriter = new XmlWriterToTree(Marshaller.getMarshallers(), parent);
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
   215
        marshal(xwriter, DOMUtils.getSignaturePrefix(context), context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return transform(data, xc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
}