123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- using System;
- namespace CommonMPQ.SharpZipLib.Checksums
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public sealed class Adler32 : IChecksum
- {
-
-
-
- const uint BASE = 65521;
-
-
-
-
- public long Value {
- get {
- return checksum;
- }
- }
-
-
-
-
-
- public Adler32()
- {
- Reset();
- }
-
-
-
-
- public void Reset()
- {
- checksum = 1;
- }
-
-
-
-
-
-
-
- public void Update(int value)
- {
-
-
- uint s1 = checksum & 0xFFFF;
- uint s2 = checksum >> 16;
-
- s1 = (s1 + ((uint)value & 0xFF)) % BASE;
- s2 = (s1 + s2) % BASE;
-
- checksum = (s2 << 16) + s1;
- }
-
-
-
-
-
-
-
- public void Update(byte[] buffer)
- {
- if ( buffer == null ) {
- throw new ArgumentNullException("buffer");
- }
- Update(buffer, 0, buffer.Length);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void Update(byte[] buffer, int offset, int count)
- {
- if (buffer == null) {
- throw new ArgumentNullException("buffer");
- }
-
- if (offset < 0) {
- #if NETCF_1_0
- throw new ArgumentOutOfRangeException("offset");
- #else
- throw new ArgumentOutOfRangeException("offset", "cannot be negative");
- #endif
- }
- if ( count < 0 )
- {
- #if NETCF_1_0
- throw new ArgumentOutOfRangeException("count");
- #else
- throw new ArgumentOutOfRangeException("count", "cannot be negative");
- #endif
- }
- if (offset >= buffer.Length)
- {
- #if NETCF_1_0
- throw new ArgumentOutOfRangeException("offset");
- #else
- throw new ArgumentOutOfRangeException("offset", "not a valid index into buffer");
- #endif
- }
-
- if (offset + count > buffer.Length)
- {
- #if NETCF_1_0
- throw new ArgumentOutOfRangeException("count");
- #else
- throw new ArgumentOutOfRangeException("count", "exceeds buffer size");
- #endif
- }
-
- uint s1 = checksum & 0xFFFF;
- uint s2 = checksum >> 16;
-
- while (count > 0) {
-
-
-
- int n = 3800;
- if (n > count) {
- n = count;
- }
- count -= n;
- while (--n >= 0) {
- s1 = s1 + (uint)(buffer[offset++] & 0xff);
- s2 = s2 + s1;
- }
- s1 %= BASE;
- s2 %= BASE;
- }
-
- checksum = (s2 << 16) | s1;
- }
-
- #region Instance Fields
- uint checksum;
- #endregion
- }
- }
|