@@ -28,22 +28,22 @@ public SSHCOM(byte[] data, string? passPhrase)
2828
2929 public Key Parse ( )
3030 {
31- var reader = new SshDataStream ( _data ) ;
32- var magicNumber = reader . ReadUInt32 ( ) ;
31+ using var dataReader = new SshDataStream ( _data ) ;
32+ var magicNumber = dataReader . ReadUInt32 ( ) ;
3333 if ( magicNumber != 0x3f6ff9eb )
3434 {
3535 throw new SshException ( "Invalid SSH2 private key." ) ;
3636 }
3737
38- _ = reader . ReadUInt32 ( ) ; // Read total bytes length including magic number
39- var keyType = reader . ReadString ( SshData . Ascii ) ;
40- var ssh2CipherName = reader . ReadString ( SshData . Ascii ) ;
41- var blobSize = ( int ) reader . ReadUInt32 ( ) ;
38+ _ = dataReader . ReadUInt32 ( ) ; // Read total bytes length including magic number
39+ var keyType = dataReader . ReadString ( SshData . Ascii ) ;
40+ var ssh2CipherName = dataReader . ReadString ( SshData . Ascii ) ;
41+ var blobSize = ( int ) dataReader . ReadUInt32 ( ) ;
4242
4343 byte [ ] keyData ;
4444 if ( ssh2CipherName == "none" )
4545 {
46- keyData = reader . ReadBytes ( blobSize ) ;
46+ keyData = dataReader . ReadBytes ( blobSize ) ;
4747 }
4848 else if ( ssh2CipherName == "3des-cbc" )
4949 {
@@ -53,17 +53,17 @@ public Key Parse()
5353 }
5454
5555 var key = GetCipherKey ( _passPhrase , 192 / 8 ) ;
56- var ssh2Сipher = new TripleDesCipher ( key , new byte [ 8 ] , CipherMode . CBC , pkcs7Padding : false ) ;
57- keyData = ssh2Сipher . Decrypt ( reader . ReadBytes ( blobSize ) ) ;
56+ using var ssh2Сipher = new TripleDesCipher ( key , new byte [ 8 ] , CipherMode . CBC , pkcs7Padding : false ) ;
57+ keyData = ssh2Сipher . Decrypt ( dataReader . ReadBytes ( blobSize ) ) ;
5858 }
5959 else
6060 {
6161 throw new SshException ( string . Format ( "Cipher method '{0}' is not supported." , ssh2CipherName ) ) ;
6262 }
6363
64- reader = new SshDataStream ( keyData ) ;
64+ using var keyReader = new SshDataStream ( keyData ) ;
6565
66- var decryptedLength = reader . ReadUInt32 ( ) ;
66+ var decryptedLength = keyReader . ReadUInt32 ( ) ;
6767
6868 if ( decryptedLength > blobSize - 4 )
6969 {
@@ -72,12 +72,12 @@ public Key Parse()
7272
7373 if ( keyType . Contains ( "rsa" ) )
7474 {
75- var exponent = ReadBigIntWithBits ( reader ) ;
76- var d = ReadBigIntWithBits ( reader ) ;
77- var modulus = ReadBigIntWithBits ( reader ) ;
78- var inverseQ = ReadBigIntWithBits ( reader ) ;
79- var q = ReadBigIntWithBits ( reader ) ;
80- var p = ReadBigIntWithBits ( reader ) ;
75+ var exponent = ReadBigIntWithBits ( keyReader ) ;
76+ var d = ReadBigIntWithBits ( keyReader ) ;
77+ var modulus = ReadBigIntWithBits ( keyReader ) ;
78+ var inverseQ = ReadBigIntWithBits ( keyReader ) ;
79+ var q = ReadBigIntWithBits ( keyReader ) ;
80+ var p = ReadBigIntWithBits ( keyReader ) ;
8181 return new RsaKey ( modulus , exponent , d , p , q , inverseQ ) ;
8282 }
8383
0 commit comments