public void ProtectInvalidArgsFail() { ArgumentException ex; ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(new byte[MaxContentSize + 1], new byte[MaxPackageSize], new byte[HashSize], 0, MaxPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("content", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(new byte[MaxContentSize], new byte[MaxPackageSize - 1], new byte[HashSize], 0, MaxPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("package", ex.ParamName); ex = Assert.ThrowsException <ArgumentNullException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], null, 0, MinPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("key", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[0], 0, MinPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("key", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[31], 0, MinPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("key", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[65], 0, MinPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("key", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[HashSize], -1, MinPackageSize, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("packageNumber", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[HashSize], 0, MinPackageSize - 1, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("packageSize", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[HashSize], 0, MaxPackageSize + 1, ArraySegment <byte> .Empty)); Assert.AreEqual <string>("packageSize", ex.ParamName); ex = Assert.ThrowsException <ArgumentOutOfRangeException>(() => PackageProtector.Protect(Array.Empty <byte>(), new byte[MinPackageSize], new byte[HashSize], 0, MinPackageSize, new byte[BlockSize + 1])); Assert.AreEqual <string>("associatedData", ex.ParamName); }
public void ProtectNullOrDefaultContentPass() { PackageProtector.Protect(null, new byte[128], new byte[32], 0, 128, new byte[1]); PackageProtector.Protect(default, new byte[128], new byte[32], 0, 128, new byte[1]);