src/java.xml.crypto/share/classes/com/sun/org/apache/xml/internal/security/transforms/implementations/TransformC14N.java
author jlaskey
Thu, 21 Jun 2018 08:58:59 -0300
changeset 50695 36ca515343e0
parent 50614 3810c9a2efa1
permissions -rw-r--r--
8203637: Fix Sources Reviewed-by: hannesw, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
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: 1337
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: 1337
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
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: 1337
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: 1337
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: 1337
diff changeset
    12
 * with the License. You may obtain a copy of the License at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
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: 1337
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: 1337
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: 1337
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: 1337
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    21
 * under the License.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.security.transforms.implementations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    30
import com.sun.org.apache.xml.internal.security.transforms.Transform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xml.internal.security.transforms.TransformSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xml.internal.security.transforms.Transforms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    35
 * Implements the {@code http://www.w3.org/TR/2001/REC-xml-c14n-20010315}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class TransformC14N extends TransformSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    41
    /** Field implementedTransformURI */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    42
    public static final String implementedTransformURI =
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    43
        Transforms.TRANSFORM_C14N_OMIT_COMMENTS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    45
    /**
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    46
     * {@inheritDoc}
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    47
     */
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    48
    protected String engineGetURI() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    49
        return TransformC14N.implementedTransformURI;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    50
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    52
    protected XMLSignatureInput enginePerformTransform(
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    53
        XMLSignatureInput input, OutputStream os, Transform transformObject
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    54
    ) throws CanonicalizationException {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    55
        Canonicalizer20010315OmitComments c14n = new Canonicalizer20010315OmitComments();
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    56
        c14n.setSecureValidation(secureValidation);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    57
        if (os != null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    58
            c14n.setWriter(os);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    59
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    60
        byte[] result = null;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    61
        result = c14n.engineCanonicalize(input);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    62
        XMLSignatureInput output = new XMLSignatureInput(result);
50614
3810c9a2efa1 8177334: Update xmldsig implementation to Apache Santuario 2.1.1
weijun
parents: 47216
diff changeset
    63
        output.setSecureValidation(secureValidation);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    64
        if (os != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            output.setOutputStream(os);
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    66
        }
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    67
        return output;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 1337
diff changeset
    68
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}