From 5bdd42c1534a196d6be9104543e4a9a9b0442324 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Thu, 22 Apr 2010 17:07:13 -0400 Subject: [PATCH] make the sha import use hashlib and make the hashlib import work sanely on versions of python that don't have a hashlib (python < 2.5) --- certmaster/certmaster.py | 18 +++++++++++++++--- scripts/certmaster-sync | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/certmaster/certmaster.py b/certmaster/certmaster.py index 9548b8b..b0a216b 100644 --- a/certmaster/certmaster.py +++ b/certmaster/certmaster.py @@ -22,7 +22,19 @@ import traceback import os import os.path from OpenSSL import crypto -import sha + +try: + import hashlib +except ImportError: + # Python-2.4.z ... gah! (or even 2.3!) + import sha + class hashlib: + @staticmethod + def new(algo): + if algo == 'sha1': + return sha.new() + raise ValueError, "Bad checksum type" + import glob import socket import exceptions @@ -123,10 +135,10 @@ class CertMaster(object): if os.path.exists(csrfile): oldfo = open(csrfile) oldcsrbuf = oldfo.read() - oldsha = sha.new() + oldsha = hashlib.new('sha1') oldsha.update(oldcsrbuf) olddig = oldsha.hexdigest() - newsha = sha.new() + newsha = hashlib.new('sha1') newsha.update(csrbuf) newdig = newsha.hexdigest() if not newdig == olddig: diff --git a/scripts/certmaster-sync b/scripts/certmaster-sync index bd27af5..fd1db93 100644 --- a/scripts/certmaster-sync +++ b/scripts/certmaster-sync @@ -7,7 +7,19 @@ import os import sys -import sha +try: + import hashlib +except ImportError: + # Python-2.4.z ... gah! (or even 2.3!) + import sha + class hashlib: + @staticmethod + def new(algo): + if algo == 'sha1': + return sha.new() + raise ValueError, "Bad checksum type" + + import xmlrpclib from glob import glob from time import sleep @@ -72,7 +84,7 @@ def local_certs(): return results def checksum(f): - thissum = sha.new() + thissum = hashlib.new('sha1') if os.path.exists(f): fo = open(f, 'r') data = fo.read() -- 2.39.2