Path: blob/master/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/Reference.java
41161 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24/*25* $Id: Reference.java,v 1.9 2005/05/10 16:03:46 mullan Exp $26*/27package javax.xml.crypto.dsig;2829import javax.xml.crypto.Data;30import javax.xml.crypto.URIReference;31import javax.xml.crypto.XMLStructure;32import java.io.InputStream;33import java.util.List;3435/**36* A representation of the <code>Reference</code> element as defined in the37* <a href="http://www.w3.org/TR/xmldsig-core/">38* W3C Recommendation for XML-Signature Syntax and Processing</a>.39* The XML schema is defined as:40* <pre>41* <element name="Reference" type="ds:ReferenceType"/>42* <complexType name="ReferenceType">43* <sequence>44* <element ref="ds:Transforms" minOccurs="0"/>45* <element ref="ds:DigestMethod"/>46* <element ref="ds:DigestValue"/>47* </sequence>48* <attribute name="Id" type="ID" use="optional"/>49* <attribute name="URI" type="anyURI" use="optional"/>50* <attribute name="Type" type="anyURI" use="optional"/>51* </complexType>52*53* <element name="DigestValue" type="ds:DigestValueType"/>54* <simpleType name="DigestValueType">55* <restriction base="base64Binary"/>56* </simpleType>57* </pre>58*59* <p>A <code>Reference</code> instance may be created by invoking one of the60* {@link XMLSignatureFactory#newReference newReference} methods of the61* {@link XMLSignatureFactory} class; for example:62*63* <pre>64* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");65* Reference ref = factory.newReference66* ("http://www.ietf.org/rfc/rfc3275.txt",67* factory.newDigestMethod(DigestMethod.SHA1, null));68* </pre>69*70* @author Sean Mullan71* @author Erwin van der Koogh72* @author JSR 105 Expert Group73* @since 1.674* @see XMLSignatureFactory#newReference(String, DigestMethod)75* @see XMLSignatureFactory#newReference(String, DigestMethod, List, String, String)76*/77public interface Reference extends URIReference, XMLStructure {7879/**80* Returns an {@link java.util.Collections#unmodifiableList unmodifiable81* list} of {@link Transform}s that are contained in this82* <code>Reference</code>.83*84* @return an unmodifiable list of <code>Transform</code>s85* (may be empty but never <code>null</code>)86*/87List<Transform> getTransforms();8889/**90* Returns the digest method of this <code>Reference</code>.91*92* @return the digest method93*/94DigestMethod getDigestMethod();9596/**97* Returns the optional <code>Id</code> attribute of this98* <code>Reference</code>, which permits this reference to be99* referenced from elsewhere.100*101* @return the <code>Id</code> attribute (may be <code>null</code> if not102* specified)103*/104String getId();105106/**107* Returns the digest value of this <code>Reference</code>.108*109* @return the raw digest value, or <code>null</code> if this reference has110* not been digested yet. Each invocation of this method returns a new111* clone to protect against subsequent modification.112*/113byte[] getDigestValue();114115/**116* Returns the calculated digest value of this <code>Reference</code>117* after a validation operation. This method is useful for debugging if118* the reference fails to validate.119*120* @return the calculated digest value, or <code>null</code> if this121* reference has not been validated yet. Each invocation of this method122* returns a new clone to protect against subsequent modification.123*/124byte[] getCalculatedDigestValue();125126/**127* Validates this reference. This method verifies the digest of this128* reference.129*130* <p>This method only validates the reference the first time it is131* invoked. On subsequent invocations, it returns a cached result.132*133* @return <code>true</code> if this reference was validated successfully;134* <code>false</code> otherwise135* @param validateContext the validating context136* @throws NullPointerException if <code>validateContext</code> is137* <code>null</code>138* @throws XMLSignatureException if an unexpected exception occurs while139* validating the reference140*/141boolean validate(XMLValidateContext validateContext)142throws XMLSignatureException;143144/**145* Returns the dereferenced data, if146* <a href="XMLSignContext.html#SupportedProperties">reference caching</a>147* is enabled. This is the result of dereferencing the URI of this148* reference during a validation or generation operation.149*150* @return the dereferenced data, or <code>null</code> if reference151* caching is not enabled or this reference has not been generated or152* validated153*/154Data getDereferencedData();155156/**157* Returns the pre-digested input stream, if158* <a href="XMLSignContext.html#SupportedProperties">reference caching</a>159* is enabled. This is the input to the digest operation during a160* validation or signing operation.161*162* @return an input stream containing the pre-digested input, or163* <code>null</code> if reference caching is not enabled or this164* reference has not been generated or validated165*/166InputStream getDigestInputStream();167}168169170