public static InternalRequestSignature fromHeaders(Crypto crypto, byte[] requestBody, HttpHeaders headers) {
        if (headers == null) {
            return null;
        }

        String signatureAlgorithm = headers.getHeaderString(SIGNATURE_ALGORITHM_HEADER);
        String encodedSignature = headers.getHeaderString(SIGNATURE_HEADER);
        if (signatureAlgorithm == null || encodedSignature == null) {
            return null;
        }

        Mac mac;
        try {
            mac = crypto.mac(signatureAlgorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new BadRequestException(e.getMessage());
        }

        byte[] decodedSignature;
        try {
            decodedSignature = Base64.getDecoder().decode(encodedSignature);
        } catch (IllegalArgumentException e) {
            throw new BadRequestException(e.getMessage());
        }

        return new InternalRequestSignature(
            requestBody,
            mac,
            decodedSignature
        );
    }
@Test
    public void fromHeadersShouldThrowExceptionOnInvalidBase64Signature() {
        assertThrows(BadRequestException.class, () -> InternalRequestSignature.fromHeaders(crypto, REQUEST_BODY,
            internalRequestHeaders("not valid base 64", SIGNATURE_ALGORITHM)));
    }