22// The .NET Foundation licenses this file to you under the MIT license.
33
44using System ;
5+ using System . Runtime . CompilerServices ;
56using Microsoft . AspNetCore . Cryptography ;
67using Microsoft . AspNetCore . Cryptography . Cng ;
78using Microsoft . AspNetCore . Cryptography . SafeHandles ;
@@ -363,7 +364,7 @@ public override bool TryEncrypt(ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte>
363364 byte * pbOutputHmac = & pbOutputCiphertext[ cbOutputCiphertext] ;
364365
365366 // Copy key modifier and IV to destination
366- UnsafeBufferUtil . BlockCopy ( from : pbKeyModifierAndIV , to : pbOutputKeyModifier , byteCount : cbKeyModifierAndIV ) ;
367+ Unsafe . CopyBlock ( pbOutputKeyModifier , pbKeyModifierAndIV , cbKeyModifierAndIV ) ;
367368 bytesWritten += checked ( ( int ) cbKeyModifierAndIV) ;
368369
369370 // Perform CBC encryption directly into destination
@@ -512,7 +513,6 @@ private uint GetCbcEncryptedOutputSizeWithPadding(uint cbInput)
512513 byte * pbDummyIV = stackalloc byte [ checked ( ( int ) _symmetricAlgorithmBlockSizeInBytes ) ] ;
513514 byte * pbDummyInput = stackalloc byte [ checked ( ( int ) cbInput ) ] ;
514515
515- uint dwResult ;
516516 var ntstatus = UnsafeNativeMethods . BCryptEncrypt (
517517 hKey : tempKeyHandle ,
518518 pbInput : pbDummyInput ,
@@ -522,7 +522,7 @@ private uint GetCbcEncryptedOutputSizeWithPadding(uint cbInput)
522522 cbIV : _symmetricAlgorithmBlockSizeInBytes ,
523523 pbOutput : null , // NULL output = size query only
524524 cbOutput : 0 ,
525- pcbResult : out dwResult ,
525+ pcbResult : out var dwResult ,
526526 dwFlags : BCryptEncryptFlags . BCRYPT_BLOCK_PADDING ) ;
527527 UnsafeNativeMethods. ThrowExceptionForBCryptStatus ( ntstatus ) ;
528528
@@ -536,7 +536,6 @@ private uint GetCbcEncryptedOutputSizeWithPadding(BCryptKeyHandle symmetricKeyHa
536536
537537 // Calling BCryptEncrypt with a null output pointer will cause it to return the total number
538538 // of bytes required for the output buffer.
539- uint dwResult ;
540539 var ntstatus = UnsafeNativeMethods . BCryptEncrypt (
541540 hKey : symmetricKeyHandle ,
542541 pbInput : pbInput ,
@@ -546,7 +545,7 @@ private uint GetCbcEncryptedOutputSizeWithPadding(BCryptKeyHandle symmetricKeyHa
546545 cbIV : _symmetricAlgorithmBlockSizeInBytes ,
547546 pbOutput : null ,
548547 cbOutput : 0 ,
549- pcbResult : out dwResult ,
548+ pcbResult : out var dwResult ,
550549 dwFlags : BCryptEncryptFlags . BCRYPT_BLOCK_PADDING ) ;
551550 UnsafeNativeMethods. ThrowExceptionForBCryptStatus ( ntstatus ) ;
552551
0 commit comments