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 }
{ (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 }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
@ -40,6 +40,7 @@ Unit Renegade.Random.BSDRandom;
interface
uses
CTypes,
Objects,
Classes,
SysUtils,
@ -49,11 +50,16 @@ uses
type
PBSDRandom = ^BSDRandom;
BSDRandom = class (RandomTrait, RandomInterface)
private
function GetSystemBytes(var RandomByteBuffer : TBytes; NBytes : SizeUint) : CInt;
public
function GetBytes(NBytes : SizeUInt) : TBytes;
function GetString(NBytes : SizeUInt) : AnsiString;
end;
procedure arc4random_buf(var Buffer : PCChar; StringLength : SizeInt);
cdecl;varargs;external 'c' name 'arc4random_buf';
implementation

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or }
{ (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 }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or }
{ (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 }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }

View File

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

View File

@ -13,7 +13,7 @@
{ Foundation, either version 3 of the License, or }
{ (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 }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }

View File

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