diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rpki/resource_set.py | 27 | ||||
-rw-r--r-- | scripts/rpki/up_down.py | 4 | ||||
-rw-r--r-- | scripts/rpki/x509.py | 3 | ||||
-rw-r--r-- | scripts/test-pow.py | 3 |
4 files changed, 24 insertions, 13 deletions
diff --git a/scripts/rpki/resource_set.py b/scripts/rpki/resource_set.py index b805fb97..45fa096e 100644 --- a/scripts/rpki/resource_set.py +++ b/scripts/rpki/resource_set.py @@ -56,28 +56,31 @@ class resource_range_ip(resource_range): represented as prefixes are written as prefixes on output. """ - def __str__(self): + def _prefixlen(self): mask = self.min ^ self.max - prefixlen = self.min.bits + prefixlen = self.addr_type.bits while mask & 1: prefixlen -= 1 mask >>= 1 if mask: + return -1 + else: + return prefixlen + + def __str__(self): + prefixlen = self._prefixlen() + if prefixlen < 0: return str(self.min) + "-" + str(self.max) else: return str(self.min) + "/" + str(prefixlen) def to_tuple(self): - mask = self.min ^ self.max - if (mask & (~mask + 1)) <= 1: - n = self.bits - while mask: - n -= 1 - mask >>= 1 - return ("addressPrefix", _long2bs(self.min, self.bits, prefixlen = n)) + prefixlen = self._prefixlen() + if prefixlen < 0: + return ("addressRange", (_long2bs(self.min, self.addr_type.bits, strip = 0), + _long2bs(self.max, self.addr_type.bits, strip = 1))) else: - return ("addressRange", (_long2bs(self.min, self.bits, strip = 0), - _long2bs(self.max, self.bits, strip = 1))) + return ("addressPrefix", _long2bs(self.min, self.addr_type.bits, prefixlen = prefixlen)) class resource_range_ipv4(resource_range_ip): """Range of IPv4 addresses.""" @@ -313,7 +316,7 @@ def _long2bs(number, addrlen, prefixlen = None, strip = None): assert prefixlen is None or strip is None bs = [] while number: - bs.append(number & 1) + bs.append(int(number & 1)) number >>= 1 if addrlen > len(bs): bs.extend((0 for i in xrange(addrlen - len(bs)))) diff --git a/scripts/rpki/up_down.py b/scripts/rpki/up_down.py index ac3e5fd2..95ce745e 100644 --- a/scripts/rpki/up_down.py +++ b/scripts/rpki/up_down.py @@ -254,6 +254,10 @@ class issue_pdu(base_elt): # # This will need to become a separate function eventually, but # inline it for now until it's a bit better fleshed out. + # Might make sense as a .certify() method for the issuer. + # + # Hmm, the following is a bit confused between the POW and + # POW.pkix APIs. raise NotImplementedError cn_hash = POW.Digest(POW.SHA1_DIGEST) diff --git a/scripts/rpki/x509.py b/scripts/rpki/x509.py index 9e834607..8306b243 100644 --- a/scripts/rpki/x509.py +++ b/scripts/rpki/x509.py @@ -12,7 +12,8 @@ bring together the functionality I need in a way that hides at least some of the nasty details. This involves a lot of format conversion. """ -import POW, tlslite.api, POW.pkix, base64, rpki.exceptions, rpki.resource_set +import POW, tlslite.api, POW.pkix, base64, time +import rpki.exceptions, rpki.resource_set class PEM_converter(object): """Convert between DER and PEM encodings for various kinds of ASN.1 data.""" diff --git a/scripts/test-pow.py b/scripts/test-pow.py index 8de46029..cad5b729 100644 --- a/scripts/test-pow.py +++ b/scripts/test-pow.py @@ -82,3 +82,6 @@ for der in (alice, apnic): if as: print ",".join(map(lambda x: "AS:" + str(x), as)) if v4: print ",".join(map(lambda x: "IPv4:" + str(x), v4)) if v6: print ",".join(map(lambda x: "IPv6:" + str(x), v6)) + if as is not None: print as.to_tuple() + if v4 is not None: print v4.to_tuple() + if v6 is not None: print v6.to_tuple() |