diff options
author | kongr45gpen <electrovesta@gmail.com> | 2016-03-15 16:41:58 +0200 |
---|---|---|
committer | kongr45gpen <electrovesta@gmail.com> | 2016-03-15 16:41:58 +0200 |
commit | 23d851aff066a39e3ceb01f85c30539e467a70ea (patch) | |
tree | 2feeadac920c62161163b3b4d7ee0ae8361787b9 /local/utility.py | |
parent | e56a487b2a6672284a8f18a816782b5fdebf3b08 (diff) | |
download | supybot_github-23d851aff066a39e3ceb01f85c30539e467a70ea.tar.gz supybot_github-23d851aff066a39e3ceb01f85c30539e467a70ea.tar.bz2 supybot_github-23d851aff066a39e3ceb01f85c30539e467a70ea.zip |
Add support for github secrets
Diffstat (limited to 'local/utility.py')
-rw-r--r-- | local/utility.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/local/utility.py b/local/utility.py index de540a6..2594b61 100644 --- a/local/utility.py +++ b/local/utility.py @@ -1,5 +1,7 @@ import re import math +import random +import string import urllib2 import supybot.conf as conf @@ -134,6 +136,26 @@ def isStatusVisible(repo, status): globals.travisStatuses[repo] = status return changed +def randomString(length): + """Returns a securely generated random string of a specific length""" + return ''.join(random.SystemRandom().choice( + string.ascii_uppercase + string.ascii_lowercase + string.digits + ) for _ in range(length)) + +def secureCompare(s1, s2): + """Securely compare two strings""" + return sum(i != j for i, j in zip(s1, s2)) is 0 + +def getChannelSecret(channel): + """Returns a secret for a channel, or None if that channel has no secret""" + if globals.secretDB is None: + return None + try: + record = globals.secretDB.get(channel, 1) + return record.secret + except KeyError: + return None + def hexToMirc(hash): colors = { 'white': (255, 255, 255), |