Skip to content

Commit

Permalink
fix golangci-lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-ywliu committed Oct 26, 2022
1 parent 88f941c commit 678350d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 55 deletions.
82 changes: 43 additions & 39 deletions nas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions nasConvert/ProtocolConfigurationOptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion nasType/NAS_DNN_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions nasType/qos_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 12 additions & 6 deletions security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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++ {
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion security/snow3g/snow3g_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ func TestSnow3g(t *testing.T) {
})
}
}

0 comments on commit 678350d

Please sign in to comment.