RobRichards\XMLSecLibs\XMLSecurityKey::makeAsnSegment PHP Method

makeAsnSegment() public static method

public static makeAsnSegment ( integer $type, string $string ) : null | string
$type integer
$string string
return null | string
    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;
    }