function _openid_dh_long_to_binary

4 calls to _openid_dh_long_to_binary()
OpenIDTest::testConversion in drupal/core/modules/openid/lib/Drupal/openid/Tests/OpenIDTest.php
Test _openid_dh_XXX_to_XXX() functions.
_openid_dh_long_to_base64 in drupal/core/modules/openid/openid.inc
_openid_dh_rand in drupal/core/modules/openid/openid.inc
_openid_dh_xorsecret in drupal/core/modules/openid/openid.inc

File

drupal/core/modules/openid/openid.inc, line 468
OpenID utility functions.

Code

function _openid_dh_long_to_binary($long) {
  $cmp = _openid_math_cmp($long, 0);
  if ($cmp < 0) {
    return FALSE;
  }
  if ($cmp == 0) {
    return "\0";
  }
  $bytes = array();
  while (_openid_math_cmp($long, 0) > 0) {
    array_unshift($bytes, _openid_math_mod($long, 256));
    $long = _openid_math_div($long, pow(2, 8));
  }
  if ($bytes && $bytes[0] > 127) {
    array_unshift($bytes, 0);
  }
  $string = '';
  foreach ($bytes as $byte) {
    $string .= pack('C', $byte);
  }
  return $string;
}