# original signed block [needs to convert to \r\n]
Output = "-----BEGIN PGP SIGNED MESSAGE-----\r\n";
# Semi-evil hack to get the proper hash type inserted in the message
- if Msg.get_param('micalg') != None:
+ if Msg.get_param('micalg') is not None:
Output = Output + "Hash: SHA1,%s\r\n"%(Msg.get_param('micalg')[4:].upper())
Output = Output + "\r\n";
Output = Output + Signed.as_string().replace("\n-","\n- -") + "\n" + Signature.get_payload(decode=True)
InPipe[0] = -1;
# Send the message
- if Message != None:
+ if Message is not None:
try:
os.write(InPipe[1],Message);
except:
Output.close();
GPGText.close();
+
+
# This takes a text passage, a destination and a flag indicating the
# compatibility to use and returns an encrypted message to the recipient.
# It is best if the recipient is specified using the hex key fingerprint
# of the target, ie 0x64BE1319CCF6D393BF87FF9358A6D4EE
def GPGEncrypt(Message,To,PGP2):
- Error = "KeyringError"
+ class KeyringError(Exception): pass
# Encrypt using the PGP5 block encoding and with the PGP5 option set.
# This will handle either RSA or DSA/DH asymetric keys.
# In PGP2 compatible mode IDEA and rfc1991 encoding are used so that
# can read a message encrypted with blowfish and RSA.
searchkey = GPGKeySearch(To);
if len(searchkey) == 0:
- raise Error, "No key found matching %s"%(To);
+ raise KeyringError("No key found matching %s"%(To))
elif len(searchkey) > 1:
- raise Error, "Multiple keys found matching %s"%(To);
+ raise KeyringError("Multiple keys found matching %s"%(To))
if searchkey[0][4].find("E") < 0:
- raise Error, "Key %s has no encryption capability - are all encryption subkeys expired or revoked? Are there any encryption subkeys?"%(To);
+ raise KeyringError("Key %s has no encryption capability - are all encryption subkeys expired or revoked? Are there any encryption subkeys?"%(To))
if PGP2 == 0:
try:
Text = Res[2].read();
return Text;
finally:
- if Res != None:
+ if Res is not None:
Res[1].close();
Res[2].close();
else:
os.unlink(TmpName);
except:
pass;
- if Res != None:
+ if Res is not None:
Res[1].close();
Res[2].close();
# Good signature response
if Split[1] == "GOODSIG":
# Just in case GPG returned a bad signal before this (bug?)
- if Why == None:
+ if Why is None:
GoodSig = 1;
KeyID = Split[2];
Owner = ' '.join(Split[3:])
Text = Res[2].read();
# A gpg failure is an automatic bad signature
- if Exit[1] != 0 and Why == None:
+ if Exit[1] != 0 and Why is None:
GoodSig = 0;
Why = "GPG execution returned non-zero exit status: " + str(Exit[1]);
- if GoodSig == 0 and (Why == None or len(Why) == 0):
+ if GoodSig == 0 and (Why is None or len(Why) == 0):
Why = "Checking Failed";
# Try to decide if this message was sent using PGP2
PGP2Message = 0;
- if (re.search("-----[\n\r][\n\r]?Version: 2\\.",Message) != None):
+ if (re.search("-----[\n\r][\n\r]?Version: 2\\.",Message) is not None):
PGP2Message = 1;
return (Why,(SigId,Date,KeyFinger),(KeyID,KeyFinger,Owner,0,PGP2Message),Text);
finally:
- if Res != None:
+ if Res is not None:
Res[1].close();
Res[2].close();
continue
finally:
- if Strm != None:
+ if Strm is not None:
Strm.close()
return Result
# Check a signature. 'sig' is a 3 tuple that has the sigId, date and
# key ID
def Check(self,Sig):
- if Sig[0] == None or Sig[1] == None or Sig[2] == None:
+ if Sig[0] is None or Sig[1] is None or Sig[2] is None:
return "Invalid signature";
if int(Sig[1]) > time.time() + self.FutureCutOff:
return "Signature has a time too far in the future";
# Add a signature, the sig is the same as is given to Check
def Add(self,Sig):
- if Sig[0] == None or Sig[1] == None:
+ if Sig[0] is None or Sig[1] is None:
raise RuntimeError,"Invalid signature";
if Sig[1] < time.time() - self.CleanCutOff:
return;