You are here

private static function JWT::readDER in Auth0 Single Sign On 8.2

Reads binary DER-encoded data and decodes into a single object

Parameters

string $der the binary data in DER format:

int $offset the offset of the data stream containing the object: to decode

Return value

array [$offset, $data] the new offset and the decoded object

1 call to JWT::readDER()
JWT::signatureFromDER in vendor/firebase/php-jwt/src/JWT.php
Encodes signature from a DER object.

File

vendor/firebase/php-jwt/src/JWT.php, line 481

Class

JWT
JSON Web Token implementation, based on this spec: https://tools.ietf.org/html/rfc7519

Namespace

Firebase\JWT

Code

private static function readDER($der, $offset = 0) {
  $pos = $offset;
  $size = \strlen($der);
  $constructed = \ord($der[$pos]) >> 5 & 0x1;
  $type = \ord($der[$pos++]) & 0x1f;

  // Length
  $len = \ord($der[$pos++]);
  if ($len & 0x80) {
    $n = $len & 0x1f;
    $len = 0;
    while ($n-- && $pos < $size) {
      $len = $len << 8 | \ord($der[$pos++]);
    }
  }

  // Value
  if ($type == self::ASN1_BIT_STRING) {
    $pos++;

    // Skip the first contents octet (padding indicator)
    $data = \substr($der, $pos, $len - 1);
    $pos += $len - 1;
  }
  elseif (!$constructed) {
    $data = \substr($der, $pos, $len);
    $pos += $len;
  }
  else {
    $data = null;
  }
  return array(
    $pos,
    $data,
  );
}