Foobar
This commit is contained in:
parent
19aa55d43e
commit
5e88923de4
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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 }
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue