39 lines
727 B
Python
Executable file
39 lines
727 B
Python
Executable file
#!/usr/bin/env python
|
|
"""
|
|
Module to generate a random string
|
|
|
|
Attributes:
|
|
LENGTH (int): Defaults to a length of 16
|
|
"""
|
|
|
|
import argparse
|
|
import base64
|
|
import os
|
|
import sys
|
|
|
|
LENGTH = 16
|
|
|
|
|
|
def generate(length: int) -> str:
|
|
"""Simple function to call OpenSSL
|
|
|
|
Args:
|
|
length (int): length of string to return
|
|
"""
|
|
return base64.encodebytes(os.urandom(256)).decode()[:length]
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
def main() -> int:
|
|
"""Main function to call"""
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('-n', dest='length', default=LENGTH, type=int)
|
|
args = parser.parse_args()
|
|
|
|
sys.stdout.write(generate(args.length))
|
|
|
|
return 0
|
|
|
|
sys.exit(main())
|