68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
// /**
|
|
// * File: OctetString.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 System.Text;
|
|
using ln.snmp.asn1;
|
|
namespace ln.snmp.types
|
|
{
|
|
public class OctetString : Variable
|
|
{
|
|
public override byte[] Bytes { get; set; }
|
|
|
|
public string StringValue {
|
|
get => Encoding.UTF8.GetString(Bytes);
|
|
set => Bytes = Encoding.UTF8.GetBytes(value);
|
|
}
|
|
|
|
public char[] Characters
|
|
{
|
|
get => StringValue.ToCharArray();
|
|
set => StringValue = new string(value);
|
|
}
|
|
public override object Value { get => Bytes; set => Bytes = (byte[])value; }
|
|
|
|
public OctetString()
|
|
:base(new Identifier(IdentifierClass.UNIVERSAL, false, 4))
|
|
{
|
|
StringValue = "";
|
|
}
|
|
|
|
public OctetString(String text)
|
|
: this()
|
|
{
|
|
StringValue = text;
|
|
}
|
|
|
|
public OctetString(byte[] bytes)
|
|
: this()
|
|
{
|
|
Bytes = bytes;
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[OctetString StringValue={0}]", StringValue.Replace("\0","\\0"));
|
|
}
|
|
|
|
public static implicit operator String(OctetString octetString)
|
|
{
|
|
return octetString.StringValue;
|
|
}
|
|
|
|
public static implicit operator OctetString(String text)
|
|
{
|
|
return new OctetString(text);
|
|
}
|
|
|
|
}
|
|
}
|