Beispiel #1
0
func decode(data []byte) (interface{}, error) {
	m := Message{}
	_, err := asn1.Unmarshal(data, &m)
	if err != nil {
		return nil, fmt.Errorf("error in message decode: %v", err)
	}
	// Response
	pdu := new(PDU)
	// hack ANY -> IMPLICIT SEQUENCE
	m.Data.FullBytes[0] = 0x30
	_, err = asn1.Unmarshal(m.Data.FullBytes, pdu)
	if err != nil {
		return nil, fmt.Errorf("error in PDU decode: %v, %#v", err, m.Data.FullBytes, pdu)
	}
	return pdu, nil
}
Beispiel #2
0
Datei: snmp.go Projekt: huin/snmp
func parseVarValue(rv asn1.RawValue) (value interface{}, err error) {
	switch rv.Class {
	case asn1.ClassUniversal:
		_, err = asn1.Unmarshal(rv.FullBytes, &value)
		return
	case asn1.ClassApplication:
		switch rv.Tag {
		case TagCounter32:
			var v uint32
			v, err = asn1.ParseUint32(rv.Bytes)
			return Counter32(v), err
		case TagGauge32:
			var v uint32
			v, err = asn1.ParseUint32(rv.Bytes)
			return Gauge32(v), err
		case TagTimeTicks:
			var v uint32
			v, err = asn1.ParseUint32(rv.Bytes)
			return TimeTicks(v), err
		case TagOpaque:
			return Opaque(rv.Bytes), err
		case TagCounter64:
			var v uint64
			v, err = asn1.ParseUint64(rv.Bytes)
			return Counter64(v), err
		default:
			err = fmt.Errorf("Unknown application class tag %d", rv.Tag)
		}
	default:
		err = fmt.Errorf("Unknown var value class %d", rv.Class)
	}
	return
}