From 3e25b2c72c55d3ecef01ca6e9ea1f7c490ef6ad2 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Wed, 12 Jun 2024 21:12:05 +0300 Subject: [PATCH] Add TLEP.Encrypt/DecryptMessagesAtMax and ERROR_UNHANDLEDED_TLEP_LEVEL --- tlep/system.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tlep/system.go b/tlep/system.go index 4fe729f..d1e9d90 100644 --- a/tlep/system.go +++ b/tlep/system.go @@ -2,6 +2,8 @@ package tlep import ( "errors" + "fmt" + "git.qowevisa.me/Qowevisa/gotell/tlep/chaos" "git.qowevisa.me/Qowevisa/gotell/tlep/ecdh" "git.qowevisa.me/Qowevisa/gotell/tlep/encrypt" @@ -20,6 +22,10 @@ var ( TLEP_LEVEL_ECDH_CBES_MKLG TLEPLevel = 3 ) +var ( + ERROR_UNHANDLED_TLEP_LEVEL = errors.New("Unhandled TLEP LEVEL") +) + // Three Layer Encryption Protocol schema type TLEP struct { // Security Layer Level @@ -363,3 +369,27 @@ func (t *TLEP) DecryptMessageMESCHA(message []byte) ([]byte, error) { } return msg.Data, nil } + +func (t *TLEP) EncryptMessageAtMax(msg []byte) ([]byte, error) { + switch t.SLLevel { + case TLEP_LEVEL_ECDH: + return t.EncryptMessageEA(msg) + case TLEP_LEVEL_ECDH_CBES: + return t.EncryptMessageCAFEA(msg) + case TLEP_LEVEL_ECDH_CBES_MKLG: + return t.EncryptMessageMESCHA(msg) + } + return nil, gmyerr.WrapPrefix(fmt.Sprintf("TLEP: %d", t.SLLevel), ERROR_UNHANDLED_TLEP_LEVEL) +} + +func (t *TLEP) DecryptMessageAtMax(msg []byte) ([]byte, error) { + switch t.SLLevel { + case TLEP_LEVEL_ECDH: + return t.DecryptMessageEA(msg) + case TLEP_LEVEL_ECDH_CBES: + return t.DecryptMessageCAFEA(msg) + case TLEP_LEVEL_ECDH_CBES_MKLG: + return t.DecryptMessageMESCHA(msg) + } + return nil, gmyerr.WrapPrefix(fmt.Sprintf("TLEP: %d", t.SLLevel), ERROR_UNHANDLED_TLEP_LEVEL) +}