public BZip2OutputStream(Stream inStream, int inBlockSize) { this.mCrc = new StrangeCRC(); this.inUse = new bool[0x100]; this.seqToUnseq = new char[0x100]; this.unseqToSeq = new char[0x100]; this.selector = new char[BZip2Constants.MAX_SELECTORS]; this.selectorMtf = new char[BZip2Constants.MAX_SELECTORS]; this.mtfFreq = new int[BZip2Constants.MAX_ALPHA_SIZE]; this.currentChar = -1; this.runLength = 0; this.closed = false; this.incs = new int[] { 1, 4, 13, 40, 0x79, 0x16c, 0x445, 0xcd0, 0x2671, 0x7354, 0x159fd, 0x40df8, 0xc29e9, 0x247dbc }; this.block = null; this.quadrant = null; this.zptr = null; this.ftab = null; this.BsSetStream(inStream); this.workFactor = 50; if (inBlockSize > 9) { inBlockSize = 9; } if (inBlockSize < 1) { inBlockSize = 1; } this.blockSize100k = inBlockSize; this.AllocateCompressStructures(); this.Initialize(); this.InitBlock(); }
public BZip2OutputStream(Stream stream, int blockSize) { _increments = new[] { 1, 4, 13, 40, 0x79, 0x16c, 0x445, 0xcd0, 0x2671, 0x7354, 0x159fd, 0x40df8, 0xc29e9, 0x247dbc }; IsStreamOwner = true; _mCrc = new StrangeCRC(); _inUse = new bool[0x100]; _seqToUnseq = new char[0x100]; _unseqToSeq = new char[0x100]; _selector = new char[0x4652]; _selectorMtf = new char[0x4652]; _mtfFreq = new int[0x102]; _currentChar = -1; BsSetStream(stream); _workFactor = 50; if (blockSize > 9) { blockSize = 9; } if (blockSize < 1) { blockSize = 1; } _blockSize100K = blockSize; AllocateCompressStructures(); Initialize(); InitBlock(); }
public BZip2OutputStream(Stream stream, int blockSize) { increments = new[] { 1, 4, 13, 40, 0x79, 0x16c, 0x445, 0xcd0, 0x2671, 0x7354, 0x159fd, 0x40df8, 0xc29e9, 0x247dbc }; isStreamOwner = true; mCrc = new StrangeCRC(); inUse = new bool[0x100]; seqToUnseq = new char[0x100]; unseqToSeq = new char[0x100]; selector = new char[0x4652]; selectorMtf = new char[0x4652]; mtfFreq = new int[0x102]; currentChar = -1; BsSetStream(stream); workFactor = 50; if (blockSize > 9) { blockSize = 9; } if (blockSize < 1) { blockSize = 1; } blockSize100k = blockSize; AllocateCompressStructures(); Initialize(); InitBlock(); }
public BZip2OutputStream(Stream stream, int blockSize) { int[] array = new int[14]; RuntimeHelpers.InitializeArray((global::System.Array)array, (RuntimeFieldHandle) /*OpCode not supported: LdMemberToken*/); increments = array; isStreamOwner = true; mCrc = new StrangeCRC(); inUse = new bool[256]; seqToUnseq = new char[256]; unseqToSeq = new char[256]; selector = new char[18002]; selectorMtf = new char[18002]; mtfFreq = new int[258]; currentChar = -1; ((Stream)this)..ctor(); BsSetStream(stream); workFactor = 50; if (blockSize > 9) { blockSize = 9; } if (blockSize < 1) { blockSize = 1; } blockSize100k = blockSize; AllocateCompressStructures(); Initialize(); InitBlock(); }
protected int[] ComputeHash(IChecksum checksum, byte[] data, int m, int k) { if (checksum == null) { throw new ArgumentNullException(nameof(checksum)); } int[] positions = new int[k]; int hashes = 0; int salt = 0; byte[] output = new byte[64]; const int seed32 = 89478583; while (hashes < k) { checksum.Reset(); checksum.Update(data); checksum.Update(hashes + salt++ + seed32); int hash = Rejection((int)checksum.Value, m); if (hash != -1) { positions[hashes++] = hash; } } return(positions); }
public static Parser <T> WithChecksum <T>(this Parser <T> parser, IChecksum checksum) { if (parser == null) { throw new ArgumentNullException("parser"); } return(i => { var start = i.Position; var a = parser(i); var end = a.Remainder.Position; return a.IfSuccess( b => { return Parse.Bytes(checksum.Length)(a.Remainder) .IfSuccess( c => { var expected = checksum.Calculate(a.Remainder.Source.Skip(start).Take(end - start).ToArray()); var actual = c.Value.ToArray(); return expected.SequenceEqual(actual) ? Result.Success(b.Value, c.Remainder) : Result.Failure <T>(b.Remainder, "invalid checksum", new[] { string.Format("expected checksum {0} but was {1}", BitConverter.ToString(expected), BitConverter.ToString(actual)) }); } ); }); }); }
private void exceptionTesting(IChecksum crcUnderTest) { bool exception = false; try { crcUnderTest.Update(null); } catch (ArgumentNullException) { exception = true; } Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException"); // reset exception exception = false; try { crcUnderTest.Update(null, 0, 0); } catch (ArgumentNullException) { exception = true; } Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException"); // reset exception exception = false; try { crcUnderTest.Update(check, -1, 9); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing a negative offset should cause an ArgumentOutOfRangeException"); // reset exception exception = false; try { crcUnderTest.Update(check, 9, 0); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing an offset greater than or equal to buffer.Length should cause an ArgumentOutOfRangeException"); // reset exception exception = false; try { crcUnderTest.Update(check, 0, -1); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing a negative count should cause an ArgumentOutOfRangeException"); // reset exception exception = false; try { crcUnderTest.Update(check, 0, 10); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing a count + offset greater than buffer.Length should cause an ArgumentOutOfRangeException"); }
private void exceptionTesting(IChecksum crcUnderTest) { bool exception = false; try { crcUnderTest.Update(null); } catch (ArgumentNullException) { exception = true; } Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException"); // reset exception exception = false; try { crcUnderTest.Update(new ArraySegment <byte>(null, 0, 0)); } catch (ArgumentNullException) { exception = true; } Assert.IsTrue(exception, "Passing a null buffer should cause an ArgumentNullException"); // reset exception exception = false; try { crcUnderTest.Update(new ArraySegment <byte>(check, -1, 9)); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing a negative offset should cause an ArgumentOutOfRangeException"); // reset exception exception = false; try { crcUnderTest.Update(new ArraySegment <byte>(check, 10, 0)); } catch (ArgumentException) { exception = true; } Assert.IsTrue(exception, "Passing an offset greater than buffer.Length should cause an ArgumentException"); // reset exception exception = false; try { crcUnderTest.Update(new ArraySegment <byte>(check, 0, -1)); } catch (ArgumentOutOfRangeException) { exception = true; } Assert.IsTrue(exception, "Passing a negative count should cause an ArgumentOutOfRangeException"); // reset exception exception = false; try { crcUnderTest.Update(new ArraySegment <byte>(check, 0, 10)); } catch (ArgumentException) { exception = true; } Assert.IsTrue(exception, "Passing a count + offset greater than buffer.Length should cause an ArgumentException"); }
public FileManager(INetworkConnection networkConnection, IUserAccessCredentials userAccessCredentials, INetworkPathInfo networkPathInfo, IMetaData metaData, ISqlDatabaseFactory sqlDatabaseFactory, IChecksum checksum) { _networkConnection = networkConnection; _userAccessCredentials = userAccessCredentials; _networkPathInfo = networkPathInfo; _metaData = metaData; _sqlDatabaseFactory = sqlDatabaseFactory; _checksum = checksum; }
public Blaze() { _provider = new SerialProvider(); _provider.DataReceived += new EventHandler(OnDataReceived); _replyReceived = new AutoResetEvent(false); _provider.PortName = "COM1"; _provider.BaudRate = 115200; _checksum = new CCITT(); _dataBuffer = new ByteList(); }
public ReceiverStmContext(ILink link, IChecksum cheksum, ISequenceGenerator sequenceGenerator, int maxMessageDataSize) { _message = new Message(maxMessageDataSize); _reply = new Message(0); _link = link; _sequence = sequenceGenerator; _checksum = cheksum; SetState(new MissingSync()); }
protected void estimatedChecksum(byte[] arr) { if (this.checksum == CheckSumType.None) { this.checksum = this.des[this.dev]; } IChecksum ck = this.check[this.Checksum]; ck.setParameter(this.nbyterequest, arr); ck.execute(); }
static Guid UpdateChecksum(IChecksum item, System.Security.Cryptography.MD5CryptoServiceProvider md5) { string s = JocysCom.ClassLibrary.Runtime.RuntimeHelper.GetDataMembersString(item); var bytes = Encoding.Unicode.GetBytes(s); var cs = new Guid(md5.ComputeHash(bytes)); if (item.Checksum != cs) { item.Checksum = cs; } return(cs); }
public UploadNewVersionPresenter(IMetaData metaData, IChecksum checksum, IFileManager fileManager, IMessageService messageService, IFileValidator fileValidator, IFormFactory <IUploadNewVersionView> formFactory, IIoc ioc, INetworkPathInfo networkPathInfo) { _formFactory = formFactory; _ioc = ioc; _networkPathInfo = networkPathInfo; _messageService = messageService; _fileValidator = fileValidator; _checksum = checksum; _metaData = metaData; _fileManager = fileManager; _networkPath = _networkPathInfo.GetPathNeworkDirectory(); }
internal SqlIndexOutput( SqlDirectoryOptions options, IDatabaseLuceneOperator sqlOperator, Node node) { _sqlOperator = sqlOperator; _node = node; _checksum = new Checksum(); _bufferSize = options.BlockSize; _nodeId = node.Id; _length = node.Size; }
public bool Equals(IChecksum other) { if (Count != other.Count) { return(false); } for (int i = 0; i < Count; i++) { if (other[i] != this[i]) { return(false); } } return(true); }
public SenderStmContext(ILink link, IChecksum checksum, ISequenceGenerator sequenceGenerator, int maxMessageDataSize, int timeoutModifier) { _checksum = checksum; _timeout = link.Timeout * timeoutModifier; _timer = new Timer(MessageTimeout); _link = link; _maxMessageDataSize = maxMessageDataSize; _message = new Message(_maxMessageDataSize); _reply = new Message(0); _sequence = sequenceGenerator; SetState(new Sending()); }
public DatabasesListPresenter(IChecksum checksum, IUserAccessCredentials userAccessCredentials, IFileManager fileManager, IMetaData metaData, IIoc ioc, DatabaseDetailsPresenter databaseDetailsPresenter, LoginPresenter loginPresenter, IFormFactory <IDatabasesListView> formFactory, INetworkConnection networkConnection, INetworkPathInfo networkPathInfo) { _databaseDetailsPresenter = databaseDetailsPresenter; _loginPresenter = loginPresenter; _checksum = checksum; _userAccessCredentials = userAccessCredentials; _fileManager = fileManager; _metaData = metaData; _ioc = ioc; _formFactory = formFactory; _networkConnection = networkConnection; _networkPathInfo = networkPathInfo; _view = _formFactory.CreateDatabasesListForm(); _resumableFileManager = _fileManager as IResumableFileManager; _cancellationTokenSource = new CancellationTokenSource(); _networkPath = _networkPathInfo.GetPathNeworkDirectory(); }
public AzureIndexOutput(AzureDirectory azureDirectory, ICloudBlob blob) { _fileMutex = BlobMutexManager.GrabMutex(_name); _fileMutex.WaitOne(); try { _azureDirectory = azureDirectory; _blobContainer = _azureDirectory.BlobContainer; _blob = blob; _name = blob.Uri.Segments[blob.Uri.Segments.Length - 1]; // create the local cache one we will operate against... _indexOutput = CacheDirectory.CreateOutput(_name, IOContext.DEFAULT); } finally { _fileMutex.ReleaseMutex(); } _digest = new CRC32(); }
internal static List <ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All) { IChecksum adler32CtxData = null; IChecksum crc16CtxData = null; IChecksum crc32CtxData = null; IChecksum crc64CtxData = null; IChecksum md5CtxData = null; IChecksum sha1CtxData = null; IChecksum sha256CtxData = null; IChecksum sha384CtxData = null; IChecksum sha512CtxData = null; IChecksum ssctxData = null; IChecksum f16CtxData = null; IChecksum f32CtxData = null; var adlerThreadData = new Thread(UpdateHash); var crc16ThreadData = new Thread(UpdateHash); var crc32ThreadData = new Thread(UpdateHash); var crc64ThreadData = new Thread(UpdateHash); var md5ThreadData = new Thread(UpdateHash); var sha1ThreadData = new Thread(UpdateHash); var sha256ThreadData = new Thread(UpdateHash); var sha384ThreadData = new Thread(UpdateHash); var sha512ThreadData = new Thread(UpdateHash); var spamsumThreadData = new Thread(UpdateHash); var f16ThreadData = new Thread(UpdateHash); var f32ThreadData = new Thread(UpdateHash); if (enabled.HasFlag(EnableChecksum.Adler32)) { adler32CtxData = new Adler32Context(); var adlerPktData = new HashPacket { Context = adler32CtxData, Data = data }; adlerThreadData.Start(adlerPktData); } if (enabled.HasFlag(EnableChecksum.Crc16)) { crc16CtxData = new CRC16IBMContext(); var crc16PktData = new HashPacket { Context = crc16CtxData, Data = data }; crc16ThreadData.Start(crc16PktData); } if (enabled.HasFlag(EnableChecksum.Crc32)) { crc32CtxData = new Crc32Context(); var crc32PktData = new HashPacket { Context = crc32CtxData, Data = data }; crc32ThreadData.Start(crc32PktData); } if (enabled.HasFlag(EnableChecksum.Crc64)) { crc64CtxData = new Crc64Context(); var crc64PktData = new HashPacket { Context = crc64CtxData, Data = data }; crc64ThreadData.Start(crc64PktData); } if (enabled.HasFlag(EnableChecksum.Md5)) { md5CtxData = new Md5Context(); var md5PktData = new HashPacket { Context = md5CtxData, Data = data }; md5ThreadData.Start(md5PktData); } if (enabled.HasFlag(EnableChecksum.Sha1)) { sha1CtxData = new Sha1Context(); var sha1PktData = new HashPacket { Context = sha1CtxData, Data = data }; sha1ThreadData.Start(sha1PktData); } if (enabled.HasFlag(EnableChecksum.Sha256)) { sha256CtxData = new Sha256Context(); var sha256PktData = new HashPacket { Context = sha256CtxData, Data = data }; sha256ThreadData.Start(sha256PktData); } if (enabled.HasFlag(EnableChecksum.Sha384)) { sha384CtxData = new Sha384Context(); var sha384PktData = new HashPacket { Context = sha384CtxData, Data = data }; sha384ThreadData.Start(sha384PktData); } if (enabled.HasFlag(EnableChecksum.Sha512)) { sha512CtxData = new Sha512Context(); var sha512PktData = new HashPacket { Context = sha512CtxData, Data = data }; sha512ThreadData.Start(sha512PktData); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { ssctxData = new SpamSumContext(); var spamsumPktData = new HashPacket { Context = ssctxData, Data = data }; spamsumThreadData.Start(spamsumPktData); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { f16CtxData = new Fletcher16Context(); var f16PktData = new HashPacket { Context = f16CtxData, Data = data }; f16ThreadData.Start(f16PktData); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { f32CtxData = new Fletcher32Context(); var f32PktData = new HashPacket { Context = f32CtxData, Data = data }; f32ThreadData.Start(f32PktData); } while (adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha512ThreadData.IsAlive || spamsumThreadData.IsAlive || f16ThreadData.IsAlive || f32ThreadData.IsAlive) { } List <ChecksumType> dataChecksums = new List <ChecksumType>(); ChecksumType chk; if (enabled.HasFlag(EnableChecksum.Adler32)) { chk = new ChecksumType { type = ChecksumTypeType.adler32, Value = adler32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc16)) { chk = new ChecksumType { type = ChecksumTypeType.crc16, Value = crc16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc32)) { chk = new ChecksumType { type = ChecksumTypeType.crc32, Value = crc32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc64)) { chk = new ChecksumType { type = ChecksumTypeType.crc64, Value = crc64CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Md5)) { chk = new ChecksumType { type = ChecksumTypeType.md5, Value = md5CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha1)) { chk = new ChecksumType { type = ChecksumTypeType.sha1, Value = sha1CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha256)) { chk = new ChecksumType { type = ChecksumTypeType.sha256, Value = sha256CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha384)) { chk = new ChecksumType { type = ChecksumTypeType.sha384, Value = sha384CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha512)) { chk = new ChecksumType { type = ChecksumTypeType.sha512, Value = sha512CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { chk = new ChecksumType { type = ChecksumTypeType.spamsum, Value = ssctxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher16, Value = f16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher32, Value = f32CtxData.End() }; dataChecksums.Add(chk); } return(dataChecksums); }
/// <summary> /// Creates a new instance of the <see cref="ChecksumTestDriver"/> class. /// </summary> /// <param name="checksum"><see cref="IChecksum"/> to use in calculations.</param> public ChecksumTestDriver(IChecksum checksum) { Debug.Assert(checksum != null); _checksum = checksum; }
/// <summary> /// Create a new BufferedChecksum with the specified bufferSize </summary> public BufferedChecksum(IChecksum @in, int bufferSize) { this.@in = @in; this.Buffer = new byte[bufferSize]; }
internal static List <ChecksumType> GetChecksums(byte[] data, EnableChecksum enabled = EnableChecksum.All) { IChecksum adler32CtxData = null; IChecksum crc16CtxData = null; IChecksum crc32CtxData = null; IChecksum crc64CtxData = null; IChecksum md5CtxData = null; #if !NETSTANDARD2_0 IChecksum ripemd160CtxData = null; #endif IChecksum sha1CtxData = null; IChecksum sha256CtxData = null; IChecksum sha384CtxData = null; IChecksum sha512CtxData = null; IChecksum ssctxData = null; IChecksum f16CtxData = null; IChecksum f32CtxData = null; Thread adlerThreadData = new Thread(UpdateHash); Thread crc16ThreadData = new Thread(UpdateHash); Thread crc32ThreadData = new Thread(UpdateHash); Thread crc64ThreadData = new Thread(UpdateHash); Thread md5ThreadData = new Thread(UpdateHash); #if !NETSTANDARD2_0 Thread ripemd160ThreadData = new Thread(UpdateHash); #endif Thread sha1ThreadData = new Thread(UpdateHash); Thread sha256ThreadData = new Thread(UpdateHash); Thread sha384ThreadData = new Thread(UpdateHash); Thread sha512ThreadData = new Thread(UpdateHash); Thread spamsumThreadData = new Thread(UpdateHash); Thread f16ThreadData = new Thread(UpdateHash); Thread f32ThreadData = new Thread(UpdateHash); if (enabled.HasFlag(EnableChecksum.Adler32)) { adler32CtxData = new Adler32Context(); HashPacket adlerPktData = new HashPacket { Context = adler32CtxData, Data = data }; adlerThreadData.Start(adlerPktData); } if (enabled.HasFlag(EnableChecksum.Crc16)) { crc16CtxData = new Crc16Context(); HashPacket crc16PktData = new HashPacket { Context = crc16CtxData, Data = data }; crc16ThreadData.Start(crc16PktData); } if (enabled.HasFlag(EnableChecksum.Crc32)) { crc32CtxData = new Crc32Context(); HashPacket crc32PktData = new HashPacket { Context = crc32CtxData, Data = data }; crc32ThreadData.Start(crc32PktData); } if (enabled.HasFlag(EnableChecksum.Crc64)) { crc64CtxData = new Crc64Context(); HashPacket crc64PktData = new HashPacket { Context = crc64CtxData, Data = data }; crc64ThreadData.Start(crc64PktData); } if (enabled.HasFlag(EnableChecksum.Md5)) { md5CtxData = new Md5Context(); HashPacket md5PktData = new HashPacket { Context = md5CtxData, Data = data }; md5ThreadData.Start(md5PktData); } #if !NETSTANDARD2_0 if (enabled.HasFlag(EnableChecksum.Ripemd160)) { ripemd160CtxData = new Ripemd160Context(); HashPacket ripemd160PktData = new HashPacket { Context = ripemd160CtxData, Data = data }; ripemd160ThreadData.Start(ripemd160PktData); } #endif if (enabled.HasFlag(EnableChecksum.Sha1)) { sha1CtxData = new Sha1Context(); HashPacket sha1PktData = new HashPacket { Context = sha1CtxData, Data = data }; sha1ThreadData.Start(sha1PktData); } if (enabled.HasFlag(EnableChecksum.Sha256)) { sha256CtxData = new Sha256Context(); HashPacket sha256PktData = new HashPacket { Context = sha256CtxData, Data = data }; sha256ThreadData.Start(sha256PktData); } if (enabled.HasFlag(EnableChecksum.Sha384)) { sha384CtxData = new Sha384Context(); HashPacket sha384PktData = new HashPacket { Context = sha384CtxData, Data = data }; sha384ThreadData.Start(sha384PktData); } if (enabled.HasFlag(EnableChecksum.Sha512)) { sha512CtxData = new Sha512Context(); HashPacket sha512PktData = new HashPacket { Context = sha512CtxData, Data = data }; sha512ThreadData.Start(sha512PktData); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { ssctxData = new SpamSumContext(); HashPacket spamsumPktData = new HashPacket { Context = ssctxData, Data = data }; spamsumThreadData.Start(spamsumPktData); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { f16CtxData = new Fletcher16Context(); HashPacket f16PktData = new HashPacket { Context = f16CtxData, Data = data }; f16ThreadData.Start(f16PktData); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { f32CtxData = new Fletcher32Context(); HashPacket f32PktData = new HashPacket { Context = f32CtxData, Data = data }; f32ThreadData.Start(f32PktData); } while (adlerThreadData.IsAlive || crc16ThreadData.IsAlive || crc32ThreadData.IsAlive || crc64ThreadData.IsAlive || md5ThreadData.IsAlive || #if !NETSTANDARD2_0 ripemd160ThreadData.IsAlive || #endif sha1ThreadData.IsAlive || sha256ThreadData.IsAlive || sha384ThreadData.IsAlive || sha512ThreadData.IsAlive || spamsumThreadData.IsAlive || f16ThreadData.IsAlive || f32ThreadData.IsAlive) { } List <ChecksumType> dataChecksums = new List <ChecksumType>(); ChecksumType chk; if (enabled.HasFlag(EnableChecksum.Adler32)) { chk = new ChecksumType { type = ChecksumTypeType.adler32, Value = adler32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc16)) { chk = new ChecksumType { type = ChecksumTypeType.crc16, Value = crc16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc32)) { chk = new ChecksumType { type = ChecksumTypeType.crc32, Value = crc32CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Crc64)) { chk = new ChecksumType { type = ChecksumTypeType.crc64, Value = crc64CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Md5)) { chk = new ChecksumType { type = ChecksumTypeType.md5, Value = md5CtxData.End() }; dataChecksums.Add(chk); } #if !NETSTANDARD2_0 if (enabled.HasFlag(EnableChecksum.Ripemd160)) { chk = new ChecksumType { type = ChecksumTypeType.ripemd160, Value = ripemd160CtxData.End() }; dataChecksums.Add(chk); } #endif if (enabled.HasFlag(EnableChecksum.Sha1)) { chk = new ChecksumType { type = ChecksumTypeType.sha1, Value = sha1CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha256)) { chk = new ChecksumType { type = ChecksumTypeType.sha256, Value = sha256CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha384)) { chk = new ChecksumType { type = ChecksumTypeType.sha384, Value = sha384CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Sha512)) { chk = new ChecksumType { type = ChecksumTypeType.sha512, Value = sha512CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.SpamSum)) { chk = new ChecksumType { type = ChecksumTypeType.spamsum, Value = ssctxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher16, Value = f16CtxData.End() }; dataChecksums.Add(chk); } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { chk = new ChecksumType { type = ChecksumTypeType.fletcher32, Value = f32CtxData.End() }; dataChecksums.Add(chk); } return(dataChecksums); }
/// <summary> /// Creates a new <see cref="BufferedChecksumIndexInput"/> </summary> public BufferedChecksumIndexInput(IndexInput main) : base("BufferedChecksumIndexInput(" + main + ")") { this.main = main; this.digest = new BufferedChecksum(new CRC32()); }
protected ChecksumTest(IChecksum provider) { _provider = provider; }
/// <summary> /// Creates a new BufferedChecksumIndexInput </summary> public BufferedChecksumIndexInput(IndexInput main) : base("BufferedChecksumIndexInput(" + main + ")") { this.Main = main; this.Digest = new BufferedChecksum(new CRC32()); }
public static void CalcularCRC(string file, int offset, int count ,IChecksum crc) { FileStream reader = new FileStream (file, FileMode.Open); reader.Seek (offset, SeekOrigin.Begin); for (int i=0; i < count; i++){ crc.Update (reader.ReadByte()); } reader.Close(); }
/// <summary>Copia el contendio de un fichero, a partir de una posición /// dada al final de otro y realiza /// la suma de comprobación de los datos transferidos.</summary> /// <param name="desde">El fichero origen de datos.</param> /// <param name="hacia">El fichero destido de los datos.</param> /// <param name="pos">El número de bytes que no se leerán del /// principio de origen</param> /// <param name="crc">El checsum a aplicar a los datos.</param> /// <returns>El número de bytes copiados</returns> public static long CopiarIntervalo(String desde, String hacia, long pos, IChecksum crc) { return CopiarIntervalo (desde, hacia, pos, new FileInfo(desde).Length - pos, crc); }
public ValidatePassport(IChecksum checksum) { _checksum = checksum; }
public ChecksumEntry(String fileName, IChecksum checksum) { this.FileName = fileName; this.Checksum = checksum; }
public Transport() { _connected = false; _synced = false; _checksum = new Checksum(); }
/// <summary> /// 将字节数组添加到数据校验和 /// </summary> /// <param name="buffer">字节数组</param> /// <param name="offset">起始偏移量</param> /// <param name="count">多少长度会被添加到数据校验</param> /// <param name="checksum">使用效验类类型</param> /// <returns>效验值</returns> private long Checksum(byte[] buffer, int offset, int count, IChecksum checksum) { HashingGuard.BufferOffsetCount(buffer, offset, count); checksum.Update(buffer, offset, count); return(checksum.Value); }
public Checksum(EnableChecksum enabled = EnableChecksum.All) { _enabled = enabled; if (enabled.HasFlag(EnableChecksum.Adler32)) { _adler32Ctx = new Adler32Context(); _adlerPkt = new HashPacket { Context = _adler32Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc16)) { _crc16Ctx = new CRC16IBMContext(); _crc16Pkt = new HashPacket { Context = _crc16Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc32)) { _crc32Ctx = new Crc32Context(); _crc32Pkt = new HashPacket { Context = _crc32Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc64)) { _crc64Ctx = new Crc64Context(); _crc64Pkt = new HashPacket { Context = _crc64Ctx }; } if (enabled.HasFlag(EnableChecksum.Md5)) { _md5Ctx = new Md5Context(); _md5Pkt = new HashPacket { Context = _md5Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha1)) { _sha1Ctx = new Sha1Context(); _sha1Pkt = new HashPacket { Context = _sha1Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha256)) { _sha256Ctx = new Sha256Context(); _sha256Pkt = new HashPacket { Context = _sha256Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha384)) { _sha384Ctx = new Sha384Context(); _sha384Pkt = new HashPacket { Context = _sha384Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha512)) { _sha512Ctx = new Sha512Context(); _sha512Pkt = new HashPacket { Context = _sha512Ctx }; } if (enabled.HasFlag(EnableChecksum.SpamSum)) { _ssCtx = new SpamSumContext(); _spamsumPkt = new HashPacket { Context = _ssCtx }; } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { _f16Ctx = new Fletcher16Context(); _f16Pkt = new HashPacket { Context = _f16Ctx }; } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { _f32Ctx = new Fletcher32Context(); _f32Pkt = new HashPacket { Context = _f32Ctx }; } _adlerThread = new Thread(UpdateHash); _crc16Thread = new Thread(UpdateHash); _crc32Thread = new Thread(UpdateHash); _crc64Thread = new Thread(UpdateHash); _md5Thread = new Thread(UpdateHash); _sha1Thread = new Thread(UpdateHash); _sha256Thread = new Thread(UpdateHash); _sha384Thread = new Thread(UpdateHash); _sha512Thread = new Thread(UpdateHash); _spamsumThread = new Thread(UpdateHash); _f16Thread = new Thread(UpdateHash); _f32Thread = new Thread(UpdateHash); }
private CountryEnum(int id, string code, IChecksum checksum) : base(id) { Code = code; _checksum = checksum; }
/// <summary> /// Create a new BufferedChecksum with <seealso cref="#DEFAULT_BUFFERSIZE"/> </summary> public BufferedChecksum(IChecksum @in) : this(@in, DEFAULT_BUFFERSIZE) { }
/// <summary> /// Create a new <see cref="BufferedChecksum"/> with the specified <paramref name="bufferSize"/> </summary> public BufferedChecksum(IChecksum @in, int bufferSize) { this.@in = @in; this.buffer = new byte[bufferSize]; }
public ChecksumIndexInput(IndexInput main) { this.main = main; digest = new CRC32(); }
static void Check(IChecksum <ulong> crc, byte[] data, ulong value) { crc.Reset(); crc.Update(data); Assert.AreEqual(value, crc.Value, "Test crc {0} invalid result {1:x2} expected {2:x2}!", crc, crc.Value, value); }
/// <summary>Copia una parte de un fichero final de otro y realiza /// el checksum de comprobación de los datos transferidos.</summary> /// <param name="desde">El fichero origen de datos.</param> /// <param name="hacia">El fichero destido de los datos.</param> /// <param name="from">El número de bytes que no se leerán del principio de origen</param> /// <param count="count">El tamaño del fragmento a copiar.</param> /// <param name="crc">El checsum a aplicar a los datos.</param> /// <returns>El número de bytes copiados</returns> public static long CopiarIntervalo(String desde, String hacia, long from, long count, IChecksum crc) { long totales = 0; long leidos = 0; FileStream writer = new FileStream (hacia, FileMode.Append, FileAccess.Write); writer.Seek (writer.Length, SeekOrigin.Begin); FileStream reader = new FileStream (desde, FileMode.Open, FileAccess.Read); reader.Seek (from, SeekOrigin.Begin); byte[] buffer = new byte[_bufferSize]; long limite = 0; do{ limite = (buffer.Length > (count - totales)) ? (count - totales) : buffer.Length; leidos = reader.Read (buffer, 0, (int)limite); crc.Update (buffer, 0, (int) leidos); totales += leidos; writer.Write (buffer, 0, (int)leidos); }while ((leidos != 0) && ((totales + from) < reader.Length)); writer.Close(); reader.Close(); return totales; }
public Checksum(EnableChecksum enabled = EnableChecksum.All) { this.enabled = enabled; if (enabled.HasFlag(EnableChecksum.Adler32)) { adler32Ctx = new Adler32Context(); adlerPkt = new HashPacket { Context = adler32Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc16)) { crc16Ctx = new Crc16Context(); crc16Pkt = new HashPacket { Context = crc16Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc32)) { crc32Ctx = new Crc32Context(); crc32Pkt = new HashPacket { Context = crc32Ctx }; } if (enabled.HasFlag(EnableChecksum.Crc64)) { crc64Ctx = new Crc64Context(); crc64Pkt = new HashPacket { Context = crc64Ctx }; } if (enabled.HasFlag(EnableChecksum.Md5)) { md5Ctx = new Md5Context(); md5Pkt = new HashPacket { Context = md5Ctx }; } #if !NETSTANDARD2_0 if (enabled.HasFlag(EnableChecksum.Ripemd160)) { ripemd160Ctx = new Ripemd160Context(); ripemd160Pkt = new HashPacket { Context = ripemd160Ctx }; } #endif if (enabled.HasFlag(EnableChecksum.Sha1)) { sha1Ctx = new Sha1Context(); sha1Pkt = new HashPacket { Context = sha1Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha256)) { sha256Ctx = new Sha256Context(); sha256Pkt = new HashPacket { Context = sha256Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha384)) { sha384Ctx = new Sha384Context(); sha384Pkt = new HashPacket { Context = sha384Ctx }; } if (enabled.HasFlag(EnableChecksum.Sha512)) { sha512Ctx = new Sha512Context(); sha512Pkt = new HashPacket { Context = sha512Ctx }; } if (enabled.HasFlag(EnableChecksum.SpamSum)) { ssctx = new SpamSumContext(); spamsumPkt = new HashPacket { Context = ssctx }; } if (enabled.HasFlag(EnableChecksum.Fletcher16)) { f16Ctx = new Fletcher16Context(); f16Pkt = new HashPacket { Context = f16Ctx }; } if (enabled.HasFlag(EnableChecksum.Fletcher32)) { f32Ctx = new Fletcher32Context(); f32Pkt = new HashPacket { Context = f32Ctx }; } adlerThread = new Thread(UpdateHash); crc16Thread = new Thread(UpdateHash); crc32Thread = new Thread(UpdateHash); crc64Thread = new Thread(UpdateHash); md5Thread = new Thread(UpdateHash); #if !NETSTANDARD2_0 ripemd160Thread = new Thread(UpdateHash); #endif sha1Thread = new Thread(UpdateHash); sha256Thread = new Thread(UpdateHash); sha384Thread = new Thread(UpdateHash); sha512Thread = new Thread(UpdateHash); spamsumThread = new Thread(UpdateHash); f16Thread = new Thread(UpdateHash); f32Thread = new Thread(UpdateHash); }
/// <summary> /// Create a new <see cref="BufferedChecksum"/> with <see cref="DEFAULT_BUFFERSIZE"/> </summary> public BufferedChecksum(IChecksum @in) : this(@in, DEFAULT_BUFFERSIZE) { }
/// <summary>Copia el contendio de un fichero al final de otro y realiza /// la suma de comprobación de los datos transferidos.</summary> /// <param name="desde">El fichero origen de datos.</param> /// <param name="hacia">El fichero destido de los datos.</param> /// <param name="crc">El checsum a aplicar a los datos.</param> /// <returns>El número de bytes copiados</returns> public static long CopiarTodo(String desde, String hacia, IChecksum crc) { return CopiarIntervalo (desde, hacia, 0, new FileInfo(desde).Length, crc); }
protected ZStream(IChecksum adler) { this.adler = adler; }
public static long GenerateHash(string file, IChecksum crc) { FileStream reader = new FileStream (file, FileMode.Open); byte[] buffer = new byte[_bufferSize]; long total = 0; long count = 0; do { count = reader.Read (buffer, 0, buffer.Length); crc.Update (buffer, 0, (int)count); total += count; } while (count > 0); reader.Close (); return total; }
public static void Append(String fichero, byte[] data, IChecksum crc) { if (crc != null){ crc.Update (data); } FileStream writer = new FileStream (fichero, FileMode.Append, FileAccess.Write); writer.Seek (writer.Length, SeekOrigin.Begin); writer.Write(data, 0, data.Length); writer.Close(); }
public ChecksumIndexOutput(IndexOutput main) { this.main = main; digest = new CRC32(); }
void Check(IChecksum <uint> crc, byte[] data, uint value) { crc.Reset(); crc.Update(data); Assert.AreEqual(value, crc.Value); }
public ChecksumStream(Stream stream, IChecksum crc) { this.stream = stream; this.crc = crc; }