public static function githubApiLoginUrl() { $state = \Session::get('state'); if ($state === null) { $state = md5(\Dcrypt\Random::bytes(16)); \Session::put('state', $state); } $url = urlencode('https://' . $_SERVER['HTTP_HOST']); $cid = env('APIGENCI_ID'); return "https://github.com/login/oauth/authorize?client_id={$cid}&redirect_uri={$url}&scope=write:repo_hook&state={$state}"; }
/** * Change a random byte, randomly. This function is used in unit testing * only and never in the namespaced areas of code. * * @param string $inp * @return string */ public static function swaprandbyte($inp) { // @codeCoverageIgnoreStart $len = strlen($inp); $inp = str_split($inp); $off = rand(0, $len - 1); $byte = $inp[$off]; $rbyte = \Dcrypt\Random::bytes(1); if ($byte === $rbyte) { $rbyte = (ord($rbyte) + 1) % 256; $rbyte = chr($rbyte); } $inp[$off] = $rbyte; // @codeCoverageIgnoreEnd return implode($inp); }
private static function nonce() { $time = time(); return "apigen-{$time}-" . md5(\Dcrypt\Random::bytes(16)); }
public function testGet() { $len = 10; $m = \Dcrypt\Random::bytes($len); $this->assertTrue(strlen($m) === $len); }