Example #1
0
    def _decode_hook(self):
        if self.asn1 is None:
            self._distribution_points = None
            return

        self._distribution_points = []
        for asn1_point in self.asn1:
            point_name_rdn_malformed = False
            if asn1_point["distributionPoint"].hasValue():
                point_name_asn1 = asn1_point["distributionPoint"].getComponent(
                )
                if asn1_point["distributionPoint"]["fullName"].hasValue():
                    # GeneralNames
                    point_name = ASN1GeneralNamesWrapper.from_asn1(
                        point_name_asn1)
                else:
                    # RelativeDistinguishedName
                    try:
                        point_name = RelativeDistinguishedName.from_asn1(
                            point_name_asn1)
                    except InvalidInputException:
                        point_name = None
                        point_name_rdn_malformed = True
            else:
                point_name = None

            if asn1_point["reasons"].hasValue():
                reasons = set()
                for (bitno, value) in enumerate(asn1_point["reasons"]):
                    if value == 1:
                        value = self._KNOWN_REASON_BITS.get(bitno, bitno)
                        reasons.add(value)
                reasons_trailing_zero = ASN1Tools.bitstring_has_trailing_zeros(
                    asn1_point["reasons"])
            else:
                reasons = None
                reasons_trailing_zero = False

            if asn1_point["cRLIssuer"].hasValue():
                crl_issuer = ASN1GeneralNamesWrapper.from_asn1(
                    asn1_point["cRLIssuer"])
            else:
                crl_issuer = None

            cdp = self._DistributionPoint(
                point_name=point_name,
                point_name_rdn_malformed=point_name_rdn_malformed,
                reasons=reasons,
                reasons_trailing_zero=reasons_trailing_zero,
                crl_issuer=crl_issuer)
            self._distribution_points.append(cdp)
Example #2
0
    def test_bitstring_trailing_zero(self):
        self.assertTrue(
            ASN1Tools.bitstring_has_trailing_zeros(BitString([0, 1, 0])))
        self.assertTrue(ASN1Tools.bitstring_has_trailing_zeros(BitString([0])))
        self.assertTrue(
            ASN1Tools.bitstring_has_trailing_zeros(
                BitString([1, 1, 1, 1, 1, 1, 1, 0])))
        self.assertTrue(
            ASN1Tools.bitstring_has_trailing_zeros(
                BitString([1, 1, 1, 1, 1, 1, 1, 1, 0])))

        self.assertFalse(
            ASN1Tools.bitstring_has_trailing_zeros(BitString([0, 1])))
        self.assertFalse(ASN1Tools.bitstring_has_trailing_zeros(BitString([])))
        self.assertFalse(
            ASN1Tools.bitstring_has_trailing_zeros(BitString([0, 0, 0, 0, 1])))
        self.assertFalse(
            ASN1Tools.bitstring_has_trailing_zeros(
                BitString([0, 0, 0, 0, 0, 0, 1])))
        self.assertFalse(
            ASN1Tools.bitstring_has_trailing_zeros(
                BitString([0, 0, 0, 0, 0, 0, 0, 1])))
Example #3
0
 def has_trailing_zero(self):
     return ASN1Tools.bitstring_has_trailing_zeros(
         self.asn1) if (self.asn1 is not None) else None