benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf a95e2348-4771-53f9-8185-2b9777d24ad7

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import rsa
import urllib.request
from hashlib import sha256

def task_func(url):
    """
    Generates RSA public and private keys, retrieves the content from the specified URL, calculates
    its SHA256 hash, and signs the hash with the private key. Returns the public key and the signed hash
    as a hexadecimal string.

    Parameters:
    url (str): The URL whose content is to be fetched and signed.

    Returns:
    rsa.PublicKey: The RSA public key.
    str: The hexadecimal string of the signed SHA256 hash of the URL content.
    bytes: The hashed URL content, for verification purpose

    Raises:
    ValueError: If there's an issue reaching the server (e.g., network error, invalid URL)
                or if the server returns an HTTP error.
    rsa.pkcs1.VerificationError: If there's a failure in signing the hash with the RSA private key.
    urllib.error.URLError: If the server is not reachable

    Requirements:
    - rsa
    - urllib.request
    - hashlib.sha256

    Examples:
    >>> pub_key, signed_hash, hash_value = task_func('https://www.example.com')
    >>> isinstance(pub_key, rsa.PublicKey)
    True
    >>> isinstance(signed_hash, str)
    True
    >>> isinstance(hash_value, bytes)
    True
    """

instruct prompt

Generates RSA public and private keys, retrieves the content from the specified URL, calculates its SHA256 hash, and signs the hash with the private key. Returns the public key and the signed hash as a hexadecimal string.
The function should raise the exception for: ValueError: If there's an issue reaching the server (e.g., network error, invalid URL) or if the server returns an HTTP error. rsa.pkcs1.VerificationError: If there's a failure in signing the hash with the RSA private key. urllib.error.URLError: If the server is not reachable
The function should output with:
    rsa.PublicKey: The RSA public key.
    str: The hexadecimal string of the signed SHA256 hash of the URL content.
    bytes: The hashed URL content, for verification purpose
You should write self-contained code starting with:

Code

import rsa
import urllib.request
from hashlib import sha256
def task_func(url):

code prompt

Code

import rsa
import urllib.request
from hashlib import sha256
def task_func(url):

entry point

task_func

libs

  • urllib
  • rsa
  • hashlib

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import