Ryujinx/Ryujinx.HLE/HOS/Services/Spl/IRandomInterface.cs

50 lines
1.2 KiB
C#
Raw Normal View History

using Ryujinx.HLE.HOS.Ipc;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Ryujinx.HLE.HOS.Services.Spl
{
class IRandomInterface : IpcService, IDisposable
{
2018-12-01 20:01:59 +00:00
private Dictionary<int, ServiceProcessRequest> _commands;
2018-12-01 20:01:59 +00:00
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
2018-12-01 20:01:59 +00:00
private RNGCryptoServiceProvider _rng;
public IRandomInterface()
{
2018-12-01 20:01:59 +00:00
_commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetRandomBytes }
};
2018-12-01 20:01:59 +00:00
_rng = new RNGCryptoServiceProvider();
}
2018-12-01 20:01:59 +00:00
public long GetRandomBytes(ServiceCtx context)
{
2018-12-01 20:01:59 +00:00
byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
2018-12-01 20:01:59 +00:00
_rng.GetBytes(randomBytes);
2018-12-01 20:01:59 +00:00
context.Memory.WriteBytes(context.Request.ReceiveBuff[0].Position, randomBytes);
return 0;
}
public void Dispose()
{
Dispose(true);
}
2018-12-01 20:01:59 +00:00
protected virtual void Dispose(bool disposing)
{
2018-12-01 20:01:59 +00:00
if (disposing)
{
2018-12-01 20:01:59 +00:00
_rng.Dispose();
}
}
}
}