blob: fe3d46a18c27f2a7b8e64e4bc40c178600616b7d [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Copyright 1999-2005 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * 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 */
24package org.jcp.xml.dsig.internal;
25
26import java.io.ByteArrayOutputStream;
27import java.security.Signature;
28import 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 */
37public 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}