aboutsummaryrefslogtreecommitdiff
path: root/rpkid/rpki
diff options
context:
space:
mode:
Diffstat (limited to 'rpkid/rpki')
-rw-r--r--rpkid/rpki/publication.py5
-rw-r--r--rpkid/rpki/rpki_engine.py4
-rw-r--r--rpkid/rpki/xml_utils.py8
3 files changed, 12 insertions, 5 deletions
diff --git a/rpkid/rpki/publication.py b/rpkid/rpki/publication.py
index dc033d31..64094cdd 100644
--- a/rpkid/rpki/publication.py
+++ b/rpkid/rpki/publication.py
@@ -315,10 +315,9 @@ class msg(rpki.xml_utils.msg, publication_namespace):
"""
Serve one msg PDU.
"""
- if self.type != "query":
+ if not self.is_query():
raise rpki.exceptions.BadQuery, "Message type is not query"
- r_msg = self.__class__()
- r_msg.type = "reply"
+ r_msg = self.__class__.reply()
def loop(iterator, q_pdu):
diff --git a/rpkid/rpki/rpki_engine.py b/rpkid/rpki/rpki_engine.py
index 08f090f3..04cc72f9 100644
--- a/rpkid/rpki/rpki_engine.py
+++ b/rpkid/rpki/rpki_engine.py
@@ -71,7 +71,7 @@ class rpkid_context(object):
def unwrap(der):
r_msg = rpki.left_right.cms_msg.unwrap(der, (self.bpki_ta, self.irdb_cert))
- if r_msg.type != "reply" or [r_pdu for r_pdu in r_msg if type(r_pdu) is not type(q_pdu)]:
+ if not r_msg.is_reply() or [r_pdu for r_pdu in r_msg if type(r_pdu) is not type(q_pdu)]:
errback(rpki.exceptions.BadIRDBReply(
"Unexpected response to IRDB query: %s" % lxml.etree.tostring(r_msg.toXML(), pretty_print = True, encoding = "us-ascii")))
else:
@@ -137,7 +137,7 @@ class rpkid_context(object):
try:
self.sql.ping()
q_msg = rpki.left_right.cms_msg.unwrap(query, (self.bpki_ta, self.irbe_cert))
- if q_msg.type != "query":
+ if not q_msg.is_query():
raise rpki.exceptions.BadQuery, "Message type is not query"
q_msg.serve_top_level(self, done)
except (rpki.async.ExitNow, SystemExit):
diff --git a/rpkid/rpki/xml_utils.py b/rpkid/rpki/xml_utils.py
index 9e4aa265..6bcd03c8 100644
--- a/rpkid/rpki/xml_utils.py
+++ b/rpkid/rpki/xml_utils.py
@@ -429,3 +429,11 @@ class msg(list):
self = cls(*args)
self.type = "reply"
return self
+
+ def is_query(self):
+ """Is this msg a query?"""
+ return self.type == "query"
+
+ def is_reply(self):
+ """Is this msg a reply?"""
+ return self.type == "reply"