01: /*
02: * $Id: ImageCanonicalizer.java,v 1.4 2007/01/08 09:28:48 ashutoshshahi Exp $
03: * $Revision: 1.4 $
04: * $Date: 2007/01/08 09:28:48 $
05: */
06:
07: /*
08: * The contents of this file are subject to the terms
09: * of the Common Development and Distribution License
10: * (the License). You may not use this file except in
11: * compliance with the License.
12: *
13: * You can obtain a copy of the license at
14: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
15: * See the License for the specific language governing
16: * permissions and limitations under the License.
17: *
18: * When distributing Covered Code, include this CDDL
19: * Header Notice in each file and include the License file
20: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
21: * If applicable, add the following below the CDDL Header,
22: * with the fields enclosed by brackets [] replaced by
23: * you own identifying information:
24: * "Portions Copyrighted [year] [name of copyright owner]"
25: *
26: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
27: */
28:
29: package com.sun.xml.wss.impl.c14n;
30:
31: import com.sun.xml.wss.XWSSecurityException;
32: import java.io.InputStream;
33: import java.io.OutputStream;
34: import java.util.logging.Level;
35:
36: /**
37: * Section 4.2 on Image Media types in RFC 2046
38: * http://www.rfc-editor.org/rfc/rfc2046.txt
39: * does not specify any rules for image canonicalization.
40: *
41: * So assuming that this binary data need not be canonicalized.
42: *
43: * @author XWS-Security Team
44: */
45: public class ImageCanonicalizer extends Canonicalizer {
46:
47: public ImageCanonicalizer() {
48: }
49:
50: public ImageCanonicalizer(String charset) {
51: super (charset);
52: }
53:
54: /*
55: * RFC 3851 says - http://www.rfc-archive.org/getrfc.php?rfc=3851
56: * Other than text types, most types
57: * have only one representation regardless of computing platform or
58: * environment which can be considered their canonical representation.
59: *
60: * So right now we are just serializing the attachment for gif data types.
61: *
62: */
63: public byte[] canonicalize(byte[] input)
64: throws XWSSecurityException {
65: return input;
66: }
67:
68: public InputStream canonicalize(InputStream input,
69: OutputStream outputStream)
70: throws javax.xml.crypto.dsig.TransformException {
71: try {
72: if (outputStream == null) {
73: return input;
74: } else {
75: byte[] data = new byte[128];
76: while (true) {
77: int len = input.read(data);
78: if (len <= 0)
79: break;
80: outputStream.write(data, 0, len);
81: }
82: }
83: } catch (Exception ex) {
84: log.log(Level.SEVERE, "WSS1001.error.canonicalizing.image",
85: new Object[] { ex.getMessage() });
86: throw new javax.xml.crypto.dsig.TransformException(ex
87: .getMessage());
88: }
89: return null;
90: }
91: }
|