diff --git a/nasType/NAS_DNN.go b/nasType/NAS_DNN.go index f76c3b1..5e7359d 100644 --- a/nasType/NAS_DNN.go +++ b/nasType/NAS_DNN.go @@ -65,15 +65,17 @@ func fqdnToRfc1035(fqdn string) ([]byte, error) { domainSegments := strings.Split(fqdn, ".") for _, segment := range domainSegments { - if len(segment) > 63 { - return nil, errors.New("fqdn limit the label to 63 octets or less") + // In RFC 1035 max length is 63, but in TS 23.003 including length octet + if len(segment) > 62 { + return nil, errors.New("DNN limit the label to 62 octets or less") } rfc1035RR = append(rfc1035RR, uint8(len(segment))) rfc1035RR = append(rfc1035RR, segment...) } - if len(rfc1035RR) > 255 { - return nil, errors.New("fqdn should less then 255 octet") + // In RFC 1035 max length is 255, but in TS 23.003 is 100 + if len(rfc1035RR) > 100 { + return nil, errors.New("DNN should less then 100 octet") } return rfc1035RR, nil } diff --git a/nasType/NAS_DNN_test.go b/nasType/NAS_DNN_test.go index ad1ec9a..9f86f7c 100644 --- a/nasType/NAS_DNN_test.go +++ b/nasType/NAS_DNN_test.go @@ -56,13 +56,49 @@ func TestNasTypeDNNGetSetDNNValue(t *testing.T) { 0x03, 0x63, 0x6f, 0x6d, }, }, + { + // length of label = 62, length of encoded buffer = 100 + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + + ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij", + []uint8{0x3E, + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, + 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, + 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, + 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, + 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x24, + 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, + 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, + 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, + }, + }, } a := nasType.NewDNN(0) for _, table := range NNTable { a.SetDNN(table.in) assert.Equalf(t, table.out, a.Buffer, "in(%v): out %v, actual %x", table.in, table.out, a.Buffer) - assert.Equalf(t, uint8(len(table.out)), a.Len, "outlen %d, actual %d", table.in, len(table.out), a.Len) + assert.Equalf(t, uint8(len(table.out)), a.Len, "in(%v): outlen %d, actual %d", table.in, len(table.out), a.Len) assert.Equalf(t, table.in, a.GetDNN(), "in(%v): GetDNN %x", table.in, a.GetDNN()) } } + +func TestNasTypeDNNSetDNNInvalidValue(t *testing.T) { + invalidDnns := []string{ + // length of label > 62 + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A", + // length of encoded buffer > 100 + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk", + } + + var emptyDNN []uint8 + a := nasType.NewDNN(0) + for _, dnn := range invalidDnns { + a.SetDNN(dnn) + assert.Equalf(t, emptyDNN, a.Buffer, "in(%v): out <>, actual %x", dnn, a.Buffer) + assert.Equalf(t, uint8(0), a.Len, "in(%v): outlen 0, actual %d", dnn, a.Len) + } +}