public void Crc24_OfNullFile_ThrowsArgumentNullException() { var storageAcces = new Crc24TestStorageAccess(); StreamUtilities.Initialize(storageAcces); Assert.Throws <System.ArgumentNullException>(() => Crc24.OfFile(null)); }
/// <summary> /// Adds CRC24 to signatures that does not have it. /// </summary> /// <returns>The fix.</returns> /// <param name="signature">Signature.</param> public static string SignatureFix(string signature) { var retSig = signature; var m = PGPSig.Match(signature); if (m.Groups.Count > 1) { var sig = ""; var data = m.Groups[1].Value.TrimStart().TrimEnd().Split('\n'); var save = false; if (data.Length == 1) { sig = data[0]; } else { data.ToList().ForEach((l) => { if (!save) { save |= l.Length == 0; if (l.Length > 2 && l.Substring(0, 2) == "iQ") // Workarround for a GPG Bug in production { save = true; sig += l; } } else { sig += l; } }); } try { byte[] bData = Convert.FromBase64String(sig); // Append checksum var crc24 = new Crc24(); foreach (var b in bData) { crc24.Update(b); } var crc = crc24.Value; var crcu8 = new byte[3]; crcu8[0] = (byte)(crc >> 16 & 0xFF); crcu8[1] = (byte)(crc >> 8 & 0xFF); crcu8[2] = (byte)(crc & 0xFF); retSig = "-----BEGIN PGP SIGNATURE-----\n\n"; retSig += sig + "\n="; retSig += Convert.ToBase64String(crcu8); retSig += "\n-----END PGP SIGNATURE-----"; return(retSig); } catch (Exception) { // Signature is already with checksum } } return(retSig); }
public void Crc24_OfStreamWithInitialValue_IsCorrect() { using (var testData = new MemoryStream(new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 })) { testData.Seek(0, SeekOrigin.Begin); var crc24 = Crc24.OfStream(testData, Crc24.InitialValue); Assert.Equal(0x004F40DAu, crc24); } }
public void Crc24_OfFile_IsCorrect() { // We use a privately defined type for the storage access to check initialize and remove, which will // hopefully guarantee that we use the expected storage during this test. var storageAcces = new Crc24TestStorageAccess(); StreamUtilities.Initialize(storageAcces); var testFileName = "~/Crc24_OfFile_IsCorrect.dat"; using (var fileStream = StreamUtilities.OpenFileStream(testFileName)) { var testData = new byte[] { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 }; fileStream.Write(testData, 0, testData.Length); var crc24 = Crc24.OfFile(testFileName); Assert.Equal(0x004F40DAu, crc24); } }
/// <inheritdoc /> public override string ToString() { var forkString = "Fork {" + "ID: " + GlobalForkNumber + " UID: " + Crc24.ToString("X4"); return(forkString + " Base:" + StartingVirtualBlock.ToString("X4") + " Size: " + Size + "}"); }
/// <inheritdoc /> public override int GetHashCode() { return(StartingVirtualBlock.GetHashCode() ^ Size.GetHashCode() ^ Crc24.GetHashCode()); }
public void Crc24_OfNullStream_ThrowsNullReferenceException() { Assert.Throws <System.NullReferenceException>(() => Crc24.OfStream(null, 0)); }