-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
Pkcs9LocalKeyId.cs
53 lines (44 loc) · 1.42 KB
/
Pkcs9LocalKeyId.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using System.Formats.Asn1;
using Internal.Cryptography;
namespace System.Security.Cryptography.Pkcs
{
public sealed class Pkcs9LocalKeyId : Pkcs9AttributeObject
{
private byte[]? _lazyKeyId;
public Pkcs9LocalKeyId() :
base(Oids.LocalKeyIdOid.CopyOid())
{
}
public Pkcs9LocalKeyId(byte[] keyId)
// The ReadOnlySpan constructor permits null
: this(new ReadOnlySpan<byte>(keyId))
{
}
public Pkcs9LocalKeyId(ReadOnlySpan<byte> keyId)
: this()
{
AsnWriter writer = new AsnWriter(AsnEncodingRules.DER);
writer.WriteOctetString(keyId);
RawData = writer.Encode();
}
public ReadOnlyMemory<byte> KeyId =>
_lazyKeyId ??= Decode(RawData);
public override void CopyFrom(AsnEncodedData asnEncodedData)
{
base.CopyFrom(asnEncodedData);
_lazyKeyId = null;
}
[return: NotNullIfNotNull(nameof(rawData))]
private static byte[]? Decode(byte[]? rawData)
{
if (rawData == null)
{
return null;
}
return PkcsHelpers.DecodeOctetString(rawData);
}
}
}