From 678350da5d3115ca8fe36766b9cdd75db69bf584 Mon Sep 17 00:00:00 2001 From: Tim Liu Date: Wed, 26 Oct 2022 08:41:24 +0000 Subject: [PATCH] fix golangci-lint error --- nas.go | 82 ++++++++++++---------- nasConvert/ProtocolConfigurationOptions.go | 8 +-- nasType/NAS_DNN_test.go | 3 +- nasType/qos_rule.go | 6 +- security/security.go | 18 +++-- security/snow3g/snow3g_test.go | 1 - 6 files changed, 63 insertions(+), 55 deletions(-) diff --git a/nas.go b/nas.go index 36bc4f4..c907452 100644 --- a/nas.go +++ b/nas.go @@ -212,23 +212,23 @@ func (a *Message) GmmMessageDecode(byteArray *[]byte) error { a.GmmMessage.RegistrationReject = nasMessage.NewRegistrationReject(MsgTypeRegistrationReject) a.GmmMessage.DecodeRegistrationReject(byteArray) case MsgTypeDeregistrationRequestUEOriginatingDeregistration: - a.GmmMessage.DeregistrationRequestUEOriginatingDeregistration = - nasMessage.NewDeregistrationRequestUEOriginatingDeregistration( + a.GmmMessage.DeregistrationRequestUEOriginatingDeregistration = nasMessage. + NewDeregistrationRequestUEOriginatingDeregistration( MsgTypeDeregistrationRequestUEOriginatingDeregistration) a.GmmMessage.DecodeDeregistrationRequestUEOriginatingDeregistration(byteArray) case MsgTypeDeregistrationAcceptUEOriginatingDeregistration: - a.GmmMessage.DeregistrationAcceptUEOriginatingDeregistration = - nasMessage.NewDeregistrationAcceptUEOriginatingDeregistration( + a.GmmMessage.DeregistrationAcceptUEOriginatingDeregistration = nasMessage. + NewDeregistrationAcceptUEOriginatingDeregistration( MsgTypeDeregistrationAcceptUEOriginatingDeregistration) a.GmmMessage.DecodeDeregistrationAcceptUEOriginatingDeregistration(byteArray) case MsgTypeDeregistrationRequestUETerminatedDeregistration: - a.GmmMessage.DeregistrationRequestUETerminatedDeregistration = - nasMessage.NewDeregistrationRequestUETerminatedDeregistration( + a.GmmMessage.DeregistrationRequestUETerminatedDeregistration = nasMessage. + NewDeregistrationRequestUETerminatedDeregistration( MsgTypeDeregistrationRequestUETerminatedDeregistration) a.GmmMessage.DecodeDeregistrationRequestUETerminatedDeregistration(byteArray) case MsgTypeDeregistrationAcceptUETerminatedDeregistration: - a.GmmMessage.DeregistrationAcceptUETerminatedDeregistration = - nasMessage.NewDeregistrationAcceptUETerminatedDeregistration( + a.GmmMessage.DeregistrationAcceptUETerminatedDeregistration = nasMessage. + NewDeregistrationAcceptUETerminatedDeregistration( MsgTypeDeregistrationAcceptUETerminatedDeregistration) a.GmmMessage.DecodeDeregistrationAcceptUETerminatedDeregistration(byteArray) case MsgTypeServiceRequest: @@ -241,15 +241,15 @@ func (a *Message) GmmMessageDecode(byteArray *[]byte) error { a.GmmMessage.ServiceAccept = nasMessage.NewServiceAccept(MsgTypeServiceAccept) a.GmmMessage.DecodeServiceAccept(byteArray) case MsgTypeConfigurationUpdateCommand: - a.GmmMessage.ConfigurationUpdateCommand = - nasMessage.NewConfigurationUpdateCommand(MsgTypeConfigurationUpdateCommand) + a.GmmMessage.ConfigurationUpdateCommand = nasMessage.NewConfigurationUpdateCommand(MsgTypeConfigurationUpdateCommand) a.GmmMessage.DecodeConfigurationUpdateCommand(byteArray) case MsgTypeConfigurationUpdateComplete: - a.GmmMessage.ConfigurationUpdateComplete = - nasMessage.NewConfigurationUpdateComplete(MsgTypeConfigurationUpdateComplete) + a.GmmMessage.ConfigurationUpdateComplete = nasMessage. + NewConfigurationUpdateComplete(MsgTypeConfigurationUpdateComplete) a.GmmMessage.DecodeConfigurationUpdateComplete(byteArray) case MsgTypeAuthenticationRequest: - a.GmmMessage.AuthenticationRequest = nasMessage.NewAuthenticationRequest(MsgTypeAuthenticationRequest) + a.GmmMessage.AuthenticationRequest = nasMessage. + NewAuthenticationRequest(MsgTypeAuthenticationRequest) a.GmmMessage.DecodeAuthenticationRequest(byteArray) case MsgTypeAuthenticationResponse: a.GmmMessage.AuthenticationResponse = nasMessage.NewAuthenticationResponse(MsgTypeAuthenticationResponse) @@ -412,60 +412,64 @@ func (a *Message) GsmMessageDecode(byteArray *[]byte) error { } switch a.GsmMessage.GsmHeader.GetMessageType() { case MsgTypePDUSessionEstablishmentRequest: - a.GsmMessage.PDUSessionEstablishmentRequest = - nasMessage.NewPDUSessionEstablishmentRequest(MsgTypePDUSessionEstablishmentRequest) + a.GsmMessage.PDUSessionEstablishmentRequest = nasMessage. + NewPDUSessionEstablishmentRequest(MsgTypePDUSessionEstablishmentRequest) a.GsmMessage.DecodePDUSessionEstablishmentRequest(byteArray) case MsgTypePDUSessionEstablishmentAccept: - a.GsmMessage.PDUSessionEstablishmentAccept = - nasMessage.NewPDUSessionEstablishmentAccept(MsgTypePDUSessionEstablishmentAccept) + a.GsmMessage.PDUSessionEstablishmentAccept = nasMessage. + NewPDUSessionEstablishmentAccept(MsgTypePDUSessionEstablishmentAccept) a.GsmMessage.DecodePDUSessionEstablishmentAccept(byteArray) case MsgTypePDUSessionEstablishmentReject: - a.GsmMessage.PDUSessionEstablishmentReject = - nasMessage.NewPDUSessionEstablishmentReject(MsgTypePDUSessionEstablishmentReject) + a.GsmMessage.PDUSessionEstablishmentReject = nasMessage. + NewPDUSessionEstablishmentReject(MsgTypePDUSessionEstablishmentReject) a.GsmMessage.DecodePDUSessionEstablishmentReject(byteArray) case MsgTypePDUSessionAuthenticationCommand: - a.GsmMessage.PDUSessionAuthenticationCommand = - nasMessage.NewPDUSessionAuthenticationCommand(MsgTypePDUSessionAuthenticationCommand) + a.GsmMessage.PDUSessionAuthenticationCommand = nasMessage. + NewPDUSessionAuthenticationCommand(MsgTypePDUSessionAuthenticationCommand) a.GsmMessage.DecodePDUSessionAuthenticationCommand(byteArray) case MsgTypePDUSessionAuthenticationComplete: - a.GsmMessage.PDUSessionAuthenticationComplete = - nasMessage.NewPDUSessionAuthenticationComplete(MsgTypePDUSessionAuthenticationComplete) + a.GsmMessage.PDUSessionAuthenticationComplete = nasMessage. + NewPDUSessionAuthenticationComplete(MsgTypePDUSessionAuthenticationComplete) a.GsmMessage.DecodePDUSessionAuthenticationComplete(byteArray) case MsgTypePDUSessionAuthenticationResult: - a.GsmMessage.PDUSessionAuthenticationResult = - nasMessage.NewPDUSessionAuthenticationResult(MsgTypePDUSessionAuthenticationResult) + a.GsmMessage.PDUSessionAuthenticationResult = nasMessage. + NewPDUSessionAuthenticationResult(MsgTypePDUSessionAuthenticationResult) a.GsmMessage.DecodePDUSessionAuthenticationResult(byteArray) case MsgTypePDUSessionModificationRequest: - a.GsmMessage.PDUSessionModificationRequest = - nasMessage.NewPDUSessionModificationRequest(MsgTypePDUSessionModificationRequest) + a.GsmMessage.PDUSessionModificationRequest = nasMessage. + NewPDUSessionModificationRequest(MsgTypePDUSessionModificationRequest) a.GsmMessage.DecodePDUSessionModificationRequest(byteArray) case MsgTypePDUSessionModificationReject: - a.GsmMessage.PDUSessionModificationReject = - nasMessage.NewPDUSessionModificationReject(MsgTypePDUSessionModificationReject) + a.GsmMessage.PDUSessionModificationReject = nasMessage. + NewPDUSessionModificationReject(MsgTypePDUSessionModificationReject) a.GsmMessage.DecodePDUSessionModificationReject(byteArray) case MsgTypePDUSessionModificationCommand: - a.GsmMessage.PDUSessionModificationCommand = - nasMessage.NewPDUSessionModificationCommand(MsgTypePDUSessionModificationCommand) + a.GsmMessage.PDUSessionModificationCommand = nasMessage. + NewPDUSessionModificationCommand(MsgTypePDUSessionModificationCommand) a.GsmMessage.DecodePDUSessionModificationCommand(byteArray) case MsgTypePDUSessionModificationComplete: - a.GsmMessage.PDUSessionModificationComplete = - nasMessage.NewPDUSessionModificationComplete(MsgTypePDUSessionModificationComplete) + a.GsmMessage.PDUSessionModificationComplete = nasMessage. + NewPDUSessionModificationComplete(MsgTypePDUSessionModificationComplete) a.GsmMessage.DecodePDUSessionModificationComplete(byteArray) case MsgTypePDUSessionModificationCommandReject: - a.GsmMessage.PDUSessionModificationCommandReject = - nasMessage.NewPDUSessionModificationCommandReject(MsgTypePDUSessionModificationCommandReject) + a.GsmMessage.PDUSessionModificationCommandReject = nasMessage. + NewPDUSessionModificationCommandReject(MsgTypePDUSessionModificationCommandReject) a.GsmMessage.DecodePDUSessionModificationCommandReject(byteArray) case MsgTypePDUSessionReleaseRequest: - a.GsmMessage.PDUSessionReleaseRequest = nasMessage.NewPDUSessionReleaseRequest(MsgTypePDUSessionReleaseRequest) + a.GsmMessage.PDUSessionReleaseRequest = nasMessage. + NewPDUSessionReleaseRequest(MsgTypePDUSessionReleaseRequest) a.GsmMessage.DecodePDUSessionReleaseRequest(byteArray) case MsgTypePDUSessionReleaseReject: - a.GsmMessage.PDUSessionReleaseReject = nasMessage.NewPDUSessionReleaseReject(MsgTypePDUSessionReleaseReject) + a.GsmMessage.PDUSessionReleaseReject = nasMessage. + NewPDUSessionReleaseReject(MsgTypePDUSessionReleaseReject) a.GsmMessage.DecodePDUSessionReleaseReject(byteArray) case MsgTypePDUSessionReleaseCommand: - a.GsmMessage.PDUSessionReleaseCommand = nasMessage.NewPDUSessionReleaseCommand(MsgTypePDUSessionReleaseCommand) + a.GsmMessage.PDUSessionReleaseCommand = nasMessage. + NewPDUSessionReleaseCommand(MsgTypePDUSessionReleaseCommand) a.GsmMessage.DecodePDUSessionReleaseCommand(byteArray) case MsgTypePDUSessionReleaseComplete: - a.GsmMessage.PDUSessionReleaseComplete = nasMessage.NewPDUSessionReleaseComplete(MsgTypePDUSessionReleaseComplete) + a.GsmMessage.PDUSessionReleaseComplete = nasMessage. + NewPDUSessionReleaseComplete(MsgTypePDUSessionReleaseComplete) a.GsmMessage.DecodePDUSessionReleaseComplete(byteArray) case MsgTypeStatus5GSM: a.GsmMessage.Status5GSM = nasMessage.NewStatus5GSM(MsgTypeStatus5GSM) diff --git a/nasConvert/ProtocolConfigurationOptions.go b/nasConvert/ProtocolConfigurationOptions.go index be33904..188ca0f 100644 --- a/nasConvert/ProtocolConfigurationOptions.go +++ b/nasConvert/ProtocolConfigurationOptions.go @@ -240,11 +240,11 @@ func (protocolConfigurationOptions *ProtocolConfigurationOptions) AddIPv4LinkMTU protocolOrContainerUnit.ProtocolOrContainerID = nasMessage.IPv4LinkMTUDL protocolOrContainerUnit.LengthOfContents = 2 logger.ConvertLog.Traceln("LengthOfContents: ", protocolOrContainerUnit.LengthOfContents) - protocolOrContainerUnit.Contents = - append(protocolOrContainerUnit.Contents, []byte{uint8(mtu >> 8), uint8(mtu & 0xff)}...) + protocolOrContainerUnit.Contents = append( + protocolOrContainerUnit.Contents, []byte{uint8(mtu >> 8), uint8(mtu & 0xff)}...) logger.ConvertLog.Traceln("Contents: ", protocolOrContainerUnit.Contents) - protocolConfigurationOptions.ProtocolOrContainerList = - append(protocolConfigurationOptions.ProtocolOrContainerList, protocolOrContainerUnit) + protocolConfigurationOptions.ProtocolOrContainerList = append( + protocolConfigurationOptions.ProtocolOrContainerList, protocolOrContainerUnit) return } diff --git a/nasType/NAS_DNN_test.go b/nasType/NAS_DNN_test.go index 9f86f7c..2585f68 100644 --- a/nasType/NAS_DNN_test.go +++ b/nasType/NAS_DNN_test.go @@ -60,7 +60,8 @@ func TestNasTypeDNNGetSetDNNValue(t *testing.T) { // length of label = 62, length of encoded buffer = 100 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghij", - []uint8{0x3E, + []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, diff --git a/nasType/qos_rule.go b/nasType/qos_rule.go index 09760cf..99fa777 100644 --- a/nasType/qos_rule.go +++ b/nasType/qos_rule.go @@ -65,11 +65,9 @@ func (q *QoSRules) MarshalBinary() ([]byte, error) { var packetFilterError error var packetFilterBytes []byte if rule.Operation == OperationCodeModifyExistingQoSRuleAndDeletePacketFilters { - packetFilterBytes, packetFilterError = - buildPacketFilterDeleteList(rule.PacketFilterList) + packetFilterBytes, packetFilterError = buildPacketFilterDeleteList(rule.PacketFilterList) } else { - packetFilterBytes, packetFilterError = - buildPacketFilterList(rule.PacketFilterList) + packetFilterBytes, packetFilterError = buildPacketFilterList(rule.PacketFilterList) } if packetFilterError != nil { diff --git a/security/security.go b/security/security.go index fae063d..acca22f 100644 --- a/security/security.go +++ b/security/security.go @@ -14,7 +14,8 @@ import ( ) func NASEncrypt(AlgoID uint8, KnasEnc [16]byte, Count uint32, Bearer uint8, - Direction uint8, payload []byte) error { + Direction uint8, payload []byte, +) error { if Bearer > 0x1f { return fmt.Errorf("Bearer is beyond 5 bits") } @@ -62,7 +63,8 @@ func NASEncrypt(AlgoID uint8, KnasEnc [16]byte, Count uint32, Bearer uint8, } func NASMacCalculate(AlgoID uint8, KnasInt [16]uint8, Count uint32, - Bearer uint8, Direction uint8, msg []byte) ([]byte, error) { + Bearer uint8, Direction uint8, msg []byte, +) ([]byte, error) { if Bearer > 0x1f { return nil, fmt.Errorf("Bearer is beyond 5 bits") } @@ -124,7 +126,8 @@ func NEA1(ck [16]byte, countC, bearer, direction uint32, ibs []byte, length uint // ibs: input bit stream, obs: output bit stream func NEA2(key [16]byte, count uint32, bearer uint8, direction uint8, - ibs []byte) (obs []byte, err error) { + ibs []byte, +) (obs []byte, err error) { // Couter[0..32] | BEARER[0..4] | DIRECTION[0] | 0^26 | 0^64 couterBlk := make([]byte, 16) // First 32 bits are count @@ -147,7 +150,8 @@ func NEA2(key [16]byte, count uint32, bearer uint8, direction uint8, // NEA3 ibs: input bit stream, obs: output bit stream // ref: https://www.gsma.com/security/wp-content/uploads/2019/05/EEA3_EIA3_specification_v1_8.pdf func NEA3(ck [16]byte, count uint32, bearer uint8, direction uint8, - ibs []byte, length uint32) (obs []byte, err error) { + ibs []byte, length uint32, +) (obs []byte, err error) { iv := make([]byte, 16) binary.BigEndian.PutUint32(iv, count) iv[4] = (bearer << 3) | (direction << 2) @@ -207,7 +211,8 @@ func mul(V, P, c uint64) uint64 { } func NIA1(ik [16]byte, countI uint32, bearer byte, direction uint32, msg []byte, length uint64) ( - mac []byte, err error) { + mac []byte, err error, +) { fresh := uint32(bearer) << 27 var k [4]uint32 for i := uint32(0); i < 4; i++ { @@ -266,7 +271,8 @@ func NIA2(key [16]byte, count uint32, bearer uint8, direction uint8, msg []byte) // NIA3 ibs: input bit stream, obs: output bit stream (mac) // ref: https://www.gsma.com/security/wp-content/uploads/2019/05/EEA3_EIA3_specification_v1_8.pdf func NIA3(ik [16]byte, count uint32, bearer uint8, direction uint8, - msg []byte, length uint32) (mac []byte, err error) { + msg []byte, length uint32, +) (mac []byte, err error) { iv := make([]byte, 16) binary.BigEndian.PutUint32(iv, count) iv[4] = (bearer << 3) & 0xF8 diff --git a/security/snow3g/snow3g_test.go b/security/snow3g/snow3g_test.go index 984c573..cddcc65 100644 --- a/security/snow3g/snow3g_test.go +++ b/security/snow3g/snow3g_test.go @@ -53,4 +53,3 @@ func TestSnow3g(t *testing.T) { }) } } -