Add TLEP.Encrypt/DecryptMessagesAtMax and ERROR_UNHANDLEDED_TLEP_LEVEL

This commit is contained in:
qowevisa 2024-06-12 21:12:05 +03:00
parent 29dbc8736b
commit 3e25b2c72c

View File

@ -2,6 +2,8 @@ package tlep
import ( import (
"errors" "errors"
"fmt"
"git.qowevisa.me/Qowevisa/gotell/tlep/chaos" "git.qowevisa.me/Qowevisa/gotell/tlep/chaos"
"git.qowevisa.me/Qowevisa/gotell/tlep/ecdh" "git.qowevisa.me/Qowevisa/gotell/tlep/ecdh"
"git.qowevisa.me/Qowevisa/gotell/tlep/encrypt" "git.qowevisa.me/Qowevisa/gotell/tlep/encrypt"
@ -20,6 +22,10 @@ var (
TLEP_LEVEL_ECDH_CBES_MKLG TLEPLevel = 3 TLEP_LEVEL_ECDH_CBES_MKLG TLEPLevel = 3
) )
var (
ERROR_UNHANDLED_TLEP_LEVEL = errors.New("Unhandled TLEP LEVEL")
)
// Three Layer Encryption Protocol schema // Three Layer Encryption Protocol schema
type TLEP struct { type TLEP struct {
// Security Layer Level // Security Layer Level
@ -363,3 +369,27 @@ func (t *TLEP) DecryptMessageMESCHA(message []byte) ([]byte, error) {
} }
return msg.Data, nil 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)
}