Commits

Jeff Hardy committed 797d814

Fiz adler32 and crc32 implementations.

Comments (0)

Files changed (1)

IronPython.Zlib/ZlibModule.cs

 
         #region adler32
 
-        public static long adler32(string data)
+        public static int adler32(string data, [DefaultParameterValue(1L)] long baseValue)
         {
-            return adler32(data, 0);
+            return adler32(Latin1.GetBytes(data), baseValue);
         }
 
-        public static long adler32(string data, uint value)
+        public static int adler32(byte[] data, [DefaultParameterValue(1L)] long baseValue)
         {
-            byte[] bytes = Latin1.GetBytes(data);
-            return Adler32.GetAdler32Checksum(value, bytes, 0, bytes.Length);
+            return (int)Adler32.GetAdler32Checksum(baseValue, data, 0, data.Length);
         }
 
         #endregion
 
         #region crc32
 
-        public static int crc32(string data, [DefaultParameterValue(0)] int baseValue)
+        public static int crc32(string data, [DefaultParameterValue(0L)] long baseValue)
         {
-            return IronPython.Modules.PythonBinaryAscii.crc32(data, baseValue);
+            if(baseValue < int.MinValue || baseValue > uint.MaxValue)
+                throw new ArgumentOutOfRangeException("baseValue");
+
+            if(baseValue >= 0 && baseValue <= uint.MaxValue)
+                return IronPython.Modules.PythonBinaryAscii.crc32(data, (uint)baseValue);
+            else
+                return IronPython.Modules.PythonBinaryAscii.crc32(data, (int)baseValue);
         }
 
-        public static int crc32(string data, uint baseValue)
+        public static int crc32(byte[] data, [DefaultParameterValue(0L)] long baseValue)
         {
-            return IronPython.Modules.PythonBinaryAscii.crc32(data, baseValue);
+            if(baseValue < int.MinValue || baseValue > uint.MaxValue)
+                throw new ArgumentOutOfRangeException("baseValue");
+
+            if(baseValue >= 0 && baseValue <= uint.MaxValue)
+                return IronPython.Modules.PythonBinaryAscii.crc32(data, (uint)baseValue);
+            else
+                return IronPython.Modules.PythonBinaryAscii.crc32(data, (int)baseValue);
         }
 
         #endregion