示例#1
0
 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}";
 }
示例#2
0
 /**
  * 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);
 }
示例#3
0
 private static function nonce()
 {
     $time = time();
     return "apigen-{$time}-" . md5(\Dcrypt\Random::bytes(16));
 }
示例#4
0
 public function testGet()
 {
     $len = 10;
     $m = \Dcrypt\Random::bytes($len);
     $this->assertTrue(strlen($m) === $len);
 }