// Expect NoSuchPaddingException /// <exception cref="System.Exception"/> public virtual void TestUpdateArguments() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); cipher.Init(OpensslCipher.EncryptMode, key, iv); // Require direct buffers ByteBuffer input = ByteBuffer.Allocate(1024); ByteBuffer output = ByteBuffer.Allocate(1024); try { cipher.Update(input, output); NUnit.Framework.Assert.Fail("Input and output buffer should be direct buffer."); } catch (ArgumentException e) { GenericTestUtils.AssertExceptionContains("Direct buffers are required", e); } // Output buffer length should be sufficient to store output data input = ByteBuffer.AllocateDirect(1024); output = ByteBuffer.AllocateDirect(1000); try { cipher.Update(input, output); NUnit.Framework.Assert.Fail("Output buffer length should be sufficient " + "to store output data" ); } catch (ShortBufferException e) { GenericTestUtils.AssertExceptionContains("Output buffer is not sufficient", e); } }
/// <exception cref="System.IO.IOException"/> public virtual void Init(byte[] key, byte[] iv) { Preconditions.CheckNotNull(key); Preconditions.CheckNotNull(iv); contextReset = false; cipher.Init(mode, key, iv); }
/// <exception cref="System.Exception"/> public virtual void TestDoFinalArguments() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); cipher.Init(OpensslCipher.EncryptMode, key, iv); // Require direct buffer ByteBuffer output = ByteBuffer.Allocate(1024); try { cipher.DoFinal(output); NUnit.Framework.Assert.Fail("Output buffer should be direct buffer."); } catch (ArgumentException e) { GenericTestUtils.AssertExceptionContains("Direct buffer is required", e); } }