You are here

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

Parameters

int $type:

string $string:

Return value

null|string

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

File

src/XMLSecurityKey.php, line 601

Class

XMLSecurityKey

Namespace

Drupal\miniorange_saml

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;
}