From 94cfec15f0e9a94341f2468634e8c1bd00a95c66 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Fri, 12 Jul 2024 20:33:22 +0300 Subject: [PATCH] Add IsThisALinkData(data) (bool, error) func to communication package --- communication/protocol.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/communication/protocol.go b/communication/protocol.go index ee7cd66..a55859a 100644 --- a/communication/protocol.go +++ b/communication/protocol.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "encoding/base32" "encoding/gob" + "errors" "git.qowevisa.me/Qowevisa/gotell/gmyerr" ) @@ -158,6 +159,18 @@ func (r *RegisteredUser) GenerateLink(count uint16) (Link, error) { return l, nil } +func IsThisALinkData(data string) (bool, error) { + dst := make([]byte, len([]byte(data))) + n, err := base32.StdEncoding.Decode(dst, []byte(data)) + if err != nil { + return false, err + } + if n != LINK_LEN_V1 { + return false, errors.New("Link len is not standard") + } + return true, nil +} + func (l *Link) Bytes() ([]byte, error) { var buf bytes.Buffer encoder := gob.NewEncoder(&buf)