You are here

public static function XMLSecurityKey::makeAsnSegment in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

Parameters

int $type:

string $string:

Return value

null|string

1 call to XMLSecurityKey::makeAsnSegment()
XMLSecurityKey::convertRSA in includes/XMLSecurityKey.php
Hint: Modulus and Exponent must already be base64 decoded

File

includes/XMLSecurityKey.php, line 634

Class

XMLSecurityKey

Code

public static function makeAsnSegment($type, $string) {
  switch ($type) {
    case 0x2:
      if (ord($string) > 0x7f) {
        $string = chr(0) . $string;
      }
      break;
    case 0x3:
      $string = chr(0) . $string;
      break;
  }
  $length = strlen($string);
  if ($length < 128) {
    $output = sprintf("%c%c%s", $type, $length, $string);
  }
  else {
    if ($length < 0x100) {
      $output = sprintf("%c%c%c%s", $type, 0x81, $length, $string);
    }
    else {
      if ($length < 0x10000) {
        $output = sprintf("%c%c%c%c%s", $type, 0x82, $length / 0x100, $length % 0x100, $string);
      }
      else {
        $output = null;
      }
    }
  }
  return $output;
}