0N/A/*
661N/A * reserved comment block
661N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
661N/A * Copyright 2005 The Apache Software Foundation.
661N/A *
661N/A * Licensed under the Apache License, Version 2.0 (the "License");
661N/A * you may not use this file except in compliance with the License.
661N/A * You may obtain a copy of the License at
661N/A *
661N/A * http://www.apache.org/licenses/LICENSE-2.0
661N/A *
661N/A * Unless required by applicable law or agreed to in writing, software
661N/A * distributed under the License is distributed on an "AS IS" BASIS,
661N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
661N/A * See the License for the specific language governing permissions and
661N/A * limitations under the License.
661N/A *
661N/A */
661N/A/*
2362N/A * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
661N/A */
661N/A/*
661N/A * $Id: DOMCanonicalizationMethod.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
0N/A */
0N/Apackage org.jcp.xml.dsig.internal.dom;
0N/A
0N/Aimport java.io.OutputStream;
0N/Aimport java.security.InvalidAlgorithmParameterException;
661N/Aimport java.security.Provider;
0N/A
0N/Aimport org.w3c.dom.Element;
0N/A
0N/Aimport javax.xml.crypto.*;
0N/Aimport javax.xml.crypto.dsig.*;
0N/A
0N/A/**
0N/A * DOM-based abstract implementation of CanonicalizationMethod.
0N/A *
0N/A * @author Sean Mullan
0N/A */
0N/Apublic class DOMCanonicalizationMethod extends DOMTransform
0N/A implements CanonicalizationMethod {
0N/A
0N/A /**
0N/A * Creates a <code>DOMCanonicalizationMethod</code>.
0N/A *
0N/A * @param spi TransformService
0N/A */
0N/A public DOMCanonicalizationMethod(TransformService spi)
0N/A throws InvalidAlgorithmParameterException {
0N/A super(spi);
6387N/A if (!(spi instanceof ApacheCanonicalizer) &&
6387N/A !isC14Nalg(spi.getAlgorithm())) {
6387N/A throw new InvalidAlgorithmParameterException(
6387N/A "Illegal CanonicalizationMethod");
6387N/A }
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>DOMCanonicalizationMethod</code> from an element. This
0N/A * ctor invokes the abstract {@link #unmarshalParams unmarshalParams}
0N/A * method to unmarshal any algorithm-specific input parameters.
0N/A *
0N/A * @param cmElem a CanonicalizationMethod element
0N/A */
661N/A public DOMCanonicalizationMethod(Element cmElem, XMLCryptoContext context,
661N/A Provider provider) throws MarshalException {
661N/A super(cmElem, context, provider);
6387N/A if (!(spi instanceof ApacheCanonicalizer) &&
6387N/A !isC14Nalg(spi.getAlgorithm())) {
6387N/A throw new MarshalException("Illegal CanonicalizationMethod");
6387N/A }
0N/A }
0N/A
0N/A /**
0N/A * Canonicalizes the specified data using the underlying canonicalization
0N/A * algorithm. This is a convenience method that is equivalent to invoking
0N/A * the {@link #transform transform} method.
0N/A *
0N/A * @param data the data to be canonicalized
0N/A * @param xc the <code>XMLCryptoContext</code> containing
0N/A * additional context (may be <code>null</code> if not applicable)
0N/A * @return the canonicalized data
0N/A * @throws NullPointerException if <code>data</code> is <code>null</code>
661N/A * @throws TransformException if an unexpected error occurs while
0N/A * canonicalizing the data
0N/A */
0N/A public Data canonicalize(Data data, XMLCryptoContext xc)
0N/A throws TransformException {
0N/A return transform(data, xc);
0N/A }
0N/A
0N/A public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os)
0N/A throws TransformException {
0N/A return transform(data, xc, os);
0N/A }
0N/A
0N/A public boolean equals(Object o) {
0N/A if (this == o) {
0N/A return true;
0N/A }
0N/A
0N/A if (!(o instanceof CanonicalizationMethod)) {
0N/A return false;
0N/A }
0N/A CanonicalizationMethod ocm = (CanonicalizationMethod) o;
0N/A
0N/A return (getAlgorithm().equals(ocm.getAlgorithm()) &&
0N/A DOMUtils.paramsEqual(getParameterSpec(), ocm.getParameterSpec()));
0N/A }
6387N/A
6387N/A private static boolean isC14Nalg(String alg) {
6387N/A return (alg.equals(CanonicalizationMethod.INCLUSIVE) ||
6387N/A alg.equals(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS) ||
6387N/A alg.equals(CanonicalizationMethod.EXCLUSIVE) ||
6387N/A alg.equals(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS) ||
6387N/A alg.equals(DOMCanonicalXMLC14N11Method.C14N_11) ||
6387N/A alg.equals(DOMCanonicalXMLC14N11Method.C14N_11_WITH_COMMENTS));
6387N/A }
0N/A}