From 2393690267a84d2c19148631b32bc5e0496da26b Mon Sep 17 00:00:00 2001 From: Yoshiyuki Kurauchi Date: Sat, 23 Dec 2023 15:32:25 +0100 Subject: [PATCH] Fix SMF Set ID encoding --- ie/ie.go | 2 +- ie/ie_string_test.go | 2 +- ie/ie_test.go | 2 +- ie/smf-set-id.go | 32 ++++------------------- message/association-setup-request_test.go | 4 +-- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/ie/ie.go b/ie/ie.go index 5b53690..02cdb83 100644 --- a/ie/ie.go +++ b/ie/ie.go @@ -421,7 +421,7 @@ func (i *IE) ValueAsString() (string, error) { return string(i.Payload), nil } -// ValueAsFQDN returns the value of IE as FQDN. +// ValueAsFQDN returns the value of IE as string, decoded as FQDN. func (i *IE) ValueAsFQDN() (string, error) { if i.IsGrouped() { return "", &InvalidTypeError{Type: i.Type} diff --git a/ie/ie_string_test.go b/ie/ie_string_test.go index 3e6b1cc..986c89c 100644 --- a/ie/ie_string_test.go +++ b/ie/ie_string_test.go @@ -180,7 +180,7 @@ func TestStringIEs(t *testing.T) { description: "SMFSetID", structured: ie.NewSMFSetID("go-pfcp"), decoded: "go-pfcp", - decoderFunc: func(i *ie.IE) (string, error) { return i.SMFSetIDString() }, + decoderFunc: func(i *ie.IE) (string, error) { return i.SMFSetID() }, }, { description: "UEIPAddressPoolIdentity", structured: ie.NewUEIPAddressPoolIdentity("go-pfcp"), diff --git a/ie/ie_test.go b/ie/ie_test.go index 444eac3..a751360 100644 --- a/ie/ie_test.go +++ b/ie/ie_test.go @@ -2451,7 +2451,7 @@ func TestIEs(t *testing.T) { }, { "SMFSetID", ie.NewSMFSetID("go-pfcp.epc.3gppnetwork.org"), - []byte{0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67}, + []byte{0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67}, }, { "QuotaValidityTime", ie.NewQuotaValidityTime(10 * time.Second), diff --git a/ie/smf-set-id.go b/ie/smf-set-id.go index fc93437..cfb5c9b 100644 --- a/ie/smf-set-id.go +++ b/ie/smf-set-id.go @@ -4,38 +4,16 @@ package ie -import "io" - // NewSMFSetID creates a new SMFSetID IE. func NewSMFSetID(id string) *IE { - l := len([]byte(id)) - i := New(SMFSetID, make([]byte, 1+l)) - - i.Payload[0] = 0 // Spare - copy(i.Payload[1:], id) - - return i + return newFQDNIE(SMFSetID, id) } -// SMFSetID returns SMFSetID in []byte if the type of IE matches. -func (i *IE) SMFSetID() ([]byte, error) { +// SMFSetID returns SMFSetID in string if the type of IE matches. +func (i *IE) SMFSetID() (string, error) { if i.Type != SMFSetID { - return nil, &InvalidTypeError{Type: i.Type} - } - - return i.Payload, nil -} - -// SMFSetIDString returns SMFSetID in string if the type of IE matches. -func (i *IE) SMFSetIDString() (string, error) { - v, err := i.SMFSetID() - if err != nil { - return "", err - } - - if len(v) < 1 { - return "", io.ErrUnexpectedEOF + return "", &InvalidTypeError{Type: i.Type} } - return string(v[1:]), nil + return i.ValueAsFQDN() } diff --git a/message/association-setup-request_test.go b/message/association-setup-request_test.go index 5a010b6..ba5791b 100644 --- a/message/association-setup-request_test.go +++ b/message/association-setup-request_test.go @@ -59,7 +59,7 @@ func TestAssociationSetupRequest(t *testing.T) { 0x00, 0x2b, 0x00, 0x02, 0x01, 0x02, 0x00, 0x59, 0x00, 0x01, 0x3f, 0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67, + 0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67, 0x00, 0xb7, 0x00, 0x09, 0x00, 0xb9, 0x00, 0x05, 0x02, 0x7f, 0x00, 0x00, 0x01, 0x00, 0xe9, 0x00, 0x25, @@ -165,7 +165,7 @@ func TestAssociationSetupRequest(t *testing.T) { 0x00, 0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x01, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xb2, 0x00, 0x15, 0x03, 0x7f, 0x00, 0x00, 0x02, 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0xb4, 0x00, 0x1c, 0x00, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x2e, 0x65, 0x70, 0x63, 0x2e, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2e, 0x6f, 0x72, 0x67, + 0x00, 0xb4, 0x00, 0x1c, 0x07, 0x67, 0x6f, 0x2d, 0x70, 0x66, 0x63, 0x70, 0x03, 0x65, 0x70, 0x63, 0x0b, 0x33, 0x67, 0x70, 0x70, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x03, 0x6f, 0x72, 0x67, 0x00, 0xb7, 0x00, 0x09, 0x00, 0xb9, 0x00, 0x05, 0x02, 0x7f, 0x00, 0x00, 0x01, 0x00, 0xe9, 0x00, 0x29,