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

[minion-cvs] Function to parse directory of either type.



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria:/tmp/cvs-serv27298

Modified Files:
	ServerInfo.py 
Log Message:
Function to parse directory of either type.

Index: ServerInfo.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerInfo.py,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -d -r1.92 -r1.93
--- ServerInfo.py	3 May 2005 06:10:37 -0000	1.92
+++ ServerInfo.py	4 Jun 2005 13:53:25 -0000	1.93
@@ -9,7 +9,7 @@
    """
 
 __all__ = [ 'ServerInfo', 'ServerDirectory', 'displayServerByRouting',
-            'getNicknameByKeyID' ]
+            'getNicknameByKeyID', 'SignedDirectory', 'parseDirectory' ]
 
 import re
 import time
@@ -344,11 +344,15 @@
         return self['Server']['Identity']
 
     def getIdentityDigest(self):
-        """DOCDOC"""
+        """Return the digest of this server's public identity key.
+           (SHA-1 digest of ASN.1-encodd key).
+        """
         return sha1(pk_encode_public_key(self.getIdentity()))
 
     def getIdentityFingerprint(self):
-        """DOCDOC"""
+        """Return the digest of this server's public identity key, encoded in
+           hexadecimal, with every 4 characters separated by spaces.
+        """
         d = getIdentityDigest(self)
         assert (len(d) % 2) == 0
         b = binascii.b2a_hex(d)
@@ -613,10 +617,9 @@
         sigs, info, servers = _splitMultisignedDirectory(contents)
         del contents
 
-        self.signatures = [ ]
-
         # Check signature digests.
         badsigs = 0
+        self.signatures = [ ]
         for idx in range(len(sigs)):
             sig = _DirectorySignature(sigs[idx])
             if sig.getDigest() != digest:
@@ -628,7 +631,6 @@
 
         # Parse the DirectoryInfo
         self.dirInfo = _DirectoryInfo(info)
-
         # Parse the Server descriptors.
         self.servers = [ ]
         for s in servers:
@@ -686,6 +688,15 @@
     def get(self, item, default=None):
         return self.header.get(item, default)
 
+def parseDirectory(fname, validatedDigests=None):
+    """DOCDOC"""
+    s = readPossiblyGzippedFile(fname)
+    if s.startswith("[Directory]\n"):
+        tp = ServerDirectory
+    else:
+        tp = SignedDirectory
+    return tp(fname=fname, string=s, validatedDigests=validatedDigests)
+
 class _DirectoryHeader(mixminion.Config._ConfigFile):
     """Internal object: used to parse, validate, and store fields in a
        directory's header sections.
@@ -951,7 +962,12 @@
     return digest
 
 def _splitMultisignedDirectory(directory):
-    """DOCDOC -- returns [signature...],info,[server...]"""
+    """Given a multiply-signed directory in a string 'directory', return
+       a 3-tuple containing:
+          - a list of signature sections.
+          - the directory header
+          - a list of serverinfo sections.
+    """
     sigs = []
 
     # Extract all signatures.