'Ensure the resource is in its desired state.'

def check(self, module, perms_required=True):

    state_and_perms = super(CertificateSigningRequest, self).check(module, perms_required)
    self.privatekey = crypto_utils.load_privatekey(self.privatekey_path, self.privatekey_passphrase)
    def _check_subject(csr):
        subject = csr.get_subject()
        for (key, value) in self.subject.items():
            if (getattr(subject, key, None) != value):
                return False
        return True
    def _check_subjectAltName(extensions):
        altnames_ext = next((ext.__str__() for ext in extensions if (ext.get_short_name() == 'subjectAltName')), '')
        altnames = [altname.strip() for altname in altnames_ext.split(',')]
        altnames = [(name if (not name.startswith('IP    Address:')) else ('IP:' + name.split(':', 1)[1])) for name in altnames]
        if self.subjectAltName:
            if (set(altnames) != set(self.subjectAltName)):
                return False
        elif altnames:
            return False
        return True
    def _check_keyUsage_(extensions, extName, expected, long):
        usages_ext = [str(ext) for ext in extensions if (ext.get_short_name() == extName)]
        if (((not usages_ext) and expected) or (usages_ext and (not expected))):
            return False
        elif ((not usages_ext) and (not expected)):
            return True
        else:
            current = [usage.strip() for usage in usages_ext[0].split(',')]
            expected = [(long[usage] if (usage in long) else usage) for usage in expected]
            return (current == expected)
    def _check_keyUsage(extensions):
        return _check_keyUsage_(extensions, 'keyUsage', self.keyUsage, crypto_utils.keyUsageLong)
    def _check_extenededKeyUsage(extensions):
        return _check_keyUsage_(extensions, 'extendedKeyUsage', self.extendedKeyUsage, crypto_utils.extendedKeyUsageLong)
    def _check_extensions(csr):
        extensions = csr.get_extensions()
        return (_check_subjectAltName(extensions) and _check_keyUsage(extensions) and _check_extenededKeyUsage(extensions))
    def _check_signature(csr):
        try:
            return csr.verify(self.privatekey)
        except crypto.Error:
            return False
    if (not state_and_perms):
        return False
    csr = crypto_utils.load_certificate_request(self.path)
    return (_check_subject(csr) and _check_extensions(csr) and _check_signature(csr))
