Merge pull request 'Block overwrite' (#6) from key-overwrite into master

Reviewed-on: https://apollo-server.ddns.net/gitea/Hesham/hesham-rsa/pulls/6
This commit is contained in:
Hesham 2020-09-06 09:06:28 +03:00
commit b97b6b14f4

13
rsa.py
View File

@ -30,6 +30,16 @@ def main():
print("hesham-rsa version ", VERSION) print("hesham-rsa version ", VERSION)
if sys.argv[1] == "gen" and len(sys.argv) == 4: ##rsa gen <keysize> <keyname> if sys.argv[1] == "gen" and len(sys.argv) == 4: ##rsa gen <keysize> <keyname>
keyFileName = sys.argv[3] keyFileName = sys.argv[3]
if keyExist(keyFileName):
choice = input("overwrite key %s (y/n)" % keyFileName)
if choice == "y":
key = generateKeys(keyFileName, int(sys.argv[2]))
elif choice == "n":
sys.exit(0)
else:
print("unrecognized choice!")
sys.exit(1)
else:
key = generateKeys(keyFileName, int(sys.argv[2])) key = generateKeys(keyFileName, int(sys.argv[2]))
print("e: ", key[E]) print("e: ", key[E])
print("n: ", key[N]) print("n: ", key[N])
@ -351,5 +361,8 @@ def backTrack(x):
print("\b",end="") print("\b",end="")
length -= 1 length -= 1
def keyExist(keyName):
exist = os.path.exists(keysFolder+keyName)
return exist
if __name__ == "__main__": if __name__ == "__main__":
main() main()