public static Packet GeneratePacket(List <Frame> frames, ChecksumType checksumType, int checksumLength) { IChecksumCalculator calculator = ChecksumCalculatorFactory.Create(checksumType); string framesData = string.Join("", frames.Select(f => f.GetFrame())); string checksum = calculator.Calculate(framesData, checksumLength); return(new Packet(frames, checksum)); }
public static Frame GenerateFrame(int length, ChecksumType checksumType, int checksumLength) { string data = GenerateBytes(length); IChecksumCalculator calculator = ChecksumCalculatorFactory.Create(checksumType); string checksum = calculator.Calculate(data, checksumLength); return(new Frame(data, checksum)); }
private bool IsLineHashDifferent(IAnalysisIssueLocation location, ITextSnapshotLine snapshotLine) { if (string.IsNullOrEmpty(location.LineHash)) { return(false); } var textInSnapshot = snapshotLine.GetText(); var snapshotLineHash = checksumCalculator.Calculate(textInSnapshot); return(snapshotLineHash != location.LineHash); }
public string Calculate(string documentText, int oneBasedLineNumber) { if (string.IsNullOrEmpty(documentText) || oneBasedLineNumber < 1) { return(null); } var lines = GetLines(documentText); if (oneBasedLineNumber > lines.Length) { return(null); } var lineToHash = lines[oneBasedLineNumber - 1]; var hash = checksumCalculator.Calculate(lineToHash); return(hash); }
/// <summary> /// Validate the subject for the given expected checksum. /// The checksum is calculated and then compared to the expected one. /// </summary> /// <param name="calculator">The algorithm</param> /// <param name="subject">the text to check</param> /// <param name="expectedChecksum">the checksum that is expected</param> /// <returns>Is the expected checksum found</returns> public static bool Validate(this IChecksumCalculator calculator, string subject, int expectedChecksum) { var actualChecksum = calculator.Calculate(subject); return(actualChecksum == expectedChecksum); }