mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathAsn1UniversalType.cs
More file actions
52 lines (39 loc) · 1.85 KB
/
Copy pathAsn1UniversalType.cs
File metadata and controls
52 lines (39 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.IO;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Asn1
{
internal abstract class Asn1UniversalType
: Asn1Type
{
internal readonly Asn1Tag m_tag;
internal Asn1UniversalType(Type platformType, int tagNo)
: base(platformType)
{
m_tag = Asn1Tag.Create(Asn1Tags.Universal, tagNo);
}
internal Asn1Object CheckedCast(Asn1Object asn1Object)
{
if (PlatformType.IsInstanceOfType(asn1Object))
return asn1Object;
throw new ArgumentException("unexpected object: " + Platform.GetTypeName(asn1Object));
}
internal Asn1Object FromExplicit(Asn1Object asn1Object)
{
if (PlatformType.IsInstanceOfType(asn1Object))
return asn1Object;
throw new InvalidOperationException("unexpected explicit encoding");
}
internal virtual Asn1Object FromImplicitPrimitive(DerOctetString octetString) =>
throw new InvalidOperationException("unexpected implicit primitive encoding");
internal virtual Asn1Object FromImplicitConstructed(Asn1Sequence sequence) =>
throw new InvalidOperationException("unexpected implicit constructed encoding");
/// <exception cref="IOException"/>
internal Asn1Object FromByteArray(byte[] bytes) => CheckedCast(Asn1Object.FromByteArray(bytes));
internal Asn1Object GetContextTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
CheckedCast(Asn1Utilities.CheckContextTagClass(taggedObject).GetBaseUniversal(declaredExplicit, this));
internal Asn1Object GetTagged(Asn1TaggedObject taggedObject, bool declaredExplicit) =>
CheckedCast(taggedObject.GetBaseUniversal(declaredExplicit, this));
internal Asn1Tag Tag => m_tag;
}
}