Skip to content

Commit a561901

Browse files
committed
added basic support for ASN.1 VideotexString
1 parent 12acfe7 commit a561901

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

Asn1Parser/Asn1Reader.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ public Asn1Universal GetTagObject() {
550550
return new Asn1PrintableString(this);
551551
case (Byte)Asn1Type.TeletexString:
552552
return new Asn1TeletexString(this);
553+
case (Byte)Asn1Type.VideotexString:
554+
return new Asn1VideotexString(this);
553555
case (Byte)Asn1Type.IA5String:
554556
return new Asn1IA5String(this);
555557
case (Byte)Asn1Type.UTCTime:

Asn1Parser/Universal/Asn1String.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public static Asn1String DecodeAnyString(Byte[] rawData, IEnumerable<Asn1Type> a
9191
return new Asn1TeletexString(rawData);
9292
case Asn1Type.NumericString:
9393
return new Asn1NumericString(rawData);
94-
94+
case Asn1Type.VideotexString:
95+
return new Asn1VideotexString(rawData);
9596
default:
9697
throw new Asn1InvalidTagException("Input data is not valid string.");
9798
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.IO;
3+
using System.Text;
4+
5+
namespace SysadminsLV.Asn1Parser.Universal;
6+
/// <summary>
7+
/// Represents an ASN.1 <strong>VideotexString</strong> data type.
8+
/// The ASN.1 VideotexString type supports T.100/T.101 characters. This type is no longer used.
9+
/// </summary>
10+
public sealed class Asn1VideotexString : Asn1String {
11+
const Asn1Type TYPE = Asn1Type.VideotexString;
12+
13+
/// <summary>
14+
/// Initializes a new instance of the <strong>Asn1VideotexString</strong> class from an <see cref="Asn1Reader"/>
15+
/// object.
16+
/// </summary>
17+
/// <param name="asn">Existing <see cref="Asn1Reader"/> object.</param>
18+
/// <exception cref="Asn1InvalidTagException">
19+
/// Current position in the <strong>ASN.1</strong> object is not <strong>VideotexString</strong> data type.
20+
/// </exception>
21+
/// <exception cref="InvalidDataException">
22+
/// Input data contains invalid VideotexString character.
23+
/// </exception>
24+
public Asn1VideotexString(Asn1Reader asn) : base(asn, TYPE) {
25+
decode(asn);
26+
}
27+
/// <summary>
28+
/// Initializes a new instance of <strong>Asn1VideotexString</strong> from a ASN.1-encoded byte array.
29+
/// </summary>
30+
/// <param name="rawData">ASN.1-encoded byte array.</param>
31+
/// <exception cref="Asn1InvalidTagException">
32+
/// <strong>rawData</strong> is not <strong>VideotexString</strong> data type.
33+
/// </exception>
34+
/// <exception cref="InvalidDataException">
35+
/// Input data contains invalid VideotexString character.
36+
/// </exception>
37+
public Asn1VideotexString(Byte[] rawData) : this(new Asn1Reader(rawData)) { }
38+
/// <summary>
39+
/// Initializes a new instance of the <strong>Asn1VideotexString</strong> class from a unicode string.
40+
/// </summary>
41+
/// <param name="inputString">A unicode string to encode.</param>
42+
/// <exception cref="InvalidDataException">
43+
/// <strong>inputString</strong> contains invalid VideotexString characters
44+
/// </exception>
45+
public Asn1VideotexString(String inputString) : base(TYPE) {
46+
encode(inputString);
47+
}
48+
49+
void encode(String inputString) {
50+
Initialize(new Asn1Reader(Asn1Utils.Encode(Encoding.ASCII.GetBytes(inputString), TYPE)));
51+
Value = inputString;
52+
}
53+
void decode(Asn1Reader asn) {
54+
Value = Encoding.ASCII.GetString(asn.GetPayload());
55+
}
56+
57+
/// <inheritdoc/>
58+
public override String GetDisplayValue() {
59+
return Value;
60+
}
61+
}

0 commit comments

Comments
 (0)