Refactor to make OTA code more independent and clear.

and misc changes
This commit is contained in:
noisyfox
2016-09-03 08:57:33 +08:00
committed by Syrone Wong
parent 4c5376ce0b
commit e6e9fc8588
2 changed files with 56 additions and 55 deletions
@@ -83,7 +83,8 @@ namespace Shadowsocks.Encryption
* == MBEDTLS_{EN,DE}CRYPT
*
*/
if (MbedTLS.cipher_setkey(ctx, realkey, keyLen * 8, isCipher ? MbedTLS.MBEDTLS_ENCRYPT : MbedTLS.MBEDTLS_DECRYPT) != 0 )
if (MbedTLS.cipher_setkey(ctx, realkey, keyLen * 8,
isCipher ? MbedTLS.MBEDTLS_ENCRYPT : MbedTLS.MBEDTLS_DECRYPT) != 0 )
throw new Exception("Cannot set mbed TLS cipher key");
if (MbedTLS.cipher_set_iv(ctx, iv, ivLen) != 0)
throw new Exception("Cannot set mbed TLS cipher IV");
@@ -98,16 +99,8 @@ namespace Shadowsocks.Encryption
{
throw new ObjectDisposedException(this.ToString());
}
IntPtr ctx;
if (isCipher)
{
ctx = _encryptCtx;
}
else
{
ctx = _decryptCtx;
}
if (MbedTLS.cipher_update(ctx, buf, length, outbuf, ref length) != 0 )
if (MbedTLS.cipher_update(isCipher ? _encryptCtx : _decryptCtx,
buf, length, outbuf, ref length) != 0 )
throw new Exception("Cannot update mbed TLS cipher context");
}