public function parseSignedJSON(Response $response, SignaturePublicKey $publicKey)
{
$code = $response->getStatusCode();
if ($code >= 200 && $code < 300) {
$body = (string) $response->getBody();
$firstNewLine = \strpos($body, "\n");
// There should be a newline immediately after the base64urlsafe-encoded signature
if ($firstNewLine !== self::ENCODED_SIGNATURE_LENGTH) {
throw new SignatureFailed(\sprintf("First newline found at position %s, expected %d.\n%s", \print_r($firstNewLine, true), \print_r(self::ENCODED_SIGNATURE_LENGTH, true), Base64::encode($body)));
}
$sig = Base64UrlSafe::decode(Binary::safeSubstr($body, 0, 88));
$msg = Binary::safeSubstr($body, 89);
if (!Asymmetric::verify($msg, $publicKey, $sig, true)) {
throw new SignatureFailed();
}
return \Airship\parseJSON($msg, true);
}
throw new TransferException();
}