// 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.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); } }
/// <exception cref="System.Exception"/> public virtual void TestGetInstance() { Assume.AssumeTrue(OpensslCipher.GetLoadingFailureReason() == null); OpensslCipher cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding"); Assert.True(cipher != null); try { cipher = OpensslCipher.GetInstance("AES2/CTR/NoPadding"); NUnit.Framework.Assert.Fail("Should specify correct algorithm."); } catch (NoSuchAlgorithmException) { } // Expect NoSuchAlgorithmException try { cipher = OpensslCipher.GetInstance("AES/CTR/NoPadding2"); NUnit.Framework.Assert.Fail("Should specify correct padding."); } catch (NoSuchPaddingException) { } }
/// <exception cref="GeneralSecurityException"/> public OpensslAesCtrCipher(int mode) { this.mode = mode; cipher = OpensslCipher.GetInstance(Suite.GetName()); }