Commits

Jeff Hardy  committed 2f2ba64

- Add license information
- Replace crc32 implementation

  • Participants
  • Parent commits b00168f

Comments (0)

Files changed (8)

File IronPython.Zlib/Compress.cs

-using System;
+/* ****************************************************************************
+ *
+ * Copyright (c) Jeff Hardy 2007-2008.
+ *
+ * This source code is subject to terms and conditions of the Microsoft Public License. A 
+ * copy of the license can be found in the License.txt file at the root of this distribution. If 
+ * you cannot locate the  Microsoft Public License, please send an email to 
+ * jdhardy@gmail.com. By using this source code in any fashion, you are agreeing to be bound 
+ * by the terms of the Microsoft Public License.
+ *
+ * You must not remove this notice, or any other, from this software.
+ *
+ * ***************************************************************************/
+
+using System;
 using System.Collections.Generic;
 using System.Text;
 using IronPython.Runtime;

File IronPython.Zlib/Crc32.cs

-using System;
-using System.Security.Cryptography;
+/*
+ * Based on example code from the W3C.
+ * http://www.w3.org/TR/PNG/#D-CRCAppendix
+ * 
+ */
+
+using System;
 
 namespace IronPython.Zlib
 {
-    public class Crc32 : HashAlgorithm
+    public static class Crc32
     {
-        public const UInt32 DefaultPolynomial = 0xedb88320;
-        public const UInt32 DefaultSeed = 0xffffffff;
-
-        private UInt32 hash;
-        private UInt32 seed;
-        private UInt32[] table;
-
-        public Crc32()
+        public static uint Calculate(uint crc, byte[] buf)
         {
-            table = InitializeTable(DefaultPolynomial);
-            seed = DefaultSeed;
-            Initialize();
+            uint c = crc;
+            
+            for(int n = 0; n < buf.Length; n++)
+            {
+                c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
+            }
+            
+            return c;
         }
 
-        public Crc32(UInt32 polynomial, UInt32 seed)
+        static Crc32()
         {
-            table = InitializeTable(polynomial);
-            this.seed = seed;
-            Initialize();
+            for(uint n = 0; n < 256; n++)
+            {
+                uint c = n;
+                for(int k = 0; k < 8; k++)
+                {
+                    if((c & 1) != 0)
+                        c = 0xedb88320 ^ (c >> 1);
+                    else
+                        c = c >> 1;
+                }
+                crc_table[n] = c;
+            }
         }
 
-        public override void Initialize()
-        {
-            hash = seed;
-        }
-
-        protected override void HashCore(byte[] buffer, int start, int length)
-        {
-            hash = CalculateHash(table, hash, buffer, start, length);
-        }
-
-        protected override byte[] HashFinal()
-        {
-            byte[] hashBuffer = UInt32ToBigEndianBytes(hash);
-            this.HashValue = hashBuffer;
-            return hashBuffer;
-        }
-
-        public override int HashSize
-        {
-            get { return 32; }
-        }
-
-        public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer)
-        {
-            return CalculateHash(InitializeTable(polynomial), ~seed, buffer, 0, buffer.Length);
-        }
-
-        private static UInt32[] InitializeTable(UInt32 polynomial)
-        {
-            UInt32[] createTable = new UInt32[256];
-            for(int i = 0; i < 256; i++)
-            {
-                UInt32 entry = (UInt32)i;
-                for(int j = 0; j < 8; j++)
-                    if((entry & 1) == 1)
-                        entry = (entry >> 1) ^ polynomial;
-                    else
-                        entry = entry >> 1;
-                createTable[i] = entry;
-            }
-            return createTable;
-        }
-
-        private static UInt32 CalculateHash(UInt32[] table, UInt32 seed, byte[] buffer, int start, int size)
-        {
-            UInt32 crc = seed;
-            for(int i = start; i < size; i++)
-                unchecked
-                {
-                    crc = (crc >> 8) ^ table[buffer[i] ^ crc & 0xff];
-                }
-            return ~crc;
-        }
-
-        private byte[] UInt32ToBigEndianBytes(UInt32 x)
-        {
-            return new byte[] {
-			(byte)((x >> 24) & 0xff),
-			(byte)((x >> 16) & 0xff),
-			(byte)((x >> 8) & 0xff),
-			(byte)(x & 0xff)
-		};
-        }
+        private static readonly uint[] crc_table = new uint[256];
     }
 }

File IronPython.Zlib/Decompress.cs

-using System;
+/* ****************************************************************************
+ *
+ * Copyright (c) Jeff Hardy 2007-2008.
+ *
+ * This source code is subject to terms and conditions of the Microsoft Public License. A 
+ * copy of the license can be found in the License.txt file at the root of this distribution. If 
+ * you cannot locate the  Microsoft Public License, please send an email to 
+ * jdhardy@gmail.com. By using this source code in any fashion, you are agreeing to be bound 
+ * by the terms of the Microsoft Public License.
+ *
+ * You must not remove this notice, or any other, from this software.
+ *
+ * ***************************************************************************/
+
+using System;
 using System.Collections.Generic;
 using System.Text;
 using IronPython.Runtime;

File IronPython.Zlib/IronPython.Zlib.suo

Binary file modified.

File IronPython.Zlib/Properties/AssemblyInfo.cs

 [assembly: AssemblyTitle("IronPython.Zlib")]
 [assembly: AssemblyDescription("")]
 [assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyCompany("Jeff Hardy")]
 [assembly: AssemblyProduct("IronPython.Zlib")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2008")]
+[assembly: AssemblyCopyright("Copyright © Jeff Hardy 2008")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 

File IronPython.Zlib/ZlibModule.cs

-using System;
+/* ****************************************************************************
+ *
+ * Copyright (c) Jeff Hardy 2007-2008.
+ *
+ * This source code is subject to terms and conditions of the Microsoft Public License. A 
+ * copy of the license can be found in the License.txt file at the root of this distribution. If 
+ * you cannot locate the  Microsoft Public License, please send an email to 
+ * jdhardy@gmail.com. By using this source code in any fashion, you are agreeing to be bound 
+ * by the terms of the Microsoft Public License.
+ *
+ * You must not remove this notice, or any other, from this software.
+ *
+ * ***************************************************************************/
+
+using System;
 using System.Collections.Generic;
 using System.Text;
 using IronPython.Runtime;
 
         public static int crc32(string data, uint value)
         {
-            return (int)Crc32.Compute(Crc32.DefaultPolynomial, value, Latin1.GetBytes(data));
+            return (int)Crc32.Calculate(value, Latin1.GetBytes(data));
         }
 
         #endregion

File IronPython.Zlib/license.txt

+IronPYthon.Zlib
+===============
+Copyright (c) 2008 Jeff Hardy
+
+Microsoft Public License (Ms-PL)
+This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software.
+
+Definitions
+The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. A "contribution" is the original software, or any additions or changes to the software. A "contributor" is any person that distributes its contribution under this license. "Licensed patents" are a contributor's patent claims that read directly on its contribution.
+Grant of Rights
+(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
+(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
+Conditions and Limitations
+(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 
+(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 
+(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 
+(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 
+(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
+
+zlib.net
+========
+Copyright (c) 2006, ComponentAce
+http://www.componentace.com
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 
+Neither the name of ComponentAce nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+Copyright (c) 2000,2001,2002,2003 ymnk, JCraft,Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright 
+notice, this list of conditions and the following disclaimer in 
+the documentation and/or other materials provided with the distribution.
+
+3. The names of the authors may not be used to endorse or promote products
+derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

File IronPython.Zlib/readme.txt

+IronPYthon.Zlib
+===============
+
+Create the "DLLs" folder under your IronPython installation and drop IronPython.Zlib.dll into it. The zlib module will now be available for import.
+
+- Jeff Hardy