public void GenerateNonce_Returns24ByteArray() { // Arrange // Act var nonce = CryptoF.GenerateNonce(); // Assert Assert.Equal(24, nonce.Length); }
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 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 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 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 GenerateNonce_ReturnsUniqueValues() { // Arrange // Act var nonce1 = CryptoF.GenerateNonce(); var nonce2 = CryptoF.GenerateNonce(); // Assert Assert.NotEqual(nonce1, nonce2); }
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 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 Includes_A_Number() { // Arrange // Act var result = CryptoF.GeneratePassphrase(); // Assert var some = result.AssertSome(); Assert.Contains(some, x => char.IsNumber(x)); }
public void Uses_Correct_Number_Of_Words(int input) { // Arrange // Act var result = CryptoF.GeneratePassphrase(input); // Assert var some = result.AssertSome().Split('-'); Assert.Equal(input, some.Length); }
public void Makes_First_Letters_Upper_Case() { // Arrange // Act var result = CryptoF.GeneratePassphrase(); // Assert var some = result.AssertSome(); Assert.NotEqual(some, some.ToLower()); }
public void NumberOfWords_Less_Than_Five_Returns_None_With_CryptographicallySecurePassphrasesMustContainAtLeastFiveWordsMsg(int input) { // Arrange // Act var result = CryptoF.GeneratePassphrase(input); // Assert var none = result.AssertNone().AssertType <CryptographicallySecurePassphrasesMustContainAtLeastFiveWordsMsg>(); Assert.Equal(input, none.Value); }
public void Uses_Eight_Words() { // Arrange // Act var result = CryptoF.GeneratePassphrase(); // Assert var some = result.AssertSome().Split('-'); Assert.Equal(8, some.Length); }
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 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 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 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 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); }
string input when !string.IsNullOrWhiteSpace(input) => CryptoF.Hash(@this, bytes) .Map( x => Convert.ToBase64String(x), F.DefaultHandler ),