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 pathAsn1Encodable.cs
More file actions
57 lines (44 loc) · 1.82 KB
/
Copy pathAsn1Encodable.cs
File metadata and controls
57 lines (44 loc) · 1.82 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
53
54
55
56
57
using System.IO;
namespace Org.BouncyCastle.Asn1
{
public abstract class Asn1Encodable
: IAsn1Convertible
{
public const string Ber = "BER";
public const string Der = "DER";
public const string DL = "DL";
public virtual void EncodeTo(Stream output) => ToAsn1Object().EncodeTo(output);
public virtual void EncodeTo(Stream output, string encoding) => ToAsn1Object().EncodeTo(output, encoding);
// TODO[api] Make virtual and override in Asn1Object
public byte[] GetEncoded() => GetEncoded(Ber, preAlloc: 0, postAlloc: 0);
// TODO[api] Make virtual and override in Asn1Object
public byte[] GetEncoded(string encoding) => GetEncoded(encoding, preAlloc: 0, postAlloc: 0);
internal virtual byte[] GetEncoded(string encoding, int preAlloc, int postAlloc) =>
ToAsn1Object().GetEncoded(encoding, preAlloc, postAlloc);
/// <summary>Return the DER encoding of the object, null if the DER encoding can not be made.</summary>
/// <returns>a DER byte array, null otherwise.</returns>
public byte[] GetDerEncoded()
{
try
{
return GetEncoded(Der);
}
catch (IOException)
{
return null;
}
}
public sealed override int GetHashCode() => ToAsn1Object().CallAsn1GetHashCode();
public sealed override bool Equals(object obj)
{
if (obj == this)
return true;
if (!(obj is IAsn1Convertible that))
return false;
Asn1Object o1 = this.ToAsn1Object();
Asn1Object o2 = that.ToAsn1Object();
return o1 == o2 || (null != o2 && o1.CallAsn1Equals(o2));
}
public abstract Asn1Object ToAsn1Object();
}
}