CngCbcAuthenticatedEncryptorConfigurationTests.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) .NET Foundation. All rights reserved.
  2. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  3. using System;
  4. using Xunit;
  5. namespace Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel
  6. {
  7. public class CngCbcAuthenticatedEncryptorConfigurationTests
  8. {
  9. [Fact]
  10. public void CreateNewDescriptor_CreatesUniqueCorrectlySizedMasterKey()
  11. {
  12. // Arrange
  13. var configuration = new CngCbcAuthenticatedEncryptorConfiguration(new CngCbcAuthenticatedEncryptionSettings());
  14. // Act
  15. var masterKey1 = ((CngCbcAuthenticatedEncryptorDescriptor)configuration.CreateNewDescriptor()).MasterKey;
  16. var masterKey2 = ((CngCbcAuthenticatedEncryptorDescriptor)configuration.CreateNewDescriptor()).MasterKey;
  17. // Assert
  18. SecretAssert.NotEqual(masterKey1, masterKey2);
  19. SecretAssert.LengthIs(512 /* bits */, masterKey1);
  20. SecretAssert.LengthIs(512 /* bits */, masterKey2);
  21. }
  22. [Fact]
  23. public void CreateNewDescriptor_PropagatesOptions()
  24. {
  25. // Arrange
  26. var configuration = new CngCbcAuthenticatedEncryptorConfiguration(new CngCbcAuthenticatedEncryptionSettings());
  27. // Act
  28. var descriptor = (CngCbcAuthenticatedEncryptorDescriptor)configuration.CreateNewDescriptor();
  29. // Assert
  30. Assert.Equal(configuration.Settings, descriptor.Settings);
  31. }
  32. }
  33. }