global-functions: add $GetRandomSha256

This commit is contained in:
Christian Hesse 2020-06-18 12:23:50 +02:00
parent 3589416840
commit a1d05f93c6

View file

@ -28,6 +28,7 @@
:global DownloadPackage; :global DownloadPackage;
:global GetMacVendor; :global GetMacVendor;
:global GetRandom; :global GetRandom;
:global GetRandomSha256;
:global LogPrintExit; :global LogPrintExit;
:global MailServerIsUp; :global MailServerIsUp;
:global MkDir; :global MkDir;
@ -316,6 +317,17 @@
:return ($Sum % $Max); :return ($Sum % $Max);
} }
# generate random sha256 string
# returns 64 bytes of 0-9 and a-f
:set GetRandomSha256 do={
:local FingerPrint;
/ certificate add name=GetRandomSha256-template common-name=GetRandomSha256 key-size=prime256v1;
/ certificate sign GetRandomSha256-template name=GetRandomSha256 without-paging as-value;
:set FingerPrint [ / certificate get GetRandomSha256 fingerprint ];
/ certificate remove GetRandomSha256;
:return $FingerPrint;
}
# log and print with same text, optionally exit # log and print with same text, optionally exit
:set LogPrintExit do={ :set LogPrintExit do={
:local Severity [ :tostr $1 ]; :local Severity [ :tostr $1 ];