You are here

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

Convert an ECDSA signature to an ASN.1 DER sequence

Parameters

string $sig The ECDSA signature to convert:

Return value

string The encoded DER object

1 call to JWT::signatureToDER()
JWT::decode in vendor/firebase/php-jwt/src/JWT.php
Decodes a JWT string into a PHP object.

File

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

Class

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

Namespace

Firebase\JWT

Code

private static function signatureToDER($sig) {

  // Separate the signature into r-value and s-value
  list($r, $s) = \str_split($sig, (int) (\strlen($sig) / 2));

  // Trim leading zeros
  $r = \ltrim($r, "\0");
  $s = \ltrim($s, "\0");

  // Convert r-value and s-value from unsigned big-endian integers to
  // signed two's complement
  if (\ord($r[0]) > 0x7f) {
    $r = "\0" . $r;
  }
  if (\ord($s[0]) > 0x7f) {
    $s = "\0" . $s;
  }
  return self::encodeDER(self::ASN1_SEQUENCE, self::encodeDER(self::ASN1_INTEGER, $r) . self::encodeDER(self::ASN1_INTEGER, $s));
}