111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
// /**
|
|
// * File: USMMessage.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using ln.snmp.asn1;
|
|
using System.Linq;
|
|
using ln.snmp.channel;
|
|
namespace ln.snmp.types
|
|
{
|
|
public class USMMessage : SnmpMessage
|
|
{
|
|
public SnmpV3AuthMethod AuthMethod { get; set; }
|
|
public SnmpV3PrivMethod PrivMethod { get; set; }
|
|
|
|
public Integer msgVersion { get; } = new Integer(3);
|
|
public MsgGlobalData msgGlobalData { get; set; }
|
|
public UsmSecurityParameters SecurityParameters { get; set; }
|
|
|
|
public Variable msgData { get; set; }
|
|
|
|
public USMMessage()
|
|
: base(SnmpVersion.V3)
|
|
{
|
|
msgGlobalData = new MsgGlobalData();
|
|
SecurityParameters = new UsmSecurityParameters();
|
|
msgData = new NullValue();
|
|
}
|
|
|
|
public USMMessage(ASN1Value asn)
|
|
:this()
|
|
{
|
|
Items = asn.Items.Select((x) => (Variable)x).ToArray();
|
|
}
|
|
|
|
public override Variable[] Items
|
|
{
|
|
get => new Variable[] {
|
|
msgVersion,
|
|
msgGlobalData,
|
|
new OctetString(((ASN1Value)SecurityParameters).AsByteArray),
|
|
msgData
|
|
};
|
|
set
|
|
{
|
|
msgGlobalData = new MsgGlobalData(value[1]);
|
|
SecurityParameters = new UsmSecurityParameters(new ASN1Value(value[2].Bytes));
|
|
msgData = value[3];
|
|
}
|
|
}
|
|
|
|
public override int MessageID
|
|
{
|
|
get => (int)msgGlobalData.msgID.LongValue;
|
|
set => msgGlobalData.msgID.LongValue = value;
|
|
}
|
|
|
|
public override void Add(Variable item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public override void Remove(Variable item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public class MsgGlobalData : AbstractSequence
|
|
{
|
|
public Integer msgID { get; set; }
|
|
public Integer msgMaxSize { get; set; }
|
|
public OctetString msgFlags { get; set; }
|
|
public Integer msgSecurityModel { get; set; }
|
|
|
|
public MsgGlobalData()
|
|
:base(new Identifier(IdentifierClass.UNIVERSAL,true,0x10))
|
|
{
|
|
msgID = new Integer((int)(DateTimeOffset.Now.ToUnixTimeSeconds()));
|
|
msgMaxSize = new Integer(65000);
|
|
msgFlags = new OctetString("\0");
|
|
msgSecurityModel = new Integer(3);
|
|
}
|
|
public MsgGlobalData(ASN1Value asn)
|
|
:this()
|
|
{
|
|
|
|
}
|
|
|
|
public override void Add(Variable item) => throw new NotImplementedException();
|
|
public override void Remove(Variable item) => throw new NotImplementedException();
|
|
|
|
public override Variable[] Items
|
|
{
|
|
get => new Variable[] { msgID,msgMaxSize,msgFlags,msgSecurityModel };
|
|
set
|
|
{
|
|
msgID = value[0] as Integer;
|
|
msgMaxSize = value[1] as Integer;
|
|
msgFlags = value[2] as OctetString;
|
|
msgSecurityModel = value[3] as Integer;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|