public void CalculateMessageLength() { const int ciphertextLength = 80; const int expectedLength = ciphertextLength - HeaderBytes; var sb = new SecretBox(); Assert.That(sb.CalculateMessageLength(ciphertextLength), Is.EqualTo(expectedLength)); }
public void CalculateMessageLength_Invalid(int ciphertextLength) { var sb = new SecretBox(); Assert.That( () => sb.CalculateMessageLength(ciphertextLength), Throws.ArgumentException.With.Message.EqualTo( $"ciphertextLength must be greater than {nameof(HeaderBytes)}")); }
public void Decrypt_ValidateKeyLength(int keyLength) { var sb = new SecretBox(); var key = new byte[keyLength]; const int clen = 100; var c = new byte[clen]; var m = new byte[sb.CalculateMessageLength(clen)]; var ctx = "test"; Assert.That( () => sb.Decrypt(m, c, clen, key, ctx), Throws.ArgumentException.With.Message.EqualTo( $"'key' length must be {KeyBytes} bytes")); }
public void Decrypt_ValidateContextLength_TooLong() { var sb = new SecretBox(); var key = new byte[KeyBytes]; const int clen = 100; var c = new byte[clen]; var m = new byte[sb.CalculateMessageLength(clen)]; var ctx = "you are old father william"; Assert.That( () => sb.Decrypt(m, c, clen, key, ctx), Throws.ArgumentException.With.Message.EqualTo( $"'context' must be at most {ContextBytes} characters")); }
public void Decrypt_ValidateCiphertextLength_TooLong() { var sb = new SecretBox(); var key = new byte[KeyBytes]; const int clen = 200; const int clenActual = 100; var c = new byte[clenActual]; var m = new byte[sb.CalculateMessageLength(clenActual)]; var ctx = "test"; Assert.That( () => sb.Decrypt(m, c, clen, key, ctx), Throws.ArgumentException.With.Message.EqualTo( $"'ciphertextLength' must be at most the length of 'ciphertext'")); }