01: /*
02: * reserved comment block
03: * DO NOT REMOVE OR ALTER!
04: */
05: /*
06: * Copyright 1999-2005 The Apache Software Foundation.
07: *
08: * Licensed under the Apache License, Version 2.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: */
21: /*
22: * $Id: SignerOutputStream.java,v 1.1.2.2 2005/08/12 18:01:58 mullan Exp $
23: */
24: package org.jcp.xml.dsig.internal;
25:
26: import java.io.ByteArrayOutputStream;
27: import java.security.Signature;
28: import java.security.SignatureException;
29:
30: /**
31: * Derived from Apache sources and changed to use java.security.Signature
32: * objects as input instead of org.apache.xml.security.algorithms.SignatureAlgorithm
33: * objects.
34: *
35: * @author raul
36: */
37: public class SignerOutputStream extends ByteArrayOutputStream {
38: private final Signature sig;
39:
40: public SignerOutputStream(Signature sig) {
41: this .sig = sig;
42: }
43:
44: /** @inheritDoc */
45: public void write(byte[] arg0) {
46: super .write(arg0, 0, arg0.length);
47: try {
48: sig.update(arg0);
49: } catch (SignatureException e) {
50: throw new RuntimeException("" + e);
51: }
52: }
53:
54: /** @inheritDoc */
55: public void write(int arg0) {
56: super .write(arg0);
57: try {
58: sig.update((byte) arg0);
59: } catch (SignatureException e) {
60: throw new RuntimeException("" + e);
61: }
62: }
63:
64: /** @inheritDoc */
65: public void write(byte[] arg0, int arg1, int arg2) {
66: super .write(arg0, arg1, arg2);
67: try {
68: sig.update(arg0, arg1, arg2);
69: } catch (SignatureException e) {
70: throw new RuntimeException("" + e);
71: }
72: }
73: }
|