當前位置: 首頁>>代碼示例>>Golang>>正文


Golang asn1.RawValue類代碼示例

本文整理匯總了Golang中encoding/asn1.RawValue的典型用法代碼示例。如果您正苦於以下問題:Golang RawValue類的具體用法?Golang RawValue怎麽用?Golang RawValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RawValue類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Marshal

func (msg *messageV3) Marshal() (b []byte, err error) {
	var buf []byte
	raw := asn1.RawValue{Class: classUniversal, Tag: tagSequence, IsCompound: true}

	buf, err = asn1.Marshal(msg.version)
	if err != nil {
		return
	}
	raw.Bytes = buf

	buf, err = msg.globalDataV3.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	buf, err = msg.securityParameterV3.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	raw.Bytes = append(raw.Bytes, msg.pduBytes...)
	return asn1.Marshal(raw)
}
開發者ID:mgenov,項目名稱:snmpgo,代碼行數:25,代碼來源:message.go

示例2: convertClass

// convertClass converts the encoding of values in SNMP response from
// "custom" class to the corresponding "universal" class, thus enabling
// use of the asn1 parser from the encoding/asn1 package.
func convertClass(v *asn1.RawValue) {
	if v.Class != 1 {
		// Not a custom type.
		return
	}
	switch v.Tag {
	case 0, 4:
		// IpAddress ::= [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4))
		// Opaque ::= [APPLICATION 4] IMPLICIT OCTET STRING
		v.FullBytes[0] = 0x04
		v.Class = 0
		v.Tag = 4
	case 1, 2, 3, 6:
		// Counter32 ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)
		// Unsigned32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
		// TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
		// Counter64 ::= [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615)
		v.FullBytes[0] = 0x02
		v.Class = 0
		v.Tag = 2
	}
}
開發者ID:mathpl,項目名稱:bosun,代碼行數:25,代碼來源:snmp.go

示例3: Marshal

func (v *VarBind) Marshal() (b []byte, err error) {
	var buf []byte
	raw := asn1.RawValue{Class: classUniversal, Tag: tagSequence, IsCompound: true}

	if v.Oid == nil || v.Variable == nil {
		return asn1.Marshal(raw)
	}

	buf, err = v.Oid.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = buf

	buf, err = v.Variable.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	return asn1.Marshal(raw)
}
開發者ID:mgenov,項目名稱:snmpgo,代碼行數:22,代碼來源:pdu.go

示例4: encrypt

func encrypt(msg *messageV3, proto PrivProtocol, key []byte) (err error) {
	var dst, priv []byte
	src := msg.PduBytes()

	switch proto {
	case Des:
		dst, priv, err = encryptDES(src, key, int32(msg.AuthEngineBoots), genSalt32())
	case Aes:
		dst, priv, err = encryptAES(
			src, key, int32(msg.AuthEngineBoots), int32(msg.AuthEngineTime), genSalt64())
	}
	if err != nil {
		return
	}

	raw := asn1.RawValue{Class: classUniversal, Tag: tagOctetString, IsCompound: false}
	raw.Bytes = dst
	dst, err = asn1.Marshal(raw)
	if err == nil {
		msg.SetPduBytes(dst)
		msg.PrivParameter = priv
	}
	return
}
開發者ID:mgenov,項目名稱:snmpgo,代碼行數:24,代碼來源:security.go

示例5: Marshal

func (pdu *ScopedPdu) Marshal() (b []byte, err error) {
	var buf []byte
	raw := asn1.RawValue{Class: classUniversal, Tag: tagSequence, IsCompound: true}

	buf, err = asn1.Marshal(pdu.ContextEngineId)
	if err != nil {
		return
	}
	raw.Bytes = buf

	buf, err = asn1.Marshal(pdu.ContextName)
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	buf, err = pdu.PduV1.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	return asn1.Marshal(raw)
}
開發者ID:yulianghsueh,項目名稱:snmpgo,代碼行數:24,代碼來源:pdu.go

示例6: V1Trap

func (s *SNMP) V1Trap(varPduV1 TrapPduV1) (err error) {
	if s.args.Version > V1 {
		return ArgumentError{
			Value:   s.args.Version,
			Message: "V1trap Unsupported other SNMP Version",
		}
	}

	var buf []byte
	raw := asn1.RawValue{Class: classUniversal, Tag: tagSequence, IsCompound: true}

	//Version
	buf, err = asn1.Marshal(s.args.Version)
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//Community
	buf, err = NewOctetString([]byte(s.args.Community)).Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//Data Trap
	buf = []byte{0xa4, 0x00}
	raw.Bytes = append(raw.Bytes, buf...)

	dataTrapLength := len(raw.Bytes)

	//Enterprise
	oid, _ := NewOid(varPduV1.Enterprise)
	buf, err = oid.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//AgentAddr
	var ipByte [4]byte

	for n, v := range strings.Split(varPduV1.AgentAddr, ".") {
		input, _ := strconv.Atoi(v)

		ipByte[n] = (byte)(input)
	}

	ip := NewIpaddress(ipByte[0], ipByte[1], ipByte[2], ipByte[3])
	buf, err = ip.Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//GenericTrap
	buf, err = NewInteger((int32)(varPduV1.GenericTrap)).Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//SpecificTrap
	buf, err = NewInteger((int32)(varPduV1.SpecificTrap)).Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//TimeStamp
	buf, err = NewTimeTicks((uint32)(varPduV1.TimeStamp)).Marshal()
	if err != nil {
		return
	}
	raw.Bytes = append(raw.Bytes, buf...)

	//VarBinds
	buf = []byte{0x30, 0x00}
	raw.Bytes = append(raw.Bytes, buf...)

	raw.Bytes[dataTrapLength-1] = (byte)(len(raw.Bytes) - dataTrapLength)

	marbuf, _ := asn1.Marshal(raw)
	fmt.Println(hex.Dump(marbuf))

	s.conn.SetWriteDeadline(time.Now().Add(s.args.Timeout))
	_, err = s.conn.Write(marbuf[:len(marbuf)])
	fmt.Println("err = ", err)
	return err
}
開發者ID:yulianghsueh,項目名稱:snmpgo,代碼行數:90,代碼來源:snmpgo.go


注:本文中的encoding/asn1.RawValue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。