# Path: pynubank/exception.py
# class NuRequestException(NuException):
#     def __init__(self, response: Response):
#         super().__init__(f'The request made failed with HTTP status code {response.status_code}')
#         self.url = response.url
#         self.status_code = response.status_code
#         self.response = response
# 
# class NuException(Exception):
# 
#     def __init__(self, message):
#         super().__init__(message)
# 
# Path: pynubank/utils/discovery.py
# class Discovery:
#     def __init__(self, client: HttpClient):
#         self.client = client
#         self.proxy_list_url = {}
#         self.proxy_list_app_url = {}
# 
#         self._update_proxy_urls()
# 
#     def get_url(self, name: str) -> str:
#         return self._get_url(name, self.proxy_list_url)
# 
#     def get_app_url(self, name: str) -> str:
#         return self._get_url(name, self.proxy_list_app_url)
# 
#     def _update_proxy_urls(self):
#         self.proxy_list_url = self.client.get(DISCOVERY_URL)
#         self.proxy_list_app_url = self.client.get(DISCOVERY_APP_URL)
# 
#     def _get_url(self, name: str, target: dict) -> str:
#         url = target.get(name)
#         if not url:
#             raise NuException(f'There is no URL discovered for {name}')
# 
#         return url
# 
# Path: pynubank/utils/http.py
# class HttpClient:
# 
#     def __init__(self):
#         self._cert = None
#         self._headers = {
#             'Content-Type': 'application/json',
#             'X-Correlation-Id': 'WEB-APP.pewW9',
#             'User-Agent': 'pynubank Client - https://github.com/andreroggeri/pynubank',
#         }
# 
#     def set_cert(self, cert_path: str):
#         self._cert = cert_path
# 
#     def set_header(self, name: str, value: str):
#         self._headers[name] = value
# 
#     def remove_header(self, name: str):
#         self._headers.pop(name)
# 
#     def get_header(self, name: str):
#         return self._headers.get(name)
# 
#     @property
#     def _cert_args(self):
#         return {'pkcs12_filename': self._cert, 'pkcs12_password': ''} if self._cert else {}
# 
#     def _handle_response(self, response: Response) -> dict:
#         if response.status_code != 200:
#             raise NuRequestException(response)
# 
#         return response.json()
# 
#     def raw_get(self, url: str) -> Response:
#         return get(url, headers=self._headers, **self._cert_args)
# 
#     def get(self, url: str) -> dict:
#         return self._handle_response(self.raw_get(url))
# 
#     def post(self, url: str, json: dict) -> dict:
#         return self._handle_response(post(url, json=json, headers=self._headers, **self._cert_args))


import OpenSSL
import requests
from OpenSSL.crypto import X509
from pynubank import NuException, NuRequestException
from pynubank.utils.discovery import Discovery
from pynubank.utils.http import HttpClient



class CertificateGenerator:

    def __init__(self, login, password, device_id, encrypted_code=None):
        self.login = login
        self.password = password
        self.device_id = device_id
        self.encrypted_code = encrypted_code
        self.key1 = self._generate_key()
        self.key2 = self._generate_key()

# Path: pynubank/exception.py
# class NuRequestException(NuException):
#     def __init__(self, response: Response):
#         super().__init__(f'The request made failed with HTTP status code {response.status_code}')
#         self.url = response.url
#         self.status_code = response.status_code
#         self.response = response
# 
# class NuException(Exception):
# 
#     def __init__(self, message):
#         super().__init__(message)
# 
# Path: pynubank/utils/discovery.py
# class Discovery:
#     def __init__(self, client: HttpClient):
#         self.client = client
#         self.proxy_list_url = {}
#         self.proxy_list_app_url = {}
# 
#         self._update_proxy_urls()
# 
#     def get_url(self, name: str) -> str:
#         return self._get_url(name, self.proxy_list_url)
# 
#     def get_app_url(self, name: str) -> str:
#         return self._get_url(name, self.proxy_list_app_url)
# 
#     def _update_proxy_urls(self):
#         self.proxy_list_url = self.client.get(DISCOVERY_URL)
#         self.proxy_list_app_url = self.client.get(DISCOVERY_APP_URL)
# 
#     def _get_url(self, name: str, target: dict) -> str:
#         url = target.get(name)
#         if not url:
#             raise NuException(f'There is no URL discovered for {name}')
# 
#         return url
# 
# Path: pynubank/utils/http.py
# class HttpClient:
# 
#     def __init__(self):
#         self._cert = None
#         self._headers = {
#             'Content-Type': 'application/json',
#             'X-Correlation-Id': 'WEB-APP.pewW9',
#             'User-Agent': 'pynubank Client - https://github.com/andreroggeri/pynubank',
#         }
# 
#     def set_cert(self, cert_path: str):
#         self._cert = cert_path
# 
#     def set_header(self, name: str, value: str):
#         self._headers[name] = value
# 
#     def remove_header(self, name: str):
#         self._headers.pop(name)
# 
#     def get_header(self, name: str):
#         return self._headers.get(name)
# 
#     @property
#     def _cert_args(self):
#         return {'pkcs12_filename': self._cert, 'pkcs12_password': ''} if self._cert else {}
# 
#     def _handle_response(self, response: Response) -> dict:
#         if response.status_code != 200:
#             raise NuRequestException(response)
# 
#         return response.json()
# 
#     def raw_get(self, url: str) -> Response:
#         return get(url, headers=self._headers, **self._cert_args)
# 
#     def get(self, url: str) -> dict:
#         return self._handle_response(self.raw_get(url))
# 
#     def post(self, url: str, json: dict) -> dict:
#         return self._handle_response(post(url, json=json, headers=self._headers, **self._cert_args))


# Path: pynubank/utils/certificate_generator.py
import OpenSSL
import requests
from OpenSSL.crypto import X509
from pynubank import NuException, NuRequestException
from pynubank.utils.discovery import Discovery
from pynubank.utils.http import HttpClient




class CertificateGenerator:

    def __init__(self, login, password, device_id, encrypted_code=None):
        self.login = login
        self.password = password
        self.device_id = device_id
        self.encrypted_code = encrypted_code
        self.key1 = self._generate_key()
        self.key2 = self._generate_key()

        discovery = Discovery(HttpClient())