public void Without_Type_Null_Input_Byte_Key_Returns_Empty(string input) { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = input.Decrypt(key); // Assert Assert.Equal(string.Empty, result); }
public void Incorrect_Byte_Key_Returns_None() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = defaultInputStringEncryptedWithByteKey.Decrypt <string>(key); // Assert result.AssertNone().AssertType <IncorrectKeyOrNonceExceptionMsg>(); }
public void Null_Input_Byte_Key_Returns_None(string input) { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = input.Decrypt <int>(key); // Assert result.AssertNone().AssertType <DeserialisingNullOrEmptyStringMsg>(); }
public void Without_Type_Incorrect_Byte_Key_Returns_Empty() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = defaultInputStringEncryptedWithByteKey.Decrypt(key); // Assert Assert.Equal(string.Empty, result); }
public void Incorrect_Json_Input_Byte_Key_Returns_None() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); const string json = /*lang=json,strict*/ "{\"foo\":\"bar\"}"; // Act var result = json.Decrypt <int>(key); // Assert result.AssertNone().AssertType <UnlockWhenEncryptedContentsIsNoneMsg>(); }
public void Invalid_Json_Input_Byte_Key_Returns_None() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); var json = Rnd.Str; // Act var result = json.Decrypt <int>(key); // Assert result.AssertNone().AssertType <DeserialiseExceptionMsg>(); }
public void GenerateKey_Returns32ByteArray() { // Arrange // Act var result = CryptoF.GenerateKey(); // Assert var some = result.AssertSome(); Assert.Equal(32, some.Length); }
public void Without_Type_Incorrect_Json_Input_Byte_Key_Returns_Empty() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); const string json = /*lang=json,strict*/ "{\"foo\":\"bar\"}"; // Act var result = json.Decrypt(key); // Assert Assert.Equal(string.Empty, result); }
public void Without_Type_Invalid_Json_Input_Byte_Key_Returns_Empty() { // Arrange var key = CryptoF.GenerateKey().UnsafeUnwrap(); var json = Rnd.Str; // Act var result = json.Decrypt(key); // Assert Assert.Equal(string.Empty, result); }
public void No_EncryptedContents_Returns_None_With_UnlockWhenEncryptedContentsIsNullMsg() { // Arrange var box = new Locked <int>(); var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = box.Unlock(key); // Assert result.AssertNone().AssertType <UnlockWhenEncryptedContentsIsNoneMsg>(); }
public void Invalid_Key_Returns_None_With_InvalidKeyExceptionMsg() { // Arrange var value = Rnd.Str; var key = CryptoF.GenerateKey().UnsafeUnwrap(); var box = new Locked <string>(value, key); // Act var result = box.Unlock(Rnd.ByteF.Get(16)); // Assert result.AssertNone().AssertType <InvalidKeyExceptionMsg>(); }
public void GenerateKey_ReturnsUniqueValues() { // Arrange // Act var r0 = CryptoF.GenerateKey(); var r1 = CryptoF.GenerateKey(); // Assert var s0 = r0.AssertSome(); var s1 = r1.AssertSome(); Assert.NotEqual(s0, s1); }
public void Incorrect_Key_Returns_None_With_IncorrectKeyOrNonceMsg() { // Arrange var value = Rnd.Str; var key = CryptoF.GenerateKey().UnsafeUnwrap(); var incorrectKey = CryptoF.GenerateKey().UnsafeUnwrap(); var box = new Locked <string>(value, key); // Act var result = box.Unlock(incorrectKey); // Assert result.AssertNone().AssertType <IncorrectKeyOrNonceExceptionMsg>(); }
public void Byte_Key_Returns_Lockable() { // Arrange var value = Rnd.Str; var key = CryptoF.GenerateKey().UnsafeUnwrap(); var box = new Locked <string>(value, key); // Act var result = box.Unlock(key); // Assert var some = result.AssertSome(); Assert.Equal(value, some.Contents); }
public void Byte_Key_Fills_With_Encrypted_Contents() { // Arrange var value = Rnd.Str; var key = CryptoF.GenerateKey().UnsafeUnwrap(); // Act var result = new Locked <string>(value, key); // Assert Assert.NotEmpty(result.Salt); Assert.NotEmpty(result.Nonce); var some = result.EncryptedContents.AssertSome(); Assert.NotEmpty(some); }
public void Returns_Json() { // Arrange var value = Rnd.Str; var key = CryptoF.GenerateKey().UnsafeUnwrap(); var box = new Locked <string>(value, key); var json = string.Format("{{\"encryptedContents\":\"{0}\",\"salt\":\"{1}\",\"nonce\":\"{2}\"}}", Convert.ToBase64String(box.EncryptedContents.UnsafeUnwrap()), Convert.ToBase64String(box.Salt), Convert.ToBase64String(box.Nonce) ); // Act var result = box.Serialise(); // Assert var some = result.AssertSome(); Assert.Equal(json, some); }