You are here

function _openid_dh_long_to_binary in Drupal 6

Same name and namespace in other branches
  1. 7 modules/openid/openid.inc \_openid_dh_long_to_binary()
3 calls to _openid_dh_long_to_binary()
_openid_dh_long_to_base64 in modules/openid/openid.inc
_openid_dh_rand in modules/openid/openid.inc
_openid_dh_xorsecret in modules/openid/openid.inc

File

modules/openid/openid.inc, line 293
OpenID utility functions.

Code

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