From e3532d281439d1fba412aa4b8d2743f0122cf2b0 Mon Sep 17 00:00:00 2001 From: monty Date: Wed, 5 Jun 2024 12:26:27 +0100 Subject: [PATCH] use getpass for input of password --- examples/key_store.py | 3 ++- my_scratch.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/examples/key_store.py b/examples/key_store.py index 8246ecc..a0923f7 100644 --- a/examples/key_store.py +++ b/examples/key_store.py @@ -6,6 +6,7 @@ import sys import os import asyncio +from getpass import getpass import logging from pathlib import Path from monstr.ident.keystore import SQLiteKeyStore, KeystoreInterface, KeyDataEncrypter, NamedKeys @@ -19,7 +20,7 @@ async def get_key() -> str: # get password to unlock keystore - return input('keystore key: ') + return getpass('keystore key: ') async def get_store() -> KeystoreInterface: diff --git a/my_scratch.py b/my_scratch.py index 955151a..feaa320 100644 --- a/my_scratch.py +++ b/my_scratch.py @@ -1,5 +1,6 @@ import asyncio import logging +from getpass import getpass from hashlib import sha256 from monstr.ident.keystore import NamedKeys, FileKeyStore, KeyDataEncrypter, SQLiteKeyStore from monstr.ident.persist import MemoryProfileStore @@ -8,6 +9,11 @@ logging.getLogger().setLevel(logging.DEBUG) +async def get_key() -> str: + # will block, use aiconsole where it matters + return getpass('keystore key: ') + + async def convert_store(): # load the old data as alias stores it old_file = '/home/monty/.nostrpy/profiles.csv' @@ -15,25 +21,16 @@ async def convert_store(): # create a new key store and copy name/key maps in new_file = '/home/monty/.nostrpy/keystore.db' - - async def get_key() -> str: - # will block, use aiconsole where it matters - return input('keystore key: ') - my_enc = KeyDataEncrypter(get_key=get_key) new_store = SQLiteKeyStore(new_file, - encrypter=None) + encrypter=my_enc) await new_store.convert_memstore(old_file) - async def test_store(): # create a new key store and copy name/key maps in new_file = '/home/monty/.nostrpy/keystore.db' - async def get_key() -> str: - # will block, use aiconsole where it matters - return input('keystore key: ') my_enc = KeyDataEncrypter(get_key=get_key)