1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/**
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 */
23package com.sun.org.apache.xml.internal.security.algorithms;
24
25import java.security.Key;
26import java.security.SecureRandom;
27import java.security.spec.AlgorithmParameterSpec;
28
29import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
30import org.w3c.dom.Element;
31
32public abstract class SignatureAlgorithmSpi {
33
34    /**
35     * Returns the URI representation of <code>Transformation algorithm</code>
36     *
37     * @return the URI representation of <code>Transformation algorithm</code>
38     */
39    protected abstract String engineGetURI();
40
41    /**
42     * Proxy method for {@link java.security.Signature#getAlgorithm}
43     * which is executed on the internal {@link java.security.Signature} object.
44     *
45     * @return the result of the {@link java.security.Signature#getAlgorithm} method
46     */
47    protected abstract String engineGetJCEAlgorithmString();
48
49    /**
50     * Method engineGetJCEProviderName
51     *
52     * @return the JCE ProviderName
53     */
54    protected abstract String engineGetJCEProviderName();
55
56    /**
57     * Proxy method for {@link java.security.Signature#update(byte[])}
58     * which is executed on the internal {@link java.security.Signature} object.
59     *
60     * @param input
61     * @throws XMLSignatureException
62     */
63    protected abstract void engineUpdate(byte[] input) throws XMLSignatureException;
64
65    /**
66     * Proxy method for {@link java.security.Signature#update(byte[])}
67     * which is executed on the internal {@link java.security.Signature} object.
68     *
69     * @param input
70     * @throws XMLSignatureException
71     */
72    protected abstract void engineUpdate(byte input) throws XMLSignatureException;
73
74    /**
75     * Proxy method for {@link java.security.Signature#update(byte[], int, int)}
76     * which is executed on the internal {@link java.security.Signature} object.
77     *
78     * @param buf
79     * @param offset
80     * @param len
81     * @throws XMLSignatureException
82     */
83    protected abstract void engineUpdate(byte buf[], int offset, int len)
84        throws XMLSignatureException;
85
86    /**
87     * Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)}
88     * which is executed on the internal {@link java.security.Signature} object.
89     *
90     * @param signingKey
91     * @throws XMLSignatureException if this method is called on a MAC
92     */
93    protected abstract void engineInitSign(Key signingKey) throws XMLSignatureException;
94
95    /**
96     * Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey,
97     * java.security.SecureRandom)}
98     * which is executed on the internal {@link java.security.Signature} object.
99     *
100     * @param signingKey
101     * @param secureRandom
102     * @throws XMLSignatureException if this method is called on a MAC
103     */
104    protected abstract void engineInitSign(Key signingKey, SecureRandom secureRandom)
105        throws XMLSignatureException;
106
107    /**
108     * Proxy method for {@link javax.crypto.Mac}
109     * which is executed on the internal {@link javax.crypto.Mac#init(Key)} object.
110     *
111     * @param signingKey
112     * @param algorithmParameterSpec
113     * @throws XMLSignatureException if this method is called on a Signature
114     */
115    protected abstract void engineInitSign(
116        Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
117    ) throws XMLSignatureException;
118
119    /**
120     * Proxy method for {@link java.security.Signature#sign()}
121     * which is executed on the internal {@link java.security.Signature} object.
122     *
123     * @return the result of the {@link java.security.Signature#sign()} method
124     * @throws XMLSignatureException
125     */
126    protected abstract byte[] engineSign() throws XMLSignatureException;
127
128    /**
129     * Method engineInitVerify
130     *
131     * @param verificationKey
132     * @throws XMLSignatureException
133     */
134    protected abstract void engineInitVerify(Key verificationKey) throws XMLSignatureException;
135
136    /**
137     * Proxy method for {@link java.security.Signature#verify(byte[])}
138     * which is executed on the internal {@link java.security.Signature} object.
139     *
140     * @param signature
141     * @return true if the signature is correct
142     * @throws XMLSignatureException
143     */
144    protected abstract boolean engineVerify(byte[] signature) throws XMLSignatureException;
145
146    /**
147     * Proxy method for {@link java.security.Signature#setParameter(
148     * java.security.spec.AlgorithmParameterSpec)}
149     * which is executed on the internal {@link java.security.Signature} object.
150     *
151     * @param params
152     * @throws XMLSignatureException
153     */
154    protected abstract void engineSetParameter(AlgorithmParameterSpec params)
155        throws XMLSignatureException;
156
157
158    /**
159     * Method engineGetContextFromElement
160     *
161     * @param element
162     */
163    protected void engineGetContextFromElement(Element element) {
164    }
165
166    /**
167     * Method engineSetHMACOutputLength
168     *
169     * @param HMACOutputLength
170     * @throws XMLSignatureException
171     */
172    protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
173        throws XMLSignatureException;
174
175    public void reset() {
176    }
177}
178