• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang asn1.RawValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang base32.NewEncoder函数代码示例发布时间:2022-05-24
下一篇:
Golang asn1.ObjectIdentifier类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap