[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Correctly identify ASCII-armored messages, even when th...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv31621/lib/mixminion

Modified Files:
	Common.py test.py 
Log Message:
Correctly identify ASCII-armored messages, even when they have been \r\n-mangled (bug found by George)

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- Common.py	2 Mar 2004 07:06:14 -0000	1.132
+++ Common.py	6 Mar 2004 00:33:09 -0000	1.133
@@ -258,10 +258,10 @@
     return "".join(result)
 
 # Matches a begin line.
-BEGIN_LINE_RE = re.compile(r'^-----BEGIN ([^-]+)-----[ \t]*$',re.M)
+BEGIN_LINE_RE = re.compile(r'^-----BEGIN ([^-]+)-----[ \t]*\r?$',re.M)
 
 # Matches a header line.
-ARMOR_KV_RE = re.compile(r'([^:\s]+): ([^\n]+)')
+ARMOR_KV_RE = re.compile(r'([^:\s]+): ([^\r\n]+)')
 def unarmorText(s, findTypes, base64=1, base64fn=None):
     """Parse a list of OpenPGP-style ASCII-armored messages from 's',
        and return a list of (type, headers, body) tuples, where 'headers'
@@ -285,7 +285,7 @@
             return result
 
         tp = mBegin.group(1)
-        endPat = r"^-----END %s-----[ \t]*$" % tp
+        endPat = r"^-----END %s-----[ \t]*\r?$" % tp
 
         endRE = re.compile(endPat, re.M)
         mEnd = endRE.search(s, mBegin.start())
@@ -317,7 +317,7 @@
 
         if base64:
             try:
-                if stringContains(s[idx:endIdx], "\n[...]\n"):
+                if stringContains(s[idx:endIdx], "\n[...]"):
                     raise UIError("Corrupted data: value seems to be truncated by a Mixminion/Mixmaster gateway")
                 value = binascii.a2b_base64(s[idx:endIdx])
             except (TypeError, binascii.Incomplete, binascii.Error), e:

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- test.py	6 Mar 2004 00:04:38 -0000	1.189
+++ test.py	6 Mar 2004 00:33:09 -0000	1.190
@@ -695,6 +695,12 @@
         enc = "\n".join(enc)
         self.assertRaises(UIError, unarmorText, enc, ["MUNGED"], 1)
 
+        # Test armor and \r\n
+        enc = armorText(inp2*50, "MUNGED", [], base64=1)
+        enc = enc.replace("\n","\r\n")
+        tp, h, b = unarmorText(enc, ["MUNGED"], 1)[0]
+        self.assertEquals(b, inp2*50)
+
         # Test base64fn and concatenation.
         enc1 = armorText(inp2, "THIS THAT", [("H-64", "0")], 0)
         enc2 = armorText(inp2, "THIS THAT", [("H-64", "1")], 1)
@@ -7510,7 +7516,7 @@
     tc = loader.loadTestsFromTestCase
 
     if 0:
-        suite.addTest(tc(ClientDirectoryTests))
+        suite.addTest(tc(MiscTests))
         return suite
     testClasses = [MiscTests,
                    MinionlibCryptoTests,