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

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

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