Skip to content

Commit 2144daf

Browse files
Don't use BitConverter
Since `BitConverter.IsLittleEndian` changes on a per-system basis, we should just put a little endian implementation in play. Now the values are always deterministic on all systems.
1 parent 0bae34a commit 2144daf

File tree

1 file changed

+10
-1
lines changed
  • src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers

1 file changed

+10
-1
lines changed

src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/CRC64.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ protected override void HashCore (byte [] array, int ibStart, int cbSize)
151151
}
152152
}
153153

154-
protected override byte [] HashFinal () => BitConverter.GetBytes (crc);
154+
protected override byte [] HashFinal ()
155+
{
156+
// Equivalent to BitConverter.GetBytes(crc), but *always* little endian
157+
const int length = 8;
158+
byte [] bytes = new byte [length];
159+
for (int index = 0; index < length; index++) {
160+
bytes [index] = (byte) (crc >> (8 * index) & 0xFF);
161+
}
162+
return bytes;
163+
}
155164
}
156165
}

0 commit comments

Comments
 (0)