From cd3dcaf4a38a7b3bc9b6e00346bbd6dc1a7463e5 Mon Sep 17 00:00:00 2001 From: hinuiiik Date: Thu, 22 Oct 2026 22:48:21 -0400 Subject: [PATCH] make messageheader a dataclass --- messenger.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/messenger.py b/messenger.py index 123a01e..247ef8d 100644 --- a/messenger.py +++ b/messenger.py @@ -2,6 +2,8 @@ import os import pickle import string import hmac +from dataclasses import dataclass + from cryptography.hazmat.primitives import hashes, serialization from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.ciphers.aead import AESGCM @@ -9,6 +11,7 @@ from cryptography.hazmat.primitives.kdf.hkdf import HKDF CURVE = ec.SECP256R1() +@dataclass class MessageHeader: dh: object pn: int @@ -29,7 +32,6 @@ def KDF_RK(rk, dh_out): ).derive(dh_out) return output[:32], output[32:] - def KDF_CK(ck): return ( hmac.new(ck, b"\x01", "sha256").digest(), @@ -40,7 +42,6 @@ def ENCRYPT(mk, plaintext, associated_data): nonce = os.urandom(12) return nonce + AESGCM(mk).encrypt(nonce, plaintext, associated_data) - def DECRYPT(mk, ciphertext, associated_data): return AESGCM(mk).decrypt(ciphertext[:12], ciphertext[12:], associated_data)