# Path: django_x509/base/models.py
# class AbstractCa(BaseX509):
#     """
#     Abstract Ca model
#     """
# 
#     class Meta:
#         abstract = True
#         verbose_name = _('CA')
#         verbose_name_plural = _('CAs')
# 
#     def get_revoked_certs(self):
#         """
#         Returns revoked certificates of this CA
#         (does not include expired certificates)
#         """
#         now = timezone.now()
#         return self.cert_set.filter(
#             revoked=True, validity_start__lte=now, validity_end__gte=now
#         )
# 
#     def renew(self):
#         """
#         Renew the certificate, private key and
#         validity end date of a CA
#         """
#         super().renew()
#         for cert in self.cert_set.all():
#             cert.renew()
# 
#     @property
#     def crl(self):
#         """
#         Returns up to date CRL of this CA
#         """
#         revoked_certs = self.get_revoked_certs()
#         crl = crypto.CRL()
#         now_str = datetime_to_string(timezone.now())
#         for cert in revoked_certs:
#             revoked = crypto.Revoked()
#             revoked.set_serial(bytes(str(cert.serial_number), 'utf8'))
#             revoked.set_reason(b'unspecified')
#             revoked.set_rev_date(bytes(str(now_str), 'utf8'))
#             crl.add_revoked(revoked)
#         return crl.export(self.x509, self.pkey, days=1, digest=b'sha256')
# 
# class AbstractCert(BaseX509):
#     """
#     Abstract Cert model
#     """
# 
#     ca = models.ForeignKey(
#         swapper.get_model_name('django_x509', 'Ca'),
#         on_delete=models.CASCADE,
#         verbose_name=_('CA'),
#     )
#     revoked = models.BooleanField(_('revoked'), default=False)
#     revoked_at = models.DateTimeField(
#         _('revoked at'), blank=True, null=True, default=None
#     )
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         abstract = True
#         verbose_name = _('certificate')
#         verbose_name_plural = _('certificates')
#         unique_together = ('ca', 'serial_number')
# 
#     def revoke(self):
#         """
#         * flag certificate as revoked
#         * fill in revoked_at DateTimeField
#         """
#         now = timezone.now()
#         self.revoked = True
#         self.revoked_at = now
#         self.save()


import swapper
from .base.models import AbstractCa, AbstractCert



class Ca(AbstractCa):
    """
    Concrete Ca model
    """

    class Meta(AbstractCa.Meta):
        abstract = False
        swappable = swapper.swappable_setting('django_x509', 'Ca')


class Cert(AbstractCert):
    """
    Concrete Cert model
    """


# Path: django_x509/base/models.py
# class AbstractCa(BaseX509):
#     """
#     Abstract Ca model
#     """
# 
#     class Meta:
#         abstract = True
#         verbose_name = _('CA')
#         verbose_name_plural = _('CAs')
# 
#     def get_revoked_certs(self):
#         """
#         Returns revoked certificates of this CA
#         (does not include expired certificates)
#         """
#         now = timezone.now()
#         return self.cert_set.filter(
#             revoked=True, validity_start__lte=now, validity_end__gte=now
#         )
# 
#     def renew(self):
#         """
#         Renew the certificate, private key and
#         validity end date of a CA
#         """
#         super().renew()
#         for cert in self.cert_set.all():
#             cert.renew()
# 
#     @property
#     def crl(self):
#         """
#         Returns up to date CRL of this CA
#         """
#         revoked_certs = self.get_revoked_certs()
#         crl = crypto.CRL()
#         now_str = datetime_to_string(timezone.now())
#         for cert in revoked_certs:
#             revoked = crypto.Revoked()
#             revoked.set_serial(bytes(str(cert.serial_number), 'utf8'))
#             revoked.set_reason(b'unspecified')
#             revoked.set_rev_date(bytes(str(now_str), 'utf8'))
#             crl.add_revoked(revoked)
#         return crl.export(self.x509, self.pkey, days=1, digest=b'sha256')
# 
# class AbstractCert(BaseX509):
#     """
#     Abstract Cert model
#     """
# 
#     ca = models.ForeignKey(
#         swapper.get_model_name('django_x509', 'Ca'),
#         on_delete=models.CASCADE,
#         verbose_name=_('CA'),
#     )
#     revoked = models.BooleanField(_('revoked'), default=False)
#     revoked_at = models.DateTimeField(
#         _('revoked at'), blank=True, null=True, default=None
#     )
# 
#     def __str__(self):
#         return self.name
# 
#     class Meta:
#         abstract = True
#         verbose_name = _('certificate')
#         verbose_name_plural = _('certificates')
#         unique_together = ('ca', 'serial_number')
# 
#     def revoke(self):
#         """
#         * flag certificate as revoked
#         * fill in revoked_at DateTimeField
#         """
#         now = timezone.now()
#         self.revoked = True
#         self.revoked_at = now
#         self.save()


# Path: django_x509/models.py
import swapper
from .base.models import AbstractCa, AbstractCert




class Ca(AbstractCa):
    """
    Concrete Ca model
    """

    class Meta(AbstractCa.Meta):
        abstract = False
        swappable = swapper.swappable_setting('django_x509', 'Ca')


class Cert(AbstractCert):
    """
    Concrete Cert model
    """


    class Meta(AbstractCert.Meta):