本文整理匯總了Golang中github.com/fiorix/go-diameter/diam/sm/smparser.CER類的典型用法代碼示例。如果您正苦於以下問題:Golang CER類的具體用法?Golang CER怎麽用?Golang CER使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CER類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestClient_Handshake_FailedResultCode
func TestClient_Handshake_FailedResultCode(t *testing.T) {
mux := diam.NewServeMux()
mux.HandleFunc("CER", func(c diam.Conn, m *diam.Message) {
cer := new(smparser.CER)
if _, err := cer.Parse(m); err != nil {
panic(err)
}
a := m.Answer(diam.NoCommonApplication)
a.NewAVP(avp.OriginHost, avp.Mbit, 0, clientSettings.OriginHost)
a.NewAVP(avp.OriginRealm, avp.Mbit, 0, clientSettings.OriginRealm)
a.AddAVP(cer.OriginStateID)
a.AddAVP(cer.AcctApplicationID[0]) // The one we send below.
a.WriteTo(c)
})
srv := diamtest.NewServer(mux, dict.Default)
defer srv.Close()
cli := &Client{
Handler: New(clientSettings),
AcctApplicationID: []*diam.AVP{
diam.NewAVP(avp.AcctApplicationID, avp.Mbit, 0, datatype.Unsigned32(0)),
},
}
_, err := cli.Dial(srv.Address)
if err == nil {
t.Fatal("Unexpected CER worked")
}
e, ok := err.(*ErrFailedResultCode)
if !ok {
t.Fatal(err)
}
if !strings.Contains(e.Error(), "failed Result-Code AVP") {
t.Fatal(e.Error())
}
}
示例2: FromCER
// FromCER creates a Metadata object from data in the CER.
func FromCER(cer *smparser.CER) *Metadata {
return &Metadata{
OriginHost: cer.OriginHost,
OriginRealm: cer.OriginRealm,
Applications: cer.Applications(),
}
}
示例3: handleCER
// handleCER handles Capabilities-Exchange-Request messages.
//
// If mandatory AVPs such as Origin-Host or Origin-Realm
// are missing, we close the connection.
//
// See RFC 6733 section 5.3 for details.
func handleCER(sm *StateMachine) diam.HandlerFunc {
return func(c diam.Conn, m *diam.Message) {
ctx := c.Context()
if _, ok := smpeer.FromContext(ctx); ok {
// Ignore retransmission.
return
}
cer := new(smparser.CER)
failedAVP, err := cer.Parse(m)
if err != nil {
if failedAVP != nil {
err = errorCEA(sm, c, m, cer, failedAVP)
if err != nil {
sm.Error(&diam.ErrorReport{
Conn: c,
Message: m,
Error: err,
})
}
}
c.Close()
return
}
err = successCEA(sm, c, m, cer)
if err != nil {
sm.Error(&diam.ErrorReport{
Conn: c,
Message: m,
Error: err,
})
return
}
meta := smpeer.FromCER(cer)
c.SetContext(smpeer.NewContext(ctx, meta))
// Notify about peer passing the handshake.
select {
case sm.hsNotifyc <- c:
default:
}
}
}