Kelunik\Acme\AcmeService::doRequestCertificate PHP Method

doRequestCertificate() private method

Requests a new certificate.
private doRequestCertificate ( string $csr ) : Generator
$csr string certificate signing request
return Generator coroutine resolved by Amp returning the URI where the certificate will be provided
    private function doRequestCertificate($csr)
    {
        if (!is_string($csr)) {
            throw new \InvalidArgumentException(sprintf("\$csr must be of type bool, %s given", gettype($csr)));
        }
        $begin = "REQUEST-----";
        $end = "----END";
        $beginPos = strpos($csr, $begin) + strlen($begin);
        if ($beginPos === false) {
            throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
        }
        $csr = substr($csr, $beginPos);
        $endPos = strpos($csr, $end);
        if ($endPos === false) {
            throw new InvalidArgumentException("Invalid CSR, maybe not in PEM format?\n{$csr}");
        }
        $csr = substr($csr, 0, $endPos);
        $enc = new Base64UrlSafeEncoder();
        /** @var Response $response */
        $response = (yield $this->acmeClient->post(AcmeResource::NEW_CERTIFICATE, ["csr" => $enc->encode(base64_decode($csr))]));
        if ($response->getStatus() === 201) {
            if (!$response->hasHeader("location")) {
                throw new AcmeException("Protocol Violation: No Location Header");
            }
            (yield new CoroutineResult(current($response->getHeader("location"))));
            return;
        }
        throw $this->generateException($response);
    }