This commit is contained in:
R. Eric Wheeler 2016-05-04 11:02:09 -07:00
parent 19aa55d43e
commit 5e88923de4
6 changed files with 10 additions and 7 deletions

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or } { Foundation, either version 3 of the License, or }
{ (at your option) any later version. } { (at your option) any later version. }
{ } { }
{ Foobar is distributed in the hope that it will be } { Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the } { useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR } { implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public } { A PARTICULAR PURPOSE. See the GNU General Public }
@ -40,6 +40,7 @@ Unit Renegade.Random.BSDRandom;
interface interface
uses uses
CTypes,
Objects, Objects,
Classes, Classes,
SysUtils, SysUtils,
@ -49,11 +50,16 @@ uses
type type
PBSDRandom = ^BSDRandom; PBSDRandom = ^BSDRandom;
BSDRandom = class (RandomTrait, RandomInterface) BSDRandom = class (RandomTrait, RandomInterface)
private
function GetSystemBytes(var RandomByteBuffer : TBytes; NBytes : SizeUint) : CInt;
public public
function GetBytes(NBytes : SizeUInt) : TBytes; function GetBytes(NBytes : SizeUInt) : TBytes;
function GetString(NBytes : SizeUInt) : AnsiString; function GetString(NBytes : SizeUInt) : AnsiString;
end; end;
procedure arc4random_buf(var Buffer : PCChar; StringLength : SizeInt);
cdecl;varargs;external 'c' name 'arc4random_buf';
implementation implementation

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or } { Foundation, either version 3 of the License, or }
{ (at your option) any later version. } { (at your option) any later version. }
{ } { }
{ Foobar is distributed in the hope that it will be } { Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the } { useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR } { implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public } { A PARTICULAR PURPOSE. See the GNU General Public }

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or } { Foundation, either version 3 of the License, or }
{ (at your option) any later version. } { (at your option) any later version. }
{ } { }
{ Foobar is distributed in the hope that it will be } { Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the } { useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR } { implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public } { A PARTICULAR PURPOSE. See the GNU General Public }

View File

@ -71,7 +71,6 @@ var
RandomCharBuffer : PCChar; RandomCharBuffer : PCChar;
Return : CInt; Return : CInt;
begin begin
Writeln(SYS_getrandom);
GetMem(RandomCharBuffer, NBytes); GetMem(RandomCharBuffer, NBytes);
Return := syscall(SYS_getrandom, @RandomCharBuffer^, NBytes, GRND_DEFAULT); Return := syscall(SYS_getrandom, @RandomCharBuffer^, NBytes, GRND_DEFAULT);
Move(RandomCharBuffer[0], RandomByteBuffer[0], NBytes); Move(RandomCharBuffer[0], RandomByteBuffer[0], NBytes);

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or } { Foundation, either version 3 of the License, or }
{ (at your option) any later version. } { (at your option) any later version. }
{ } { }
{ Foobar is distributed in the hope that it will be } { Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the } { useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR } { implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public } { A PARTICULAR PURPOSE. See the GNU General Public }

View File

@ -24,8 +24,6 @@ begin
Assert(RRandom.InheritsFrom(RandomTrait)); Assert(RRandom.InheritsFrom(RandomTrait));
S := RRandom.GetString(22); S := RRandom.GetString(22);
T := RRandom.GetBytes(22); T := RRandom.GetBytes(22);
Writeln(S);
Writeln(Length(S));
Assert(Length(S) = 22); Assert(Length(S) = 22);
Assert(High(S) = 22); Assert(High(S) = 22);
Assert(Low(S) = 1); Assert(Low(S) = 1);