示例#1
0
        public void CalculateMessageLength()
        {
            const int ciphertextLength = 80;
            const int expectedLength   = ciphertextLength - HeaderBytes;
            var       sb = new SecretBox();

            Assert.That(sb.CalculateMessageLength(ciphertextLength), Is.EqualTo(expectedLength));
        }
示例#2
0
        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)}"));
        }
示例#3
0
        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"));
        }
示例#4
0
        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"));
        }
示例#5
0
        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'"));
        }