Clover Coverage Report
Coverage timestamp: Sun Mar 23 2008 08:24:39 GMT
52   208   9   4.73
16   95   0.37   11
11     1.73  
1    
 
 
  utility       Line # 72 52 9 68.4% 0.6835443
 
No Tests
 
1    /*
2    * Copyright (c) 2006, University of Kent
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * Redistributions of source code must retain the above copyright notice, this
9    * list of conditions and the following disclaimer.
10    *
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14    *
15    * 1. Neither the name of the University of Kent nor the names of its
16    * contributors may be used to endorse or promote products derived from this
17    * software without specific prior written permission.
18    *
19    * 2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22    * PURPOSE ARE DISCLAIMED.
23    *
24    * 3. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    * POSSIBILITY OF SUCH DAMAGE.
32    *
33    * 4. YOU AGREE THAT THE EXCLUSIONS IN PARAGRAPHS 2 AND 3 ABOVE ARE REASONABLE
34    * IN THE CIRCUMSTANCES. IN PARTICULAR, YOU ACKNOWLEDGE (1) THAT THIS
35    * SOFTWARE HAS BEEN MADE AVAILABLE TO YOU FREE OF CHARGE, (2) THAT THIS
36    * SOFTWARE IS NOT "PRODUCT" QUALITY, BUT HAS BEEN PRODUCED BY A RESEARCH
37    * GROUP WHO DESIRE TO MAKE THIS SOFTWARE FREELY AVAILABLE TO PEOPLE WHO WISH
38    * TO USE IT, AND (3) THAT BECAUSE THIS SOFTWARE IS NOT OF "PRODUCT" QUALITY
39    * IT IS INEVITABLE THAT THERE WILL BE BUGS AND ERRORS, AND POSSIBLY MORE
40    * SERIOUS FAULTS, IN THIS SOFTWARE.
41    *
42    * 5. This license is governed, except to the extent that local laws
43    * necessarily apply, by the laws of England and Wales.
44    */
45   
46    package issrg.SAWS;
47   
48    import java.io.*;
49    import java.util.*;
50   
51    /*
52    import java.net.*;
53    import org.apache.soap.*;
54    import org.apache.soap.encoding.*;
55    import org.apache.soap.encoding.soapenc.*;
56    import org.apache.soap.rpc.*;
57    */
58   
59    import org.w3c.dom.*;
60    import org.xml.sax.*;
61    import javax.xml.parsers.*;
62    import org.apache.soap.util.xml.*;
63   
64   
65   
66    import java.security.*;
67    import javax.crypto.*;
68    import java.security.AlgorithmParameters;
69    import java.security.interfaces.*;
70   
71   
 
72    public class utility
73    {
74   
75   
 
76  0 toggle public static byte intToByte(int value) {
77  0 byte b = (byte) (value & 0xFF);
78  0 return b;
79    }
80   
 
81  0 toggle public static int byteToInt(byte b) {
82  0 int value = 0;
83  0 value = (b & 0x000000FF);
84  0 return value;
85    }
86   
 
87  242 toggle public static byte[] longToByteArray(long value) {
88  242 byte[] b = new byte[8];
89  2178 for (int i = 0; i < 8; i++) {
90  1936 int offset = (b.length - 1 - i) * 8;
91  1936 b[i] = (byte) ((value >>> offset) & 0xFF);
92    }
93  242 return b;
94    }
95   
 
96  540 toggle public static long byteArrayToLong(byte[] b) {
97    // return byteArrayToLong(b, 0);
98  540 long value = 0;
99  4860 for (int i = 0; i < 8; i++) {
100  4320 int shift = (7 - i) * 8;
101  4320 value += (long)( (long)(b[i] & 0x00000000000000FF) << shift );
102    //System.out.println("utility: long byteArrayToLong(): current value of round "+ i + "= " + value);
103    //System.out.println("shift=" + shift+"; b[" + i + "]=" + b[i] + ";(b[i] & 0x00000000000000FF)=" + (long)(b[i] & 0x00000000000000FF) + "; (long)( (b[i] & 0x00000000000000FF) << shift )= " + (long)( (b[i] & 0x00000000000000FF) << shift ) );
104    }
105  540 return value;
106   
107    }
108   
109    /**
110    * Convert the byte array to a long starting from the given offset.
111    *
112    * @param b The byte array
113    * @param offset The array offset
114    * @return The long
115    */
 
116  0 toggle public static long byteArrayToLong(byte[] b, int offset) {
117  0 long value = 0;
118  0 for (int i = 0; i < 8; i++) {
119  0 int shift = (8 - 1 - i) * 8;
120  0 value += ( (long)(b[i + offset] & 0x00000000000000FF) << shift );
121    }
122  0 return value;
123    }
124   
125   
 
126  675 toggle public static byte[] intToByteArray(int value) {
127  675 byte[] b = new byte[4];
128  3375 for (int i = 0; i < 4; i++) {
129  2700 int offset = (b.length - 1 - i) * 8;
130  2700 b[i] = (byte) ((value >>> offset) & 0xFF);
131    }
132  675 return b;
133    }
134   
135   
136    /**
137    * Convert the byte array to an int.
138    *
139    * @param b The byte array
140    * @return The integer
141    */
 
142  1788 toggle public static int byteArrayToInt(byte[] b) {
143  1788 return byteArrayToInt(b, 0);
144    }
145   
146    /**
147    * Convert the byte array to an int starting from the given offset.
148    *
149    * @param b The byte array, b[0] is the highest digit
150    * @param offset The array offset
151    * @return The integer
152    */
 
153  1788 toggle public static int byteArrayToInt(byte[] b, int offset) {
154  1788 int value = 0;
155  8940 for (int i = 0; i < 4; i++) {
156  7152 int shift = (4 - 1 - i) * 8;
157  7152 value += (b[i + offset] & 0x000000FF) << shift;
158    }
159  1788 return value;
160    }
161   
162   
163    /*
164    * Converts a byte to hex digit and return the result
165    */
 
166  0 toggle public static String byte2hex(byte b) {
167  0 StringBuffer buf = new StringBuffer();
168  0 char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
169    '9', 'A', 'B', 'C', 'D', 'E', 'F' };
170  0 int high = ((b & 0xf0) >> 4);
171  0 int low = (b & 0x0f);
172  0 buf.append(hexChars[high]);
173  0 buf.append(hexChars[low]);
174  0 return(buf.toString());
175    }
176   
177    /*
178    * Converts a byte to hex digit and writes to the supplied buffer
179    */
 
180  120 toggle public static void byte2hex(byte b, StringBuffer buf) {
181  120 char[] hexChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
182    '9', 'A', 'B', 'C', 'D', 'E', 'F' };
183  120 int high = ((b & 0xf0) >> 4);
184  120 int low = (b & 0x0f);
185  120 buf.append(hexChars[high]);
186  120 buf.append(hexChars[low]);
187    }
188   
189    /*
190    * Converts a byte array to hex string
191    */
 
192  6 toggle public static String toHexString(byte[] block) {
193   
194  0 if (block == null) return null;
195  6 StringBuffer buf = new StringBuffer();
196   
197  6 int len = block.length;
198   
199  126 for (int i = 0; i < len; i++) {
200  120 byte2hex(block[i], buf);
201  120 if (i < len-1) {
202  114 buf.append(":");
203    }
204    }
205  6 return buf.toString();
206    }
207   
208    }