- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.2k
 
Fix Equals for cryptographic wrappers #118715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 6 commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      5d0ac18
              
                Fix Equals override on RSAWrapper
              
              
                vcsjones 532b4b3
              
                Fixup EC-DSA
              
              
                vcsjones 3922e30
              
                And ECDH
              
              
                vcsjones d5898dc
              
                Just remove the overrides entirely
              
              
                vcsjones 2d6cd6f
              
                DSA, too
              
              
                vcsjones 9132412
              
                Get rid of GetHashCode override, too
              
              
                vcsjones 1155905
              
                Update src/libraries/Common/tests/System/Security/Cryptography/Algori…
              
              
                vcsjones File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            36 changes: 36 additions & 0 deletions
          
          36 
        
  ...Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSAFactoryTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using Xunit; | ||
| 
     | 
||
| namespace System.Security.Cryptography.Dsa.Tests | ||
| { | ||
| [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst, "Not supported on Browser/iOS/tvOS/MacCatalyst")] | ||
| public partial class DSAFactoryTests | ||
| { | ||
| [Fact] | ||
| public static void DSACreateDefault_Equals_SameInstance() | ||
| { | ||
| using DSA dsa = DSAFactory.Create(); | ||
| dsa.ImportParameters(DSATestData.GetDSA1024Params()); | ||
| AssertExtensions.TrueExpression(dsa.Equals(dsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void DSACreateKeySize_Equals_SameInstance() | ||
| { | ||
| using DSA dsa = DSAFactory.Create(1024); | ||
| AssertExtensions.TrueExpression(dsa.Equals(dsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void ECDsaCreate_Equals_DifferentInstance_FalseForSameKeyMaterial() | ||
| { | ||
| using DSA dsa1 = DSAFactory.Create(); | ||
| using DSA dsa2 = DSAFactory.Create(); | ||
| dsa1.ImportParameters(DSATestData.GetDSA1024Params()); | ||
| dsa2.ImportParameters(DSATestData.GetDSA1024Params()); | ||
| AssertExtensions.FalseExpression(dsa1.Equals(dsa2)); | ||
| } | ||
| } | ||
| } | ||
        
          
          
            45 changes: 45 additions & 0 deletions
          
          45 
        
  ...rity/Cryptography/AlgorithmImplementations/ECDiffieHellman/ECDiffieHellmanFactoryTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using System.Security.Cryptography.Tests; | ||
| using Xunit; | ||
| 
     | 
||
| namespace System.Security.Cryptography.EcDiffieHellman.Tests | ||
| { | ||
| [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] | ||
| public static class ECDiffieHellmanFactoryTests | ||
| { | ||
| [Fact] | ||
| public static void ECDiffieHellmanCreateDefault_Equals_SameInstance() | ||
| { | ||
| using ECDiffieHellman ecdh = ECDiffieHellmanFactory.Create(); | ||
| AssertExtensions.TrueExpression(ecdh.Equals(ecdh)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void ECDiffieHellmanCreateKeySize_Equals_SameInstance() | ||
| { | ||
| using ECDiffieHellman ecdh = ECDiffieHellmanFactory.Create(256); | ||
| AssertExtensions.TrueExpression(ecdh.Equals(ecdh)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void ECDiffieHellmanCreateKeySize_Equals_DifferentInstance_FalseForSameKeyMaterial() | ||
| { | ||
| using ECDiffieHellman ecdh1 = ECDiffieHellmanFactory.Create(); | ||
| using ECDiffieHellman ecdh2 = ECDiffieHellmanFactory.Create(); | ||
| ecdh1.ImportParameters(EccTestData.GetNistP256ReferenceKey()); | ||
| ecdh2.ImportParameters(EccTestData.GetNistP256ReferenceKey()); | ||
| AssertExtensions.FalseExpression(ecdh1.Equals(ecdh2)); | ||
| } | ||
| 
     | 
||
| #if NET | ||
| [Fact] | ||
| public static void ECDiffieHellmanCreateCurve_Equals_SameInstance() | ||
| { | ||
| using ECDiffieHellman ecdh = ECDiffieHellmanFactory.Create(ECCurve.NamedCurves.nistP256); | ||
| AssertExtensions.TrueExpression(ecdh.Equals(ecdh)); | ||
| } | ||
| #endif | ||
| } | ||
| } | 
        
          
          
            45 changes: 45 additions & 0 deletions
          
          45 
        
  ...on/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaFactoryTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using System.Security.Cryptography.Tests; | ||
| using Xunit; | ||
| 
     | 
||
| namespace System.Security.Cryptography.EcDsa.Tests | ||
| { | ||
| [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] | ||
| public static class ECDsaFactoryTests | ||
| { | ||
| [Fact] | ||
| public static void ECDsaCreateDefault_Equals_SameInstance() | ||
| { | ||
| using ECDsa ecdsa = ECDsaFactory.Create(); | ||
| AssertExtensions.TrueExpression(ecdsa.Equals(ecdsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void ECDsaCreateKeySize_Equals_SameInstance() | ||
| { | ||
| using ECDsa ecdsa = ECDsaFactory.Create(256); | ||
| AssertExtensions.TrueExpression(ecdsa.Equals(ecdsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void ECDsaCreateKeySize_Equals_DifferentInstance_FalseForSameKeyMaterial() | ||
| { | ||
| using ECDsa ecdsa1 = ECDsaFactory.Create(); | ||
| using ECDsa ecdsa2 = ECDsaFactory.Create(); | ||
| ecdsa1.ImportParameters(EccTestData.GetNistP256ReferenceKey()); | ||
| ecdsa2.ImportParameters(EccTestData.GetNistP256ReferenceKey()); | ||
| AssertExtensions.FalseExpression(ecdsa1.Equals(ecdsa2)); | ||
| } | ||
| 
     | 
||
| #if NET | ||
| [Fact] | ||
| public static void ECDsaCreateCurve_Equals_SameInstance() | ||
| { | ||
| using ECDsa ecdsa = ECDsaFactory.Create(ECCurve.NamedCurves.nistP256); | ||
| AssertExtensions.TrueExpression(ecdsa.Equals(ecdsa)); | ||
| } | ||
| #endif | ||
| } | ||
| } | 
        
          
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  ...Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/RSAFactoryTests.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| 
     | 
||
| using Xunit; | ||
| 
     | 
||
| namespace System.Security.Cryptography.Rsa.Tests | ||
| { | ||
| [SkipOnPlatform(TestPlatforms.Browser, "Not supported on Browser")] | ||
| public static class RSAFactoryTests | ||
| { | ||
| [Fact] | ||
| public static void RSACreateDefault_Equals_SameInstance() | ||
| { | ||
| using RSA rsa = RSAFactory.Create(); | ||
| AssertExtensions.TrueExpression(rsa.Equals(rsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void RSACreateKeySize_Equals_SameInstance() | ||
| { | ||
| using RSA rsa = RSAFactory.Create(2048); | ||
| AssertExtensions.TrueExpression(rsa.Equals(rsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void RSACreateParameters_Equals_SameInstance() | ||
| { | ||
| using RSA rsa = RSAFactory.Create(TestData.RSA2048Params); | ||
| AssertExtensions.TrueExpression(rsa.Equals(rsa)); | ||
| } | ||
| 
     | 
||
| [Fact] | ||
| public static void RSACreateParameters_Equals_DifferentInstance_FalseForSameKeyMaterial() | ||
| { | ||
| using RSA rsa1 = RSAFactory.Create(TestData.RSA2048Params); | ||
| using RSA rsa2 = RSAFactory.Create(TestData.RSA2048Params); | ||
| AssertExtensions.FalseExpression(rsa1.Equals(rsa2)); | ||
| } | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.