summary refs log tree commit diff
path: root/crypto/src/x509/extension/X509ExtensionUtil.cs
blob: e1f925b089593e658b326b00c65e233534da6650 (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
using Org.BouncyCastle.Asn1;

namespace Org.BouncyCastle.X509.Extension
{
	public class X509ExtensionUtilities
	{
		public static Asn1Object FromExtensionValue(Asn1OctetString extensionValue)
		{
			return Asn1Object.FromByteArray(extensionValue.GetOctets());
		}

		/// <summary>
		/// Extract the value of the given extension, if it exists.
		/// </summary>
		/// <param name="extensions">The extensions object.</param>
		/// <param name="oid">The object identifier to obtain.</param>
		/// <returns>Asn1Object</returns>
		/// <exception cref="Exception">if the extension cannot be read.</exception>
		public static Asn1Object FromExtensionValue(IX509Extension extensions, DerObjectIdentifier oid)
		{
			Asn1OctetString extensionValue = extensions.GetExtensionValue(oid);
			return extensionValue == null ? null : FromExtensionValue(extensionValue);	
		}
	}
}