Browse Source

use optional chain syntax in RNG.cs

Hope it will resolve errors in CI.
tags/4.1.9.0
Student Main 4 years ago
parent
commit
0f0f41a4d4
1 changed files with 4 additions and 6 deletions
  1. +4
    -6
      shadowsocks-csharp/Encryption/RNG.cs

+ 4
- 6
shadowsocks-csharp/Encryption/RNG.cs View File

@@ -9,14 +9,12 @@ namespace Shadowsocks.Encryption
public static void Init()
{
if (_rng == null)
_rng = new RNGCryptoServiceProvider();
_rng = _rng ?? new RNGCryptoServiceProvider();
}
public static void Close()
{
if (_rng == null) return;
_rng.Dispose();
_rng?.Dispose();
_rng = null;
}
@@ -33,12 +31,12 @@ namespace Shadowsocks.Encryption
public static void GetBytes(byte[] buf, int len)
{
if (_rng == null) Reload();
if (_rng == null) Init();
try
{
_rng.GetBytes(buf, 0, len);
}
catch (System.Exception)
catch
{
// the backup way
byte[] tmp = new byte[len];


Loading…
Cancel
Save