You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

23 lines
567 B

from os.path import isfile
from random import SystemRandom
from string import punctuation, digits, ascii_letters
random = SystemRandom()
def gen_secret():
return ''.join(random.choices(ascii_letters+digits+punctuation, k=64))
def load_or_gen_secret(path, secret_func: callable = gen_secret):
if isfile(path):
with open(path) as f:
return f.read()
else:
from os import chmod
with open(path, 'w') as f:
secret = secret_func()
f.write(secret)
chmod(path, 0o400)
return secret