blob: eafbfd72bf14f28d987974714daf72af16d446b3 (
plain) (
blame)
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
58
59
60
61
62
63
64
65
|
using System;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Asn1.Mozilla
{
/// <summary>
/// For parsing the PublicKeyAndChallenge created by the KEYGEN tag included by Mozilla based browsers.
/// </summary>
/// <remarks>
/// <code>
/// PublicKeyAndChallenge ::= SEQUENCE
/// {
/// spki SubjectPublicKeyInfo,
/// challenge IA5STRING
/// }
/// </code>
/// </remarks>
public class PublicKeyAndChallenge
: Asn1Encodable
{
private readonly SubjectPublicKeyInfo m_spki;
private readonly DerIA5String m_challenge;
public static PublicKeyAndChallenge GetInstance(object obj)
{
if (obj == null)
return null;
if (obj is PublicKeyAndChallenge publicKeyAndChallenge)
return publicKeyAndChallenge;
#pragma warning disable CS0618 // Type or member is obsolete
return new PublicKeyAndChallenge(Asn1Sequence.GetInstance(obj));
#pragma warning restore CS0618 // Type or member is obsolete
}
public static PublicKeyAndChallenge GetInstance(Asn1TaggedObject taggedObject, bool declaredExplicit)
{
#pragma warning disable CS0618 // Type or member is obsolete
return new PublicKeyAndChallenge(Asn1Sequence.GetInstance(taggedObject, declaredExplicit));
#pragma warning restore CS0618 // Type or member is obsolete
}
public PublicKeyAndChallenge(SubjectPublicKeyInfo spki, DerIA5String challenge)
{
m_spki = spki ?? throw new ArgumentNullException(nameof(spki));
m_challenge = challenge ?? throw new ArgumentNullException(nameof(m_challenge));
}
[Obsolete("Use 'GetInstance' instead")]
public PublicKeyAndChallenge(Asn1Sequence seq)
{
m_spki = SubjectPublicKeyInfo.GetInstance(seq[0]);
m_challenge = DerIA5String.GetInstance(seq[1]);
}
public DerIA5String Challenge => m_challenge;
public SubjectPublicKeyInfo Spki => m_spki;
[Obsolete("Use 'Spki' instead")]
public SubjectPublicKeyInfo SubjectPublicKeyInfo => m_spki;
public override Asn1Object ToAsn1Object() => new DerSequence(m_spki, m_challenge);
}
}
|