<commit_before>// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package command

import (
	"github.com/fiorix/go-diameter/diam"
	"github.com/fiorix/go-diameter/diam/datatype"
	"github.com/fiorix/go-diameter/diam/dict"
)

// CER is a Capabilities-Exchange-Request message.
// See RFC 6733 section 5.3.1 for details.
type CER struct {
	OriginHost          datatype.DiameterIdentity `avp:"Origin-Host"`
	OriginRealm         datatype.DiameterIdentity `avp:"Origin-Realm"`
	OriginStateID       *diam.AVP                 `avp:"Origin-State-Id"`
	InbandSecurityID    *diam.AVP                 `avp:"Inband-Security-Id"`
	AcctAppID           []*diam.AVP               `avp:"Acct-Application-Id"`
	AuthAppID           []*diam.AVP               `avp:"Auth-Application-Id"`
	VendorSpecificAppID []struct {
		AcctAppID *diam.AVP `avp:"Acct-Application-Id"`
		AuthAppID *diam.AVP `avp:"Auth-Application-Id"`
	} `avp:"Vendor-Specific-Application-Id"`

	appID []uint32 // List of supported application IDs.
}

// Parse parses and validates the given message, and returns nil when
// all AVPs are ok, and all accounting or authentication applications
// in the CER match the applications in our dictionary. If one or more
// mandatory AVPs are missing, it returns a nil failedAVP and a proper
// error. If all mandatory AVPs are present but no common application
// is found, then it returns the failedAVP (with the application that
// we don't support in our dictionary) and an error. Another cause
// for error is the presence of Inband Security, we don't support that.
func (cer *CER) Parse(m *diam.Message) (failedAVP *diam.AVP, err error) {
	if err = m.Unmarshal(cer); err != nil {
		return nil, err
	}
	if cer.InbandSecurityID != nil {
		return cer.InbandSecurityID, ErrNoCommonSecurity
	}
	if err = cer.sanityCheck(); err != nil {
		return nil, err
	}
	if failedAVP, err = cer.appsOK(m.Dictionary()); err != nil {
		return failedAVP, err
	}
	if len(cer.appID) == 0 {
		return nil, ErrMissingApplication
	}
	return nil, nil
}
<commit_msg>Ensure Inband-Security-Id is 0 if set<commit_after>// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package command

import (
	"github.com/fiorix/go-diameter/diam"
	"github.com/fiorix/go-diameter/diam/datatype"
	"github.com/fiorix/go-diameter/diam/dict"
)

// CER is a Capabilities-Exchange-Request message.
// See RFC 6733 section 5.3.1 for details.
type CER struct {
	OriginHost          datatype.DiameterIdentity `avp:"Origin-Host"`
	OriginRealm         datatype.DiameterIdentity `avp:"Origin-Realm"`
	OriginStateID       *diam.AVP                 `avp:"Origin-State-Id"`
	InbandSecurityID    *diam.AVP                 `avp:"Inband-Security-Id"`
	AcctAppID           []*diam.AVP               `avp:"Acct-Application-Id"`
	AuthAppID           []*diam.AVP               `avp:"Auth-Application-Id"`
	VendorSpecificAppID []struct {
		AcctAppID *diam.AVP `avp:"Acct-Application-Id"`
		AuthAppID *diam.AVP `avp:"Auth-Application-Id"`
	} `avp:"Vendor-Specific-Application-Id"`

	appID []uint32 // List of supported application IDs.
}

// Parse parses and validates the given message, and returns nil when
// all AVPs are ok, and all accounting or authentication applications
// in the CER match the applications in our dictionary. If one or more
// mandatory AVPs are missing, it returns a nil failedAVP and a proper
// error. If all mandatory AVPs are present but no common application
// is found, then it returns the failedAVP (with the application that
// we don't support in our dictionary) and an error. Another cause
// for error is the presence of Inband Security, we don't support that.
func (cer *CER) Parse(m *diam.Message) (failedAVP *diam.AVP, err error) {
	if err = m.Unmarshal(cer); err != nil {
		return nil, err
	}
	if cer.InbandSecurityID != nil {
		if v := cer.InbandSecurityID.Data.(datatype.Unsigned32); v != 0 {
			return cer.InbandSecurityID, ErrNoCommonSecurity
		}
	}
	if err = cer.sanityCheck(); err != nil {
		return nil, err
	}
	if failedAVP, err = cer.appsOK(m.Dictionary()); err != nil {
		return failedAVP, err
	}
	if len(cer.appID) == 0 {
		return nil, ErrMissingApplication
	}
	return nil, nil
}

{'fraction_non_alphanumeric': 0.1098976109215017, 'fraction_numerical': 0.009101251422070534, 'mean_word_length': 3.2432432432432434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '475854', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1416, 'n_words': 454}