# Path: esteid/types.py
# class ResponderCertificate(Certificate):
#     pass
# 
# class SignedDocInfo(FromDictMixin):
#     format = attr.ib(default="BDOC")
#     version = attr.ib(default="2.1")
#     mime_type = attr.ib(default=pyasice.Container.MIME_TYPE)
# 
#     data_file_info: List[DataFileInfo] = attr.ib(
#         default=attr.Factory(list),
#         validator=[
#             attr.validators.instance_of(list),
#             get_typed_list_validator(DataFileInfo),
#         ],
#         converter=get_typed_list_converter(DataFileInfo),
#     )
# 
#     signature_info: List[SignatureInfo] = attr.ib(
#         default=attr.Factory(list),
#         validator=[
#             attr.validators.instance_of(list),
#             get_typed_list_validator(SignatureInfo),
#         ],
#         converter=get_typed_list_converter(SignatureInfo),
#     )
# 
# class Signer(FromDictMixin):
#     id_code = attr.ib()
# 
#     # Note: This should also support common_name argument coming in
#     full_name = attr.ib()
# 
#     certificate: Certificate = attr.ib(
#         validator=attr.validators.instance_of(Certificate), converter=get_instance_converter(Certificate)
#     )
# 
#     @staticmethod
#     def prepare_kwargs(kwargs):
#         kwargs = camel_2_py(kwargs)
#         full_name = kwargs.get("full_name", None)
# 
#         # If the full_name is None, check common_name field and use that
#         if full_name is None:
#             full_name = get_name_from_legacy_common_name(kwargs.pop("common_name", None))
# 
#         kwargs["full_name"] = full_name
# 
#         return kwargs
# 
#     @classmethod
#     def from_certificate(cls, cert: "Union[bytes, Asn1CryptoCertificate, OsCryptoCertificate]"):
#         """
#         Get personal info from an oscrypto/asn1crypto Certificate object
# 
#         For a closer look at where the attributes come from:
#         asn1crypto.x509.NameType
#         """
#         cert_holder_info = CertificateHolderInfo.from_certificate(cert)
#         return cls(
#             certificate=Certificate.from_certificate(cert_holder_info.asn1_certificate),
#             full_name=f"{cert_holder_info.given_name} {cert_holder_info.surname}",
#             id_code=cert_holder_info.id_code,
#         )


import base64
import hashlib
import attr
from pyasice import Container, XmlSignature
from esteid.types import ResponderCertificate, SignedDocInfo, Signer
"""
Compatibility utilities that provide signed container info
in the same format as the DDS service did.
"""





def signature_info(xml_signature: XmlSignature):
    subject_cert = xml_signature.get_certificate()
    ocsp_cert = xml_signature.get_ocsp_response().get_responder_certs()[0]
    signing_time = xml_signature.get_signing_time()

    return {
        "id": xml_signature._get_node("ds:Signature").attrib["Id"],
        "signing_time": signing_time,
        "status": True,
        "signature_production_place": None,

# Path: esteid/types.py
# class ResponderCertificate(Certificate):
#     pass
# 
# class SignedDocInfo(FromDictMixin):
#     format = attr.ib(default="BDOC")
#     version = attr.ib(default="2.1")
#     mime_type = attr.ib(default=pyasice.Container.MIME_TYPE)
# 
#     data_file_info: List[DataFileInfo] = attr.ib(
#         default=attr.Factory(list),
#         validator=[
#             attr.validators.instance_of(list),
#             get_typed_list_validator(DataFileInfo),
#         ],
#         converter=get_typed_list_converter(DataFileInfo),
#     )
# 
#     signature_info: List[SignatureInfo] = attr.ib(
#         default=attr.Factory(list),
#         validator=[
#             attr.validators.instance_of(list),
#             get_typed_list_validator(SignatureInfo),
#         ],
#         converter=get_typed_list_converter(SignatureInfo),
#     )
# 
# class Signer(FromDictMixin):
#     id_code = attr.ib()
# 
#     # Note: This should also support common_name argument coming in
#     full_name = attr.ib()
# 
#     certificate: Certificate = attr.ib(
#         validator=attr.validators.instance_of(Certificate), converter=get_instance_converter(Certificate)
#     )
# 
#     @staticmethod
#     def prepare_kwargs(kwargs):
#         kwargs = camel_2_py(kwargs)
#         full_name = kwargs.get("full_name", None)
# 
#         # If the full_name is None, check common_name field and use that
#         if full_name is None:
#             full_name = get_name_from_legacy_common_name(kwargs.pop("common_name", None))
# 
#         kwargs["full_name"] = full_name
# 
#         return kwargs
# 
#     @classmethod
#     def from_certificate(cls, cert: "Union[bytes, Asn1CryptoCertificate, OsCryptoCertificate]"):
#         """
#         Get personal info from an oscrypto/asn1crypto Certificate object
# 
#         For a closer look at where the attributes come from:
#         asn1crypto.x509.NameType
#         """
#         cert_holder_info = CertificateHolderInfo.from_certificate(cert)
#         return cls(
#             certificate=Certificate.from_certificate(cert_holder_info.asn1_certificate),
#             full_name=f"{cert_holder_info.given_name} {cert_holder_info.surname}",
#             id_code=cert_holder_info.id_code,
#         )


# Path: esteid/compat.py
import base64
import hashlib
import attr
from pyasice import Container, XmlSignature
from esteid.types import ResponderCertificate, SignedDocInfo, Signer

"""
Compatibility utilities that provide signed container info
in the same format as the DDS service did.
"""





def signature_info(xml_signature: XmlSignature):
    subject_cert = xml_signature.get_certificate()
    ocsp_cert = xml_signature.get_ocsp_response().get_responder_certs()[0]
    signing_time = xml_signature.get_signing_time()

    return {
        "id": xml_signature._get_node("ds:Signature").attrib["Id"],
        "signing_time": signing_time,
        "status": True,
        "signature_production_place": None,

        "signer": attr.asdict(Signer.from_certificate(subject_cert)),