comparison dcrypt/misc/ByteConverter.d @ 28:ad687db713a4

Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author Thomas Dixon <reikon@reikon.us>
date Sun, 10 May 2009 22:38:48 -0400
parents 6428dfd7fede
children b9ba770b8f16
comparison
equal deleted inserted replaced
27:8b5eaf3c2979 28:ad687db713a4
8 8
9 module dcrypt.misc.ByteConverter; 9 module dcrypt.misc.ByteConverter;
10 10
11 /** Converts between integral types and unsigned byte arrays */ 11 /** Converts between integral types and unsigned byte arrays */
12 struct ByteConverter { 12 struct ByteConverter {
13 private static const char[] hexits = "0123456789abcdef"; 13 private static const string hexits = "0123456789abcdef";
14 14
15 /** Conversions between little endian integrals and bytes */ 15 /** Conversions between little endian integrals and bytes */
16 struct LittleEndian { 16 struct LittleEndian {
17 /** 17 /**
18 * Converts the supplied array to integral type T 18 * Converts the supplied array to integral type T
126 } 126 }
127 return output; 127 return output;
128 } 128 }
129 } 129 }
130 130
131 static char[] hexEncode(void[] input_) { 131 static string hexEncode(void[] input_) {
132 ubyte[] input = cast(ubyte[])input_; 132 ubyte[] input = cast(ubyte[])input_;
133 char[] output = new char[input.length<<1]; 133 string output = new char[input.length<<1];
134 134
135 int i = 0; 135 int i = 0;
136 foreach (ubyte j; input) { 136 foreach (ubyte j; input) {
137 output[i++] = hexits[j>>4]; 137 output[i++] = hexits[j>>4];
138 output[i++] = hexits[j&0xf]; 138 output[i++] = hexits[j&0xf];
139 } 139 }
140 return output; 140 return output;
141 } 141 }
142 142
143 static ubyte[] hexDecode(char[] input) { 143 static ubyte[] hexDecode(string input) {
144 ubyte[] output = new ubyte[input.length>>1]; 144 ubyte[] output = new ubyte[input.length>>1];
145 145
146 static ubyte[char] hexitIndex; 146 static ubyte[char] hexitIndex;
147 for (int i = 0; i < hexits.length; i++) 147 for (int i = 0; i < hexits.length; i++)
148 hexitIndex[hexits[i]] = i; 148 hexitIndex[hexits[i]] = i;