MCPcopy Create free account
hub / github.com/dedsec1121fk/DedSec / db_init

Function db_init

Scripts/ButSystem.py:677–1056  ·  view source on GitHub ↗

db_init. Database helper for connecting to or initializing the SQLite database. This docstring was expanded to make future maintenance easier. Returns: Varies.

()

Source from the content-addressed store, hash-verified

675This docstring was added automatically to improve maintainability.
676
677Args:
678 plaintext: Parameter.
679
680Returns:
681 Varies.
682"""
683 nonce = os.urandom(NONCE_LEN)
684 cipher = Cipher(algorithms.AES(MASTER_KEY), modes.GCM(nonce))
685 enc = cipher.encryptor()
686 ct = enc.update(plaintext.encode("utf-8")) + enc.finalize()
687 blob = nonce + enc.tag + ct
688 return base64.urlsafe_b64encode(blob).decode("ascii")
689
690def aesgcm_decrypt_text(blob_b64: str) -> str:
691 """aesgcm_decrypt_text.
692
693Internal helper function.
694
695This docstring was added automatically to improve maintainability.
696
697Args:
698 blob_b64: Parameter.
699
700Returns:
701 Varies.
702"""
703 blob = base64.urlsafe_b64decode(blob_b64.encode("ascii"))
704 nonce = blob[:NONCE_LEN]
705 tag = blob[NONCE_LEN:NONCE_LEN+TAG_LEN]
706 ct = blob[NONCE_LEN+TAG_LEN:]
707 cipher = Cipher(algorithms.AES(MASTER_KEY), modes.GCM(nonce, tag))
708 dec = cipher.decryptor()
709 pt = dec.update(ct) + dec.finalize()
710 return pt.decode("utf-8", errors="replace")
711
712# ---------------------------
713# Database
714# ---------------------------
715
716def db_connect():
717 """db_connect.
718
719Database helper for connecting to or initializing the SQLite database.
720
721This docstring was expanded to make future maintenance easier.
722
723Returns:
724 Varies.
725"""
726 conn = sqlite3.connect(DB_PATH, check_same_thread=False)
727 conn.row_factory = sqlite3.Row
728 conn.execute("PRAGMA foreign_keys = ON;")
729 return conn
730
731def now_z() -> str:
732 """now_z.
733
734Internal helper function.

Callers 3

ButSystem.pyFile · 0.70
chat_withFunction · 0.70
groupsFunction · 0.70

Calls 2

db_connectFunction · 0.70
_ensure_colFunction · 0.70

Tested by

no test coverage detected