@@ -76,46 +76,43 @@ internal static RsaPaddingProcessor OpenProcessor(HashAlgorithmName hashAlgorith
76
76
hashAlgorithmName ,
77
77
static hashAlgorithmName =>
78
78
{
79
- using ( IncrementalHash hasher = IncrementalHash . CreateHash ( hashAlgorithmName ) )
80
- {
81
- // SHA-2-512 is the biggest we expect
82
- Span < byte > stackDest = stackalloc byte [ 512 / 8 ] ;
83
- ReadOnlyMemory < byte > digestInfoPrefix ;
84
-
85
- if ( hashAlgorithmName == HashAlgorithmName . MD5 )
86
- {
87
- digestInfoPrefix = s_digestInfoMD5 ;
88
- }
89
- else if ( hashAlgorithmName == HashAlgorithmName . SHA1 )
90
- {
91
- digestInfoPrefix = s_digestInfoSha1 ;
92
- }
93
- else if ( hashAlgorithmName == HashAlgorithmName . SHA256 )
94
- {
95
- digestInfoPrefix = s_digestInfoSha256 ;
96
- }
97
- else if ( hashAlgorithmName == HashAlgorithmName . SHA384 )
98
- {
99
- digestInfoPrefix = s_digestInfoSha384 ;
100
- }
101
- else if ( hashAlgorithmName == HashAlgorithmName . SHA512 )
102
- {
103
- digestInfoPrefix = s_digestInfoSha512 ;
104
- }
105
- else
106
- {
107
- Debug . Fail ( "Unknown digest algorithm" ) ;
108
- throw new CryptographicException ( ) ;
109
- }
79
+ ReadOnlyMemory < byte > digestInfoPrefix ;
80
+ int digestLength ;
110
81
111
- if ( hasher . TryGetHashAndReset ( stackDest , out int bytesWritten ) )
112
- {
113
- return new RsaPaddingProcessor ( hashAlgorithmName , bytesWritten , digestInfoPrefix ) ;
114
- }
115
-
116
- byte [ ] big = hasher . GetHashAndReset ( ) ;
117
- return new RsaPaddingProcessor ( hashAlgorithmName , big . Length , digestInfoPrefix ) ;
82
+ if ( hashAlgorithmName == HashAlgorithmName . MD5 )
83
+ {
84
+ digestInfoPrefix = s_digestInfoMD5 ;
85
+ #pragma warning disable CA1416 // Unsupported on Browser. We just want the const here.
86
+ digestLength = MD5 . HashSizeInBytes ;
87
+ #pragma warning restore CA1416
88
+ }
89
+ else if ( hashAlgorithmName == HashAlgorithmName . SHA1 )
90
+ {
91
+ digestInfoPrefix = s_digestInfoSha1 ;
92
+ digestLength = SHA1 . HashSizeInBytes ;
93
+ }
94
+ else if ( hashAlgorithmName == HashAlgorithmName . SHA256 )
95
+ {
96
+ digestInfoPrefix = s_digestInfoSha256 ;
97
+ digestLength = SHA256 . HashSizeInBytes ;
98
+ }
99
+ else if ( hashAlgorithmName == HashAlgorithmName . SHA384 )
100
+ {
101
+ digestInfoPrefix = s_digestInfoSha384 ;
102
+ digestLength = SHA384 . HashSizeInBytes ;
118
103
}
104
+ else if ( hashAlgorithmName == HashAlgorithmName . SHA512 )
105
+ {
106
+ digestInfoPrefix = s_digestInfoSha512 ;
107
+ digestLength = SHA512 . HashSizeInBytes ;
108
+ }
109
+ else
110
+ {
111
+ Debug . Fail ( "Unknown digest algorithm" ) ;
112
+ throw new CryptographicException ( ) ;
113
+ }
114
+
115
+ return new RsaPaddingProcessor ( hashAlgorithmName , digestLength , digestInfoPrefix ) ;
119
116
} ) ;
120
117
}
121
118
0 commit comments