From 5767c6b37d68e645bce5666ec803570e12e22560 Mon Sep 17 00:00:00 2001 From: Rob Crittenden Date: Thu, 23 Jul 2009 16:58:21 -0400 Subject: Fix deprecation warning for the sha library on Python 2.6 sha has been replaced by hashlib. We need to support Python 2.4 - 2.6 so this will use hashlib if available but fall back onto sha if not. Fortunately they use the same API for the function we need. 509042 Signed-off-by: Jason Gerard DeRose --- ipaserver/install/certs.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ipaserver/install/certs.py') diff --git a/ipaserver/install/certs.py b/ipaserver/install/certs.py index c1b7a8089..ad851489b 100644 --- a/ipaserver/install/certs.py +++ b/ipaserver/install/certs.py @@ -18,7 +18,6 @@ # import os, stat, subprocess, re -import sha import errno import tempfile import shutil @@ -34,6 +33,13 @@ from ipapython import ipautil from nss.error import NSPRError import nss.nss as nss +# The sha module is deprecated in Python 2.6, replaced by hashlib. Try +# that first and fall back to sha.sha if it isn't available. +try: + from hashlib import sha256 as sha +except ImportError: + from sha import sha + CA_SERIALNO="/var/lib/ipa/ca_serialno" def ipa_self_signed(): @@ -194,7 +200,7 @@ class CertDB(object): os.chmod(fname, perms) def gen_password(self): - return sha.sha(ipautil.ipa_generate_password()).hexdigest() + return sha(ipautil.ipa_generate_password()).hexdigest() def run_certutil(self, args, stdin=None): new_args = ["/usr/bin/certutil", "-d", self.secdir] -- cgit