Skip to content

Commit 38649e2

Browse files
committed
Move TryGetPac to an extension method
1 parent 519647b commit 38649e2

2 files changed

Lines changed: 49 additions & 38 deletions

File tree

Kerberos.NET/Entities/Krb/KrbEncTicketPart.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// -----------------------------------------------------------------------
55

66
using System;
7-
using System.Linq;
87
using Kerberos.NET.Asn1;
98

109
namespace Kerberos.NET.Entities
@@ -17,42 +16,5 @@ public KrbEncTicketPart DecodeAsApplication(ReadOnlyMemory<byte> data)
1716
{
1817
return DecodeApplication(data);
1918
}
20-
21-
public bool TryGetPac(out PrivilegedAttributeCertificate pac)
22-
{
23-
pac = null;
24-
25-
KrbAuthorizationData adIfRelevantEntry = this.AuthorizationData?.FirstOrDefault(ad => ad.Type == AuthorizationDataType.AdIfRelevant);
26-
if (adIfRelevantEntry == null)
27-
{
28-
return false;
29-
}
30-
31-
KrbAuthorizationDataSequence adIfRelevant = null;
32-
try
33-
{
34-
adIfRelevant = KrbAuthorizationDataSequence.Decode(adIfRelevantEntry.Data);
35-
}
36-
catch
37-
{
38-
return false;
39-
}
40-
41-
KrbAuthorizationData pacEntry = adIfRelevant?.AuthorizationData?.First(ad => ad.Type == AuthorizationDataType.AdWin2kPac);
42-
if (pacEntry == null)
43-
{
44-
return false;
45-
}
46-
47-
try
48-
{
49-
pac = new PrivilegedAttributeCertificate(pacEntry);
50-
return true;
51-
}
52-
catch
53-
{
54-
return false;
55-
}
56-
}
5719
}
5820
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// -----------------------------------------------------------------------
2+
// Licensed to The .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
// -----------------------------------------------------------------------
5+
6+
using System.Linq;
7+
8+
namespace Kerberos.NET.Entities
9+
{
10+
public static class KrbExtensions
11+
{
12+
public static bool TryGetPac(this KrbEncTicketPart encTicketPart, out PrivilegedAttributeCertificate pac)
13+
{
14+
pac = null;
15+
16+
KrbAuthorizationData adIfRelevantEntry = encTicketPart.AuthorizationData?.FirstOrDefault(ad => ad.Type == AuthorizationDataType.AdIfRelevant);
17+
if (adIfRelevantEntry == null)
18+
{
19+
return false;
20+
}
21+
22+
KrbAuthorizationDataSequence adIfRelevant = null;
23+
try
24+
{
25+
adIfRelevant = KrbAuthorizationDataSequence.Decode(adIfRelevantEntry.Data);
26+
}
27+
catch
28+
{
29+
return false;
30+
}
31+
32+
KrbAuthorizationData pacEntry = adIfRelevant?.AuthorizationData?.First(ad => ad.Type == AuthorizationDataType.AdWin2kPac);
33+
if (pacEntry == null)
34+
{
35+
return false;
36+
}
37+
38+
try
39+
{
40+
pac = new PrivilegedAttributeCertificate(pacEntry);
41+
return true;
42+
}
43+
catch
44+
{
45+
return false;
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)