~ubuntu-branches/ubuntu/precise/libxml-security-java/precise-updates

« back to all changes in this revision

Viewing changes to src/javax/xml/crypto/dsig/XMLSignatureFactory.java

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2008-01-18 14:56:26 UTC
  • Revision ID: james.westby@ubuntu.com-20080118145626-makoebepbd9mb0jf
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2005 The Apache Software Foundation.
 
3
 *
 
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
 
5
 *  you may not use this file except in compliance with the License.
 
6
 *  You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 *  Unless required by applicable law or agreed to in writing, software
 
11
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
12
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 *  See the License for the specific language governing permissions and
 
14
 *  limitations under the License.
 
15
 *
 
16
 */
 
17
/*
 
18
 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
 
19
 */
 
20
/*
 
21
 * $Id: XMLSignatureFactory.java 375655 2006-02-07 18:35:54 +0000 (Tue, 07 Feb 2006) mullan $
 
22
 */
 
23
package javax.xml.crypto.dsig;
 
24
 
 
25
import javax.xml.crypto.Data;
 
26
import javax.xml.crypto.MarshalException;
 
27
import javax.xml.crypto.NoSuchMechanismException;
 
28
import javax.xml.crypto.URIDereferencer;
 
29
import javax.xml.crypto.XMLStructure;
 
30
import javax.xml.crypto.dom.DOMStructure;
 
31
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
 
32
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
 
33
import javax.xml.crypto.dsig.spec.*;
 
34
import javax.xml.crypto.dsig.dom.DOMValidateContext;
 
35
import javax.xml.crypto.dsig.dom.DOMSignContext;
 
36
 
 
37
import java.security.InvalidAlgorithmParameterException;
 
38
import java.security.NoSuchAlgorithmException;
 
39
import java.security.NoSuchProviderException;
 
40
import java.security.Provider;
 
41
import java.security.Security;
 
42
import java.util.List;
 
43
 
 
44
/**
 
45
 * A factory for creating {@link XMLSignature} objects from scratch or 
 
46
 * for unmarshalling an <code>XMLSignature</code> object from a corresponding
 
47
 * XML representation.
 
48
 *
 
49
 * <h2>XMLSignatureFactory Type</h2>
 
50
 *
 
51
 * <p>Each instance of <code>XMLSignatureFactory</code> supports a specific
 
52
 * XML mechanism type. To create an <code>XMLSignatureFactory</code>, call one
 
53
 * of the static {@link #getInstance getInstance} methods, passing in the XML 
 
54
 * mechanism type desired, for example:
 
55
 *
 
56
 * <blockquote><code>
 
57
 * XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
 
58
 * </code></blockquote>
 
59
 *
 
60
 * <p>The objects that this factory produces will be based
 
61
 * on DOM and abide by the DOM interoperability requirements as defined in the
 
62
 * <a href="../../../../overview-summary.html#DOM Mechanism Requirements">DOM
 
63
 * Mechanism Requirements</a> section of the API overview. See the
 
64
 * <a href="../../../../overview-summary.html#Service Provider">Service 
 
65
 * Providers</a> section of the API overview for a list of standard mechanism 
 
66
 * types.
 
67
 *
 
68
 * <p><code>XMLSignatureFactory</code> implementations are registered and loaded
 
69
 * using the {@link java.security.Provider} mechanism.  
 
70
 * For example, a service provider that supports the
 
71
 * DOM mechanism would be specified in the <code>Provider</code> subclass as:
 
72
 * <pre>
 
73
 *     put("XMLSignatureFactory.DOM", "org.example.DOMXMLSignatureFactory");
 
74
 * </pre>
 
75
 *
 
76
 * <p>An implementation MUST minimally support the default mechanism type: DOM. 
 
77
 *
 
78
 * <p>Note that a caller must use the same <code>XMLSignatureFactory</code>
 
79
 * instance to create the <code>XMLStructure</code>s of a particular 
 
80
 * <code>XMLSignature</code> that is to be generated. The behavior is
 
81
 * undefined if <code>XMLStructure</code>s from different providers or 
 
82
 * different mechanism types are used together.
 
83
 *
 
84
 * <p>Also, the <code>XMLStructure</code>s that are created by this factory
 
85
 * may contain state specific to the <code>XMLSignature</code> and are not
 
86
 * intended to be reusable.
 
87
 *
 
88
 * <h2>Creating XMLSignatures from scratch</h2>
 
89
 *
 
90
 * <p>Once the <code>XMLSignatureFactory</code> has been created, objects
 
91
 * can be instantiated by calling the appropriate method. For example, a
 
92
 * {@link Reference} instance may be created by invoking one of the
 
93
 * {@link #newReference newReference} methods.
 
94
 *
 
95
 * <h2>Unmarshalling XMLSignatures from XML</h2>
 
96
 *
 
97
 * <p>Alternatively, an <code>XMLSignature</code> may be created from an
 
98
 * existing XML representation by invoking the {@link #unmarshalXMLSignature
 
99
 * unmarshalXMLSignature} method and passing it a mechanism-specific 
 
100
 * {@link XMLValidateContext} instance containing the XML content:
 
101
 *
 
102
 * <pre>
 
103
 * DOMValidateContext context = new DOMValidateContext(key, signatureElement);
 
104
 * XMLSignature signature = factory.unmarshalXMLSignature(context);
 
105
 * </pre>
 
106
 *
 
107
 * Each <code>XMLSignatureFactory</code> must support the required 
 
108
 * <code>XMLValidateContext</code> types for that factory type, but may support 
 
109
 * others. A DOM <code>XMLSignatureFactory</code> must support {@link 
 
110
 * DOMValidateContext} objects.
 
111
 * 
 
112
 * <h2>Signing and marshalling XMLSignatures to XML</h2>
 
113
 *
 
114
 * Each <code>XMLSignature</code> created by the factory can also be 
 
115
 * marshalled to an XML representation and signed, by invoking the 
 
116
 * {@link XMLSignature#sign sign} method of the 
 
117
 * {@link XMLSignature} object and passing it a mechanism-specific 
 
118
 * {@link XMLSignContext} object containing the signing key and 
 
119
 * marshalling parameters (see {@link DOMSignContext}).
 
120
 * For example: 
 
121
 *
 
122
 * <pre>
 
123
 *    DOMSignContext context = new DOMSignContext(privateKey, document);
 
124
 *    signature.sign(context);
 
125
 * </pre>
 
126
 *
 
127
 * <b>Concurrent Access</b>
 
128
 * <p>The static methods of this class are guaranteed to be thread-safe. 
 
129
 * Multiple threads may concurrently invoke the static methods defined in this 
 
130
 * class with no ill effects. 
 
131
 *
 
132
 * <p>However, this is not true for the non-static methods defined by this 
 
133
 * class. Unless otherwise documented by a specific provider, threads that 
 
134
 * need to access a single <code>XMLSignatureFactory</code> instance 
 
135
 * concurrently should synchronize amongst themselves and provide the 
 
136
 * necessary locking. Multiple threads each manipulating a different 
 
137
 * <code>XMLSignatureFactory</code> instance need not synchronize. 
 
138
 *
 
139
 * @author Sean Mullan
 
140
 * @author JSR 105 Expert Group
 
141
 */
 
142
public abstract class XMLSignatureFactory {
 
143
 
 
144
    private String mechanismType;
 
145
    private Provider provider;
 
146
 
 
147
    /**
 
148
     * Default constructor, for invocation by subclasses.
 
149
     */
 
150
    protected XMLSignatureFactory() {}
 
151
 
 
152
    /**
 
153
     * Returns an <code>XMLSignatureFactory</code> that supports the
 
154
     * specified XML processing mechanism and representation type (ex: "DOM").
 
155
     *
 
156
     * <p>This method uses the standard JCA provider lookup mechanism to
 
157
     * locate and instantiate an <code>XMLSignatureFactory</code> 
 
158
     * implementation of the desired mechanism type. It traverses the list of 
 
159
     * registered security <code>Provider</code>s, starting with the most 
 
160
     * preferred <code>Provider</code>.  A new <code>XMLSignatureFactory</code> 
 
161
     * object from the first <code>Provider</code> that supports the specified 
 
162
     * mechanism is returned. 
 
163
     *
 
164
     * <p>Note that the list of registered providers may be retrieved via 
 
165
     * the {@link Security#getProviders() Security.getProviders()} method. 
 
166
     *
 
167
     * @param mechanismType the type of the XML processing mechanism and
 
168
     *    representation. See the <a 
 
169
     *    href="../../../../overview-summary.html#Service Provider">Service 
 
170
     *    Providers</a> section of the API overview for a list of standard 
 
171
     *    mechanism types.
 
172
     * @return a new <code>XMLSignatureFactory</code>
 
173
     * @throws NullPointerException if <code>mechanismType</code> is 
 
174
     *    <code>null</code>
 
175
     * @throws NoSuchMechanismException if no <code>Provider</code> supports an 
 
176
     *    <code>XMLSignatureFactory</code> implementation for the specified 
 
177
     *    mechanism
 
178
     * @see Provider
 
179
     */
 
180
    public static XMLSignatureFactory getInstance(String mechanismType) {
 
181
        if (mechanismType == null) {
 
182
            throw new NullPointerException("mechanismType cannot be null");
 
183
        }
 
184
 
 
185
        return findInstance(mechanismType, null);
 
186
    }
 
187
 
 
188
    private static XMLSignatureFactory findInstance(String mechanismType,
 
189
        Provider provider) {
 
190
 
 
191
        Object[] objs = null;
 
192
        try {
 
193
            objs = (Object[]) XMLDSigSecurity.getImpl
 
194
                (mechanismType, "XMLSignatureFactory", provider);
 
195
        } catch (NoSuchAlgorithmException nsae) {
 
196
            throw new NoSuchMechanismException
 
197
                ("Cannot find " + mechanismType + " mechanism type", nsae);
 
198
        }
 
199
 
 
200
        XMLSignatureFactory factory = (XMLSignatureFactory) objs[0];
 
201
        factory.mechanismType = mechanismType;
 
202
        factory.provider = (Provider) objs[1];
 
203
        return factory;
 
204
    }
 
205
 
 
206
    /**
 
207
     * Returns an <code>XMLSignatureFactory</code> that supports the
 
208
     * requested XML processing mechanism and representation type (ex: "DOM"),
 
209
     * as supplied by the specified provider. Note that the specified 
 
210
     * <code>Provider</code> object does not have to be registered in the 
 
211
     * provider list. 
 
212
     *
 
213
     * @param mechanismType the type of the XML processing mechanism and
 
214
     *    representation. See the <a 
 
215
     *    href="../../../../overview-summary.html#Service Provider">Service 
 
216
     *    Providers</a> section of the API overview for a list of standard 
 
217
     *    mechanism types.
 
218
     * @param provider the <code>Provider</code> object
 
219
     * @return a new <code>XMLSignatureFactory</code>
 
220
     * @throws NullPointerException if <code>provider</code> or 
 
221
     *    <code>mechanismType</code> is <code>null</code>
 
222
     * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code> 
 
223
     *   implementation for the specified mechanism is not available 
 
224
     *   from the specified <code>Provider</code> object
 
225
     * @see Provider
 
226
     */
 
227
    public static XMLSignatureFactory getInstance(String mechanismType,
 
228
        Provider provider) { 
 
229
        if (mechanismType == null) {
 
230
            throw new NullPointerException("mechanismType cannot be null");
 
231
        } else if (provider == null) {
 
232
            throw new NullPointerException("provider cannot be null");
 
233
        }
 
234
 
 
235
        return findInstance(mechanismType, provider);
 
236
    }    
 
237
 
 
238
    /**
 
239
     * Returns an <code>XMLSignatureFactory</code> that supports the
 
240
     * requested XML processing mechanism and representation type (ex: "DOM"),
 
241
     * as supplied by the specified provider. The specified provider must be 
 
242
     * registered in the security provider list. 
 
243
     *
 
244
     * <p>Note that the list of registered providers may be retrieved via 
 
245
     * the {@link Security#getProviders() Security.getProviders()} method.
 
246
     *
 
247
     * @param mechanismType the type of the XML processing mechanism and
 
248
     *    representation. See the <a 
 
249
     *    href="../../../../overview-summary.html#Service Provider">Service 
 
250
     *    Providers</a> section of the API overview for a list of standard 
 
251
     *    mechanism types.
 
252
     * @param provider the string name of the provider
 
253
     * @return a new <code>XMLSignatureFactory</code>
 
254
     * @throws NoSuchProviderException if the specified provider is not 
 
255
     *    registered in the security provider list
 
256
     * @throws NullPointerException if <code>provider</code> or 
 
257
     *    <code>mechanismType</code> is <code>null</code>
 
258
     * @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code> 
 
259
     *    implementation for the specified mechanism is not 
 
260
     *    available from the specified provider
 
261
     * @see Provider
 
262
     */
 
263
    public static XMLSignatureFactory getInstance(String mechanismType,
 
264
        String provider) throws NoSuchProviderException {
 
265
        if (mechanismType == null) {
 
266
            throw new NullPointerException("mechanismType cannot be null");
 
267
        } else if (provider == null) {
 
268
            throw new NullPointerException("provider cannot be null");
 
269
        }
 
270
 
 
271
        Provider prov = Security.getProvider(provider);
 
272
        if (prov == null) {
 
273
            throw new NoSuchProviderException("cannot find provider named "
 
274
                + provider);
 
275
        }
 
276
 
 
277
        return findInstance(mechanismType, prov);
 
278
    }
 
279
 
 
280
    /**
 
281
     * Returns an <code>XMLSignatureFactory</code> that supports the
 
282
     * default XML processing mechanism and representation type ("DOM").
 
283
     *
 
284
     * <p>This method uses the standard JCA provider lookup mechanism to
 
285
     * locate and instantiate an <code>XMLSignatureFactory</code> 
 
286
     * implementation of the default mechanism type. It traverses the list of 
 
287
     * registered security <code>Provider</code>s, starting with the most 
 
288
     * preferred <code>Provider</code>.  A new <code>XMLSignatureFactory</code> 
 
289
     * object from the first <code>Provider</code> that supports the DOM 
 
290
     * mechanism is returned. 
 
291
     *
 
292
     * <p>Note that the list of registered providers may be retrieved via 
 
293
     * the {@link Security#getProviders() Security.getProviders()} method. 
 
294
     *
 
295
     * @return a new <code>XMLSignatureFactory</code>
 
296
     * @throws NoSuchMechanismException if no <code>Provider</code> supports an 
 
297
     *    <code>XMLSignatureFactory</code> implementation for the DOM 
 
298
     *    mechanism
 
299
     * @see Provider
 
300
     */
 
301
    public static XMLSignatureFactory getInstance() {
 
302
        return getInstance("DOM");
 
303
    }
 
304
 
 
305
    /**
 
306
     * Returns the type of the XML processing mechanism and representation
 
307
     * supported by this <code>XMLSignatureFactory</code> (ex: "DOM").
 
308
     *
 
309
     * @return the XML processing mechanism type supported by this
 
310
     *    <code>XMLSignatureFactory</code>
 
311
     */
 
312
    public final String getMechanismType() {
 
313
        return mechanismType;
 
314
    }
 
315
 
 
316
    /**
 
317
     * Returns the provider of this <code>XMLSignatureFactory</code>.
 
318
     *
 
319
     * @return the provider of this <code>XMLSignatureFactory</code>
 
320
     */
 
321
    public final Provider getProvider() {
 
322
        return provider;
 
323
    }
 
324
 
 
325
    /**
 
326
     * Creates an <code>XMLSignature</code> and initializes it with the contents
 
327
     * of the specified <code>SignedInfo</code> and <code>KeyInfo</code> 
 
328
     * objects.
 
329
     *
 
330
     * @param si the signed info
 
331
     * @param ki the key info (may be <code>null</code>)
 
332
     * @return an <code>XMLSignature</code>
 
333
     * @throws NullPointerException if <code>si</code> is <code>null</code>
 
334
     */
 
335
    public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki);
 
336
 
 
337
    /**
 
338
     * Creates an <code>XMLSignature</code> and initializes it with the
 
339
     * specified parameters.
 
340
     *
 
341
     * @param si the signed info
 
342
     * @param ki the key info (may be <code>null</code>)
 
343
     * @param objects a list of {@link XMLObject}s (may be empty or
 
344
     *    <code>null</code>)
 
345
     * @param id the Id (may be <code>null</code>)
 
346
     * @param signatureValueId the SignatureValue Id (may be <code>null</code>)
 
347
     * @return an <code>XMLSignature</code>
 
348
     * @throws NullPointerException if <code>si</code> is <code>null</code>
 
349
     * @throws ClassCastException if any of the <code>objects</code> are not of
 
350
     *    type <code>XMLObject</code> 
 
351
     */ 
 
352
    public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
 
353
        List objects, String id, String signatureValueId);
 
354
 
 
355
    /**
 
356
     * Creates a <code>Reference</code> with the specified URI and digest
 
357
     * method.
 
358
     *
 
359
     * @param uri the reference URI (may be <code>null</code>)
 
360
     * @param dm the digest method
 
361
     * @return a <code>Reference</code>
 
362
     * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
 
363
     *    compliant
 
364
     * @throws NullPointerException if <code>dm</code> is <code>null</code>
 
365
     */
 
366
    public abstract Reference newReference(String uri, DigestMethod dm);
 
367
 
 
368
    /**
 
369
     * Creates a <code>Reference</code> with the specified parameters.
 
370
     *
 
371
     * @param uri the reference URI (may be <code>null</code>)
 
372
     * @param dm the digest method
 
373
     * @param transforms a list of {@link Transform}s. The list is defensively 
 
374
     *    copied to protect against subsequent modification. May be 
 
375
     *    <code>null</code> or empty.
 
376
     * @param type the reference type, as a URI (may be <code>null</code>)
 
377
     * @param id the reference ID (may be <code>null</code>)
 
378
     * @return a <code>Reference</code>
 
379
     * @throws ClassCastException if any of the <code>transforms</code> are 
 
380
     *    not of type <code>Transform</code>
 
381
     * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
 
382
     *    compliant
 
383
     * @throws NullPointerException if <code>dm</code> is <code>null</code>
 
384
     */
 
385
    public abstract Reference newReference(String uri, DigestMethod dm, 
 
386
        List transforms, String type, String id);
 
387
 
 
388
    /**
 
389
     * Creates a <code>Reference</code> with the specified parameters and
 
390
     * pre-calculated digest value. 
 
391
     *
 
392
     * <p>This method is useful when the digest value of a 
 
393
     * <code>Reference</code> has been previously computed. See for example,
 
394
     * the 
 
395
     * <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
 
396
     * OASIS-DSS (Digital Signature Services)</a> specification.
 
397
     * 
 
398
     * @param uri the reference URI (may be <code>null</code>)
 
399
     * @param dm the digest method
 
400
     * @param transforms a list of {@link Transform}s. The list is defensively 
 
401
     *    copied to protect against subsequent modification. May be 
 
402
     *    <code>null</code> or empty.
 
403
     * @param type the reference type, as a URI (may be <code>null</code>)
 
404
     * @param id the reference ID (may be <code>null</code>)
 
405
     * @param digestValue the digest value. The array is cloned to protect
 
406
     *    against subsequent modification.
 
407
     * @return a <code>Reference</code>
 
408
     * @throws ClassCastException if any of the <code>transforms</code> are 
 
409
     *    not of type <code>Transform</code>
 
410
     * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
 
411
     *    compliant
 
412
     * @throws NullPointerException if <code>dm</code> or 
 
413
     *    <code>digestValue</code> is <code>null</code>
 
414
     */
 
415
    public abstract Reference newReference(String uri, DigestMethod dm, 
 
416
        List transforms, String type, String id, byte[] digestValue);
 
417
 
 
418
    /**
 
419
     * Creates a <code>Reference</code> with the specified parameters.
 
420
     *
 
421
     * <p>This method is useful when a list of transforms have already been
 
422
     * applied to the <code>Reference</code>. See for example,
 
423
     * the 
 
424
     * <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
 
425
     * OASIS-DSS (Digital Signature Services)</a> specification.
 
426
     *
 
427
     * <p>When an <code>XMLSignature</code> containing this reference is 
 
428
     * generated, the specified <code>transforms</code> (if non-null) are 
 
429
     * applied to the specified <code>result</code>. The 
 
430
     * <code>Transforms</code> element of the resulting <code>Reference</code> 
 
431
     * element is set to the concatenation of the 
 
432
     * <code>appliedTransforms</code> and <code>transforms</code>.
 
433
     * 
 
434
     * @param uri the reference URI (may be <code>null</code>)
 
435
     * @param dm the digest method
 
436
     * @param appliedTransforms a list of {@link Transform}s that have 
 
437
     *    already been applied. The list is defensively 
 
438
     *    copied to protect against subsequent modification. The list must 
 
439
     *    contain at least one entry.
 
440
     * @param result the result of processing the sequence of 
 
441
     *    <code>appliedTransforms</code>
 
442
     * @param transforms a list of {@link Transform}s that are to be applied
 
443
     *    when generating the signature. The list is defensively copied to 
 
444
     *    protect against subsequent modification. May be <code>null</code> 
 
445
     *    or empty.
 
446
     * @param type the reference type, as a URI (may be <code>null</code>)
 
447
     * @param id the reference ID (may be <code>null</code>)
 
448
     * @return a <code>Reference</code>
 
449
     * @throws ClassCastException if any of the transforms (in either list) 
 
450
     *    are not of type <code>Transform</code>
 
451
     * @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
 
452
     *    compliant or <code>appliedTransforms</code> is empty
 
453
     * @throws NullPointerException if <code>dm</code>, 
 
454
     *    <code>appliedTransforms</code> or <code>result</code> is 
 
455
     *    <code>null</code>
 
456
     */
 
457
    public abstract Reference newReference(String uri, DigestMethod dm, 
 
458
        List appliedTransforms, Data result, List transforms, String type, 
 
459
        String id);
 
460
 
 
461
    /**
 
462
     * Creates a <code>SignedInfo</code> with the specified canonicalization
 
463
     * and signature methods, and list of one or more references. 
 
464
     *
 
465
     * @param cm the canonicalization method
 
466
     * @param sm the signature method
 
467
     * @param references a list of one or more {@link Reference}s. The list is
 
468
     *    defensively copied to protect against subsequent modification.
 
469
     * @return a <code>SignedInfo</code>
 
470
     * @throws ClassCastException if any of the references are not of
 
471
     *    type <code>Reference</code> 
 
472
     * @throws IllegalArgumentException if <code>references</code> is empty
 
473
     * @throws NullPointerException if any of the parameters
 
474
     *    are <code>null</code>
 
475
     */
 
476
    public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
 
477
        SignatureMethod sm, List references);
 
478
 
 
479
    /**
 
480
     * Creates a <code>SignedInfo</code> with the specified parameters.
 
481
     *
 
482
     * @param cm the canonicalization method
 
483
     * @param sm the signature method
 
484
     * @param references a list of one or more {@link Reference}s. The list is
 
485
     *    defensively copied to protect against subsequent modification.
 
486
     * @param id the id (may be <code>null</code>)
 
487
     * @return a <code>SignedInfo</code>
 
488
     * @throws ClassCastException if any of the references are not of
 
489
     *    type <code>Reference</code> 
 
490
     * @throws IllegalArgumentException if <code>references</code> is empty
 
491
     * @throws NullPointerException if <code>cm</code>, <code>sm</code>, or
 
492
     *    <code>references</code> are <code>null</code>
 
493
     */
 
494
    public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
 
495
        SignatureMethod sm, List references, String id);
 
496
 
 
497
    // Object factory methods
 
498
    /**
 
499
     * Creates an <code>XMLObject</code> from the specified parameters.
 
500
     *
 
501
     * @param content a list of {@link XMLStructure}s. The list
 
502
     *    is defensively copied to protect against subsequent modification.
 
503
     *    May be <code>null</code> or empty.
 
504
     * @param id the Id (may be <code>null</code>)
 
505
     * @param mimeType the mime type (may be <code>null</code>)
 
506
     * @param encoding the encoding (may be <code>null</code>)
 
507
     * @return an <code>XMLObject</code>
 
508
     * @throws ClassCastException if <code>content</code> contains any 
 
509
     *    entries that are not of type {@link XMLStructure}
 
510
     */
 
511
    public abstract XMLObject newXMLObject(List content, String id, 
 
512
        String mimeType, String encoding);
 
513
 
 
514
    /**
 
515
     * Creates a <code>Manifest</code> containing the specified 
 
516
     * list of {@link Reference}s. 
 
517
     *
 
518
     * @param references a list of one or more <code>Reference</code>s. The list
 
519
     *    is defensively copied to protect against subsequent modification.
 
520
     * @return a <code>Manifest</code>
 
521
     * @throws NullPointerException if <code>references</code> is 
 
522
     *    <code>null</code>
 
523
     * @throws IllegalArgumentException if <code>references</code> is empty
 
524
     * @throws ClassCastException if <code>references</code> contains any 
 
525
     *    entries that are not of type {@link Reference}
 
526
     */
 
527
    public abstract Manifest newManifest(List references);
 
528
 
 
529
    /**
 
530
     * Creates a <code>Manifest</code> containing the specified 
 
531
     * list of {@link Reference}s and optional id. 
 
532
     *
 
533
     * @param references a list of one or more <code>Reference</code>s. The list
 
534
     *    is defensively copied to protect against subsequent modification.
 
535
     * @param id the id (may be <code>null</code>)
 
536
     * @return a <code>Manifest</code>
 
537
     * @throws NullPointerException if <code>references</code> is 
 
538
     *    <code>null</code>
 
539
     * @throws IllegalArgumentException if <code>references</code> is empty
 
540
     * @throws ClassCastException if <code>references</code> contains any 
 
541
     *    entries that are not of type {@link Reference}
 
542
     */
 
543
    public abstract Manifest newManifest(List references, String id);
 
544
 
 
545
    /**
 
546
     * Creates a <code>SignatureProperty</code> containing the specified 
 
547
     * list of {@link XMLStructure}s, target URI and optional id. 
 
548
     *
 
549
     * @param content a list of one or more <code>XMLStructure</code>s. The list
 
550
     *    is defensively copied to protect against subsequent modification.
 
551
     * @param target the target URI of the Signature that this property applies 
 
552
     *    to
 
553
     * @param id the id (may be <code>null</code>)
 
554
     * @return a <code>SignatureProperty</code>
 
555
     * @throws NullPointerException if <code>content</code> or 
 
556
     *    <code>target</code> is <code>null</code>
 
557
     * @throws IllegalArgumentException if <code>content</code> is empty
 
558
     * @throws ClassCastException if <code>content</code> contains any 
 
559
     *    entries that are not of type {@link XMLStructure}
 
560
     */
 
561
    public abstract SignatureProperty newSignatureProperty
 
562
        (List content, String target, String id);
 
563
 
 
564
    /**
 
565
     * Creates a <code>SignatureProperties</code> containing the specified 
 
566
     * list of {@link SignatureProperty}s and optional id. 
 
567
     *
 
568
     * @param properties a list of one or more <code>SignatureProperty</code>s. 
 
569
     *    The list is defensively copied to protect against subsequent 
 
570
     *    modification.
 
571
     * @param id the id (may be <code>null</code>)
 
572
     * @return a <code>SignatureProperties</code>
 
573
     * @throws NullPointerException if <code>properties</code>
 
574
     *    is <code>null</code>
 
575
     * @throws IllegalArgumentException if <code>properties</code> is empty
 
576
     * @throws ClassCastException if <code>properties</code> contains any 
 
577
     *    entries that are not of type {@link SignatureProperty}
 
578
     */
 
579
    public abstract SignatureProperties newSignatureProperties
 
580
        (List properties, String id);
 
581
 
 
582
    // Algorithm factory methods
 
583
    /**
 
584
     * Creates a <code>DigestMethod</code> for the specified algorithm URI 
 
585
     * and parameters.
 
586
     *
 
587
     * @param algorithm the URI identifying the digest algorithm
 
588
     * @param params algorithm-specific digest parameters (may be 
 
589
     *    <code>null</code>)
 
590
     * @return the <code>DigestMethod</code>
 
591
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
592
     *    are inappropriate for the requested algorithm
 
593
     * @throws NoSuchAlgorithmException if an implementation of the
 
594
     *    specified algorithm cannot be found
 
595
     * @throws NullPointerException if <code>algorithm</code> is 
 
596
     *    <code>null</code>
 
597
     */
 
598
    public abstract DigestMethod newDigestMethod(String algorithm, 
 
599
        DigestMethodParameterSpec params) throws NoSuchAlgorithmException,
 
600
        InvalidAlgorithmParameterException;
 
601
 
 
602
    /**
 
603
     * Creates a <code>SignatureMethod</code> for the specified algorithm URI 
 
604
     * and parameters.
 
605
     *
 
606
     * @param algorithm the URI identifying the signature algorithm
 
607
     * @param params algorithm-specific signature parameters (may be 
 
608
     *    <code>null</code>)
 
609
     * @return the <code>SignatureMethod</code>
 
610
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
611
     *    are inappropriate for the requested algorithm
 
612
     * @throws NoSuchAlgorithmException if an implementation of the
 
613
     *    specified algorithm cannot be found
 
614
     * @throws NullPointerException if <code>algorithm</code> is 
 
615
     *    <code>null</code>
 
616
     */
 
617
    public abstract SignatureMethod newSignatureMethod(String algorithm, 
 
618
        SignatureMethodParameterSpec params) throws NoSuchAlgorithmException,
 
619
        InvalidAlgorithmParameterException;
 
620
 
 
621
    /**
 
622
     * Creates a <code>Transform</code> for the specified algorithm URI 
 
623
     * and parameters.
 
624
     *
 
625
     * @param algorithm the URI identifying the transform algorithm
 
626
     * @param params algorithm-specific transform parameters (may be 
 
627
     *    <code>null</code>)
 
628
     * @return the <code>Transform</code>
 
629
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
630
     *    are inappropriate for the requested algorithm
 
631
     * @throws NoSuchAlgorithmException if an implementation of the
 
632
     *    specified algorithm cannot be found
 
633
     * @throws NullPointerException if <code>algorithm</code> is 
 
634
     *    <code>null</code>
 
635
     */
 
636
    public abstract Transform newTransform(String algorithm, 
 
637
        TransformParameterSpec params) throws NoSuchAlgorithmException,
 
638
        InvalidAlgorithmParameterException;
 
639
 
 
640
    /**
 
641
     * Creates a <code>Transform</code> for the specified algorithm URI 
 
642
     * and parameters. The parameters are specified as a mechanism-specific
 
643
     * <code>XMLStructure</code> (ex: {@link DOMStructure}). This method is 
 
644
     * useful when the parameters are in XML form or there is no standard 
 
645
     * class for specifying the parameters.
 
646
     *
 
647
     * @param algorithm the URI identifying the transform algorithm
 
648
     * @param params a mechanism-specific XML structure from which to
 
649
     *   unmarshal the parameters from (may be <code>null</code> if
 
650
     *   not required or optional)
 
651
     * @return the <code>Transform</code>
 
652
     * @throws ClassCastException if the type of <code>params</code> is
 
653
     *   inappropriate for this <code>XMLSignatureFactory</code>
 
654
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
655
     *    are inappropriate for the requested algorithm
 
656
     * @throws NoSuchAlgorithmException if an implementation of the
 
657
     *    specified algorithm cannot be found
 
658
     * @throws NullPointerException if <code>algorithm</code> is 
 
659
     *    <code>null</code>
 
660
     */
 
661
    public abstract Transform newTransform(String algorithm, 
 
662
        XMLStructure params) throws NoSuchAlgorithmException,
 
663
        InvalidAlgorithmParameterException;
 
664
 
 
665
    /**
 
666
     * Creates a <code>CanonicalizationMethod</code> for the specified 
 
667
     * algorithm URI and parameters.
 
668
     *
 
669
     * @param algorithm the URI identifying the canonicalization algorithm
 
670
     * @param params algorithm-specific canonicalization parameters (may be 
 
671
     *    <code>null</code>)
 
672
     * @return the <code>CanonicalizationMethod</code>
 
673
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
674
     *    are inappropriate for the requested algorithm
 
675
     * @throws NoSuchAlgorithmException if an implementation of the
 
676
     *    specified algorithm cannot be found
 
677
     * @throws NullPointerException if <code>algorithm</code> is 
 
678
     *    <code>null</code>
 
679
     */
 
680
    public abstract CanonicalizationMethod newCanonicalizationMethod(
 
681
        String algorithm, C14NMethodParameterSpec params) 
 
682
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException;
 
683
 
 
684
    /**
 
685
     * Creates a <code>CanonicalizationMethod</code> for the specified 
 
686
     * algorithm URI and parameters. The parameters are specified as a 
 
687
     * mechanism-specific <code>XMLStructure</code> (ex: {@link DOMStructure}). 
 
688
     * This method is useful when the parameters are in XML form or there is 
 
689
     * no standard class for specifying the parameters.
 
690
     *
 
691
     * @param algorithm the URI identifying the canonicalization algorithm
 
692
     * @param params a mechanism-specific XML structure from which to
 
693
     *   unmarshal the parameters from (may be <code>null</code> if
 
694
     *   not required or optional)
 
695
     * @return the <code>CanonicalizationMethod</code>
 
696
     * @throws ClassCastException if the type of <code>params</code> is
 
697
     *   inappropriate for this <code>XMLSignatureFactory</code>
 
698
     * @throws InvalidAlgorithmParameterException if the specified parameters
 
699
     *    are inappropriate for the requested algorithm
 
700
     * @throws NoSuchAlgorithmException if an implementation of the
 
701
     *    specified algorithm cannot be found
 
702
     * @throws NullPointerException if <code>algorithm</code> is 
 
703
     *    <code>null</code>
 
704
     */
 
705
    public abstract CanonicalizationMethod newCanonicalizationMethod(
 
706
        String algorithm, XMLStructure params) 
 
707
        throws NoSuchAlgorithmException, InvalidAlgorithmParameterException;
 
708
 
 
709
    /**
 
710
     * Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
 
711
     * objects. The returned <code>KeyInfoFactory</code> has the same 
 
712
     * mechanism type and provider as this <code>XMLSignatureFactory</code>.
 
713
     *
 
714
     * @return a <code>KeyInfoFactory</code>
 
715
     * @throws NoSuchMechanismException if a <code>KeyFactory</code> 
 
716
     *    implementation with the same mechanism type and provider
 
717
     *    is not available
 
718
     */
 
719
    public final KeyInfoFactory getKeyInfoFactory() {
 
720
        return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
 
721
    }
 
722
 
 
723
    /**
 
724
     * Unmarshals a new <code>XMLSignature</code> instance from a
 
725
     * mechanism-specific <code>XMLValidateContext</code> instance.
 
726
     *
 
727
     * @param context a mechanism-specific context from which to unmarshal the
 
728
     *    signature from
 
729
     * @return the <code>XMLSignature</code>
 
730
     * @throws NullPointerException if <code>context</code> is 
 
731
     *    <code>null</code>
 
732
     * @throws ClassCastException if the type of <code>context</code> is
 
733
     *    inappropriate for this factory
 
734
     * @throws MarshalException if an unrecoverable exception occurs 
 
735
     *    during unmarshalling
 
736
     */
 
737
    public abstract XMLSignature unmarshalXMLSignature
 
738
        (XMLValidateContext context) throws MarshalException;
 
739
 
 
740
    /**
 
741
     * Unmarshals a new <code>XMLSignature</code> instance from a
 
742
     * mechanism-specific <code>XMLStructure</code> instance.
 
743
     * This method is useful if you only want to unmarshal (and not
 
744
     * validate) an <code>XMLSignature</code>.
 
745
     *
 
746
     * @param xmlStructure a mechanism-specific XML structure from which to 
 
747
     *    unmarshal the signature from
 
748
     * @return the <code>XMLSignature</code>
 
749
     * @throws NullPointerException if <code>xmlStructure</code> is 
 
750
     *    <code>null</code>
 
751
     * @throws ClassCastException if the type of <code>xmlStructure</code> is
 
752
     *    inappropriate for this factory
 
753
     * @throws MarshalException if an unrecoverable exception occurs 
 
754
     *    during unmarshalling
 
755
     */
 
756
    public abstract XMLSignature unmarshalXMLSignature
 
757
        (XMLStructure xmlStructure) throws MarshalException;
 
758
 
 
759
    /**
 
760
     * Indicates whether a specified feature is supported.
 
761
     *
 
762
     * @param feature the feature name (as an absolute URI)
 
763
     * @return <code>true</code> if the specified feature is supported,
 
764
     *    <code>false</code> otherwise
 
765
     * @throws NullPointerException if <code>feature</code> is <code>null</code>
 
766
     */
 
767
    public abstract boolean isFeatureSupported(String feature);
 
768
 
 
769
    /**
 
770
     * Returns a reference to the <code>URIDereferencer</code> that is used by 
 
771
     * default to dereference URIs in {@link Reference} objects.
 
772
     *
 
773
     * @return a reference to the default <code>URIDereferencer</code> (never
 
774
     *    <code>null</code>)
 
775
     */
 
776
    public abstract URIDereferencer getURIDereferencer();
 
777
}