01: /*
02: * Copyright 1999-2005 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: * The contents of this file are subject to the terms
19: * of the Common Development and Distribution License
20: * (the License). You may not use this file except in
21: * compliance with the License.
22: *
23: * You can obtain a copy of the license at
24: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
25: * See the License for the specific language governing
26: * permissions and limitations under the License.
27: *
28: * When distributing Covered Code, include this CDDL
29: * Header Notice in each file and include the License file
30: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
31: * If applicable, add the following below the CDDL Header,
32: * with the fields enclosed by brackets [] replaced by
33: * you own identifying information:
34: * "Portions Copyrighted [year] [name of copyright owner]"
35: *
36: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
37: */
38: /*
39: * $Id: SignerOutputStream.java,v 1.1 2006/10/13 13:08:24 ashutoshshahi Exp $
40: */
41: package com.sun.xml.ws.security.opt.crypto.dsig.internal;
42:
43: import java.io.ByteArrayOutputStream;
44: import java.security.Signature;
45: import java.security.SignatureException;
46:
47: /**
48: * Derived from Apache sources and changed to use java.security.Signature
49: * objects as input instead of org.apache.xml.security.algorithms.SignatureAlgorithm
50: * objects.
51: *
52: * @author raul
53: * @author Sean Mullan
54: */
55: public class SignerOutputStream extends ByteArrayOutputStream {
56: private final Signature sig;
57:
58: public SignerOutputStream(Signature sig) {
59: this .sig = sig;
60: }
61:
62: /** @inheritDoc */
63: public void write(byte[] arg0) {
64: super .write(arg0, 0, arg0.length);
65: try {
66: sig.update(arg0);
67: } catch (SignatureException e) {
68: throw new RuntimeException("" + e);
69: }
70: }
71:
72: /** @inheritDoc */
73: public void write(int arg0) {
74: super .write(arg0);
75: try {
76: sig.update((byte) arg0);
77: } catch (SignatureException e) {
78: throw new RuntimeException("" + e);
79: }
80: }
81:
82: /** @inheritDoc */
83: public void write(byte[] arg0, int arg1, int arg2) {
84: super .write(arg0, arg1, arg2);
85: try {
86: sig.update(arg0, arg1, arg2);
87: } catch (SignatureException e) {
88: throw new RuntimeException("" + e);
89: }
90: }
91: }
|