private void VerifyCheckSum()
        {
            if (_consumed.Count < 3)
            {
                throw new CodeError("Expected at least 3 codes in the token.");
            }

            var allBytes = _consumed.SelectMany(c => c.Values).ToList();
            var bytes    = new List <byte>(allBytes.Take(allBytes.Count - 2));

            var expectedCheckSum = _checksumCalculator.CalculateChecksum(bytes);
            var providedCheckSum = allBytes[allBytes.Count - 2];

            if (expectedCheckSum != providedCheckSum)
            {
                throw new CodeError($"Check sum mismatch. Expected {expectedCheckSum}, found {providedCheckSum}");
            }
        }
        public EncodedCode128(IMapping mapping,
                              IEnumerable <Symbol> symbols,
                              string encodedContent,
                              IChecksumCalculator calculator)
        {
            var symbolList = symbols.ToList();

            Symbols        = symbolList;
            Data           = Symbols.SelectMany(c => c.Values).ToList();
            EncodedContent = encodedContent;
            if (calculator != null)
            {
                var checkSum       = calculator.CalculateChecksum(Data);
                var checkSumSymbol = new Symbol(SpecialCodes.CheckSum, mapping.GetPattern(checkSum), checkSum);
                symbolList.Add(checkSumSymbol);
                symbolList.Add(mapping.StopSymbol);
            }

            FullData = Symbols.SelectMany(c => c.Values).ToList();
        }
 private void CalculateChecksum() =>
 _calculatedChecksum = _calculator.CalculateChecksum(_payload).ElementAt(0);
        private void AppendChecksum()
        {
            var checksum = _calculator.CalculateChecksum(_packetInfo).ToList();

            _currentPacket.AddRange(checksum);
        }
Beispiel #5
0
 private uint CalculateFileChecksum(string filePath)
 {
     return(checksumCalculator.CalculateChecksum(filePath));
 }